I need a bit of help performing calculations with different variables for my ECM to Arduino project. I am starting a new thread since I have solved the buffer problems and have moved into the next phase of the project with a different set of challenges. If you are interested in the previous discussion you can find it http://arduino.cc/forum/index.php/topic,96280.0.html
I am new to doing math and calculations with the arduino and I do not know how to set up the variables properly for some of the equations to work, so I need some help from you guys to get this working.
My code thus far:
/*
This program is used for an Arduino to request and retrieve
data from an 07 Buell XB9SX Lightning ECM DDFI-2,
EEPROM Version: BUEIB
Currently the Arduino successfully sends a request code and
receives all 107 bytes of Real-time data, and displays
on the TPS on the LCD screen and all data via serial monitor.
Created by Michael Blaylock
*/
// include the library code:
#include <LiquidCrystal.h>
#include <SoftwareSerial.h>
//new serial pins for ECM, 0 and 1 caused interferance from PC
#define rxPin 2
#define txPin 3
// set up a new serial port
SoftwareSerial mySerial = SoftwareSerial(rxPin, txPin);
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(7, 8, 9, 10, 11, 12);
byte inArray[9]; //request code for real-time data
byte outArray[107]; //real-time data series from ECM
long unsigned TPS;
float ATemp;
float ADensity;
unsigned LastSpeed;
unsigned Speed;
long unsigned LastSpeedTimestamp;
long unsigned SpeedTimestamp;
unsigned RPM;
float Accel;
float Power;
int Torque;
int IterationNumber = 0;
int ByteNumber;
int Processing = 0;
void setup(){
lcd.begin(16, 2); // set up the LCD's number of columns and rows:
mySerial.begin(9600); // baud rate for the ECM is 9600
Serial.begin(9600);
ByteNumber = 0;
inArray[0]=0x01; //SOH
inArray[1]=0x00; //Emittend
inArray[2]=0x42; //Recipient
inArray[3]=0x02; //Data Size
inArray[4]=0xFF; //EOH
inArray[5]=0x02; //SOT
inArray[6]=0x43; //Data 1 //0x56 = Get version, 0x43 = Get runttime data
inArray[7]=0x03; //EOT
inArray[8]=0xFD; //Checksum
//mySerial.write(0x01 0x00 0x43 0x02 0xFF 0x02 0x43 0x03 0xFD);
requestData();
}
//Send data request to ECM
void requestData() {
//lcd.setCursor(0,0);
for (int i = 0; i<9; i+=1)
mySerial.write(inArray[i]);
//Do not place code here
}
//display the array in serial monitor
void displayData(){
for (int j = 0; j<107; j+=1){
Serial.println(outArray[j],HEX);
}
Serial.println("Data Printed");
Processing = 0;
}
//Display the Throttle Position Sensor
void callTPS(){
TPS = outArray[91] << 8 | outArray[90];
lcd.setCursor(0,0); //right then down
lcd.print("TPS: ");
lcd.print(TPS);
}
//Obtain Air Temp and Density
void callATemp(){
ATemp = (outArray[33] << 8 | outArray[32]) * 0.18 -40;
ADensity = (39.1282 / (ATemp + 460));
}
//Obtain Speed and Acceleration
void callSpeed(){
LastSpeed = Speed;
Speed = outArray[99];
LastSpeedTimestamp = SpeedTimestamp;
SpeedTimestamp = millis();
Accel = (Speed - LastSpeed)*1000/(SpeedTimestamp-LastSpeedTimestamp);
}
//Obtain RPM
void callRPM(){
RPM = outArray[12] << 8 | outArray[11];
}
//Calculate Horsepower and Torque
void callPower(){
Power = (16.784*(Accel*1.467+0.018*32.174)+(0.5*ADensity*0.382*214.6*(Speed*1.467)^2))*Speed*1.467;
Torque1 = Power
}
void loop() {
if (mySerial.available () > 0) {
outArray[ByteNumber ++] = mySerial.read();
}
if (ByteNumber > 106){ // process it
Serial.println("Data Stream Read");
ByteNumber = 0; // ready for next time
//displayData();
lcd.setCursor(1,1);
callTPS();
callATemp();
requestData(); //restart data
//Do not place code here
} // end if full
} // end of loop
At the moment when I try to compile the code I get the error message
invalid operands of types 'double' and 'int' to binary 'operator^'
at the line:
Power = (16.784*(Accel*1.467+0.018*32.174)+(0.5*ADensity*0.382*214.6*(Speed*1.467)^2))*Speed*1.467;
This is the original equation:
It calculates the power from acceleration, rolling resistance, and drag of a vehicle at any given speed. The numbers are constants and unit conversions. I don't want to simplify them further because I won't be able to quickly change one variable without recalculating everything (like mass or cross sectional area)
What types of variables should should Accel ADensity and Speed be for the equation to work?