Skip to content

Commit

Permalink
moved stuff to MotorController, added new vars
Browse files Browse the repository at this point in the history
  • Loading branch information
neuweiler committed Sep 30, 2013
1 parent e70cd6b commit 65a9b58
Show file tree
Hide file tree
Showing 17 changed files with 476 additions and 541 deletions.
6 changes: 0 additions & 6 deletions .cproject
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,6 @@
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/GEVCU/Libraries/due_rtc}&quot;"/>
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/GEVCU/Libraries/due_wire}&quot;"/>
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/GEVCU/Libraries/DueTimer}&quot;"/>
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/GEVCU/Libraries/Ethernet}&quot;"/>
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/GEVCU/Libraries/Ethernet/utility}&quot;"/>
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/GEVCU/Libraries/SPI}&quot;"/>
</option>
<inputType id="it.baeyens.arduino.compiler.cpp.sketch.input.1752728858" name="CPP source files" superClass="it.baeyens.arduino.compiler.cpp.sketch.input"/>
</tool>
Expand All @@ -39,9 +36,6 @@
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/GEVCU/Libraries/due_rtc}&quot;"/>
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/GEVCU/Libraries/due_wire}&quot;"/>
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/GEVCU/Libraries/DueTimer}&quot;"/>
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/GEVCU/Libraries/Ethernet}&quot;"/>
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/GEVCU/Libraries/Ethernet/utility}&quot;"/>
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/GEVCU/Libraries/SPI}&quot;"/>
</option>
<inputType id="it.baeyens.arduino.compiler.c.sketch.input.95460254" name="C Source Files" superClass="it.baeyens.arduino.compiler.c.sketch.input"/>
</tool>
Expand Down
16 changes: 3 additions & 13 deletions .project.copy
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,6 @@
<type>2</type>
<locationURI>ArduinoPivateLibPath/DueTimer</locationURI>
</link>
<link>
<name>Libraries/Ethernet</name>
<type>2</type>
<locationURI>ArduinoHardwareLibPath/Ethernet</locationURI>
</link>
<link>
<name>Libraries/SPI</name>
<type>2</type>
<locationURI>ArduinoHardwareLibPath/SPI</locationURI>
</link>
<link>
<name>Libraries/due_can</name>
<type>2</type>
Expand Down Expand Up @@ -70,15 +60,15 @@
<variableList>
<variable>
<name>ArduinoHardwareLibPath</name>
<value>file:/data/development/arduino/arduino-1.5.2_linux_64bit/hardware/arduino/sam/libraries</value>
<value>file:/Z:/development/arduino/arduino-1.5.2_win_32bit/hardware/arduino/sam/libraries</value>
</variable>
<variable>
<name>ArduinoPinPath</name>
<value>file:/data/development/arduino/arduino-1.5.2_linux_64bit/hardware/arduino/sam/variants</value>
<value>file:/Z:/development/arduino/arduino-1.5.2_win_32bit/hardware/arduino/sam/variants</value>
</variable>
<variable>
<name>ArduinoPlatformPath</name>
<value>file:/data/development/arduino/arduino-1.5.2_linux_64bit/hardware/arduino/sam</value>
<value>file:/Z:/development/arduino/arduino-1.5.2_win_32bit/hardware/arduino/sam</value>
</variable>
</variableList>
</projectDescription>
86 changes: 29 additions & 57 deletions BrusaMotorController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,40 +36,20 @@
ing torque that can't be controlled.
*/

BrusaMotorController::BrusaMotorController() {
dmcReady = false;
running = false;
faulted = false;
dmcWarning = false;
BrusaMotorController::BrusaMotorController() : MotorController() {
torqueAvailable = 0;
torqueActual = 0;
speedActual = 0;

dcVoltage = 0;
dcCurrent = 0;
acCurrent = 0;
mechanicalPower = 0;

temperatureInverter = 0;
temperatureMotor = 0;
temperatureSystem = 0;
maxPositiveTorque = 0;
minNegativeTorque = 0;

errorBitField = 0;
warningBitField = 0;
statusBitField = 0;

maxPositiveTorque = 0;
minNegativeTorque = 0;
limiterStateNumber = 0;

tickCounter = 0;
powerMode = modeTorque;

maxTorque = 20; // TODO: only for testing, in tenths Nm, so 2Nm max torque, remove for production use
maxRPM = 2000; // TODO: only for testing, remove for production use
requestedRPM = 0;
requestedTorque = 0;
requestedThrottle = 0;
torqueMax = 20; // TODO: only for testing, in tenths Nm, so 2Nm max torque, remove for production use
speedMax = 2000; // TODO: only for testing, remove for production use
}

void BrusaMotorController::setup() {
Expand Down Expand Up @@ -99,19 +79,19 @@ void BrusaMotorController::sendControl() {


//TODO: remove ramp testing
requestedTorque = 20;
torqueRequested = 20;
if (speedActual < 100)
requestedRPM = 1000;
speedRequested = 1000;
if (speedActual > 950)
requestedRPM = 50;
speedRequested = 50;



outputFrame.data[0] = enablePositiveTorqueSpeed | enableNegativeTorqueSpeed;
if (faulted) {
outputFrame.data[0] |= clearErrorLatch;
} else {
if (dmcReady || speedActual > 1000) { // see warning about field weakening current to prevent uncontrollable regen
if (running || speedActual > 1000) { // see warning about field weakening current to prevent uncontrollable regen
outputFrame.data[0] |= enablePowerStage;
if (running) {
// outputFrame.data[0] |= enableOscillationLimiter;
Expand All @@ -122,12 +102,12 @@ void BrusaMotorController::sendControl() {
// TODO: check for maxRPM and maxTorque

// set the speed in rpm
outputFrame.data[2] = (requestedRPM & 0xFF00) >> 8;
outputFrame.data[3] = (requestedRPM & 0x00FF);
outputFrame.data[2] = (speedRequested & 0xFF00) >> 8;
outputFrame.data[3] = (speedRequested & 0x00FF);

// set the torque in 0.01Nm (GEVCU uses 0.1Nm -> multiply by 10)
outputFrame.data[4] = ((requestedTorque * 10) & 0xFF00) >> 8;
outputFrame.data[5] = ((requestedTorque * 10) & 0x00FF);
outputFrame.data[4] = ((torqueRequested * 10) & 0xFF00) >> 8;
outputFrame.data[5] = ((torqueRequested * 10) & 0x00FF);
}
}
}
Expand Down Expand Up @@ -194,19 +174,15 @@ void BrusaMotorController::handleCanFrame(RX_CAN_FRAME* frame) {
switch (frame->id) {
case CAN_ID_STATUS:
statusBitField = frame->data[1] | (frame->data[0] << 8);
torqueAvailable = frame->data[3] | (frame->data[2] << 8);
torqueActual = frame->data[5] | (frame->data[4] << 8);
torqueAvailable = (frame->data[3] | (frame->data[2] << 8)) / 10;
torqueActual = (frame->data[5] | (frame->data[4] << 8)) / 10;
speedActual = frame->data[7] | (frame->data[6] << 8);

//TODO: replace mapping
actualTorque = torqueActual / 10; //in tenths Nm
actualRPM = speedActual; //in RPM

if(Logger::isDebug())
Logger::debug(BRUSA_DMC5, "status: %X, torque avail: %fNm, actual torque: %fNm, speed actual: %drpm", statusBitField, (float)torqueAvailable/100.0F, (float)torqueActual/100.0F, speedActual);

dmcReady = (statusBitField & stateReady) != 0 ? true : false;
if (dmcReady)
ready = (statusBitField & stateReady) != 0 ? true : false;
if (ready)
Logger::info(BRUSA_DMC5, "ready");

running = (statusBitField & stateRunning) != 0 ? true : false;
Expand All @@ -217,8 +193,8 @@ void BrusaMotorController::handleCanFrame(RX_CAN_FRAME* frame) {
if (faulted)
Logger::error(BRUSA_DMC5, "error is present, see error message");

dmcWarning = (statusBitField & warningFlag) != 0 ? true : false;
if (dmcWarning)
warning = (statusBitField & warningFlag) != 0 ? true : false;
if (warning)
Logger::warn(BRUSA_DMC5, "warning is present, see warning message");

if (statusBitField & motorModelLimitation)
Expand Down Expand Up @@ -248,11 +224,11 @@ void BrusaMotorController::handleCanFrame(RX_CAN_FRAME* frame) {
case CAN_ID_ACTUAL_VALUES:
dcVoltage = frame->data[1] | (frame->data[0] << 8);
dcCurrent = frame->data[3] | (frame->data[2] << 8);
acCurrent = frame->data[5] | (frame->data[4] << 8);
mechanicalPower = frame->data[7] | (frame->data[6] << 8);
acCurrent = (frame->data[5] | (frame->data[4] << 8)) / 2.5;
mechanicalPower = (frame->data[7] | (frame->data[6] << 8)) / 6.25;

if (Logger::isDebug())
Logger::debug(BRUSA_DMC5, "actual values: DC Volts: %fV, DC current: %fA, AC current: %fA, mechPower: %fkW", (float)dcVoltage / 10.0F, (float)dcCurrent / 10.0F, (float)acCurrent / 4.0F, (float)mechanicalPower / 62.5F);
Logger::debug(BRUSA_DMC5, "actual values: DC Volts: %fV, DC current: %fA, AC current: %fA, mechPower: %fkW", (float)dcVoltage / 10.0F, (float)dcCurrent / 10.0F, (float)acCurrent / 10.0F, (float)mechanicalPower / 10.0F);
break;

case CAN_ID_ERRORS:
Expand Down Expand Up @@ -344,25 +320,21 @@ void BrusaMotorController::handleCanFrame(RX_CAN_FRAME* frame) {
break;

case CAN_ID_TORQUE_LIMIT:
maxPositiveTorque = frame->data[1] | (frame->data[0] << 8);
minNegativeTorque = frame->data[3] | (frame->data[2] << 8);
maxPositiveTorque = (frame->data[1] | (frame->data[0] << 8)) / 10;
minNegativeTorque = (frame->data[3] | (frame->data[2] << 8)) / 10;
limiterStateNumber = frame->data[4];

if (Logger::isDebug())
Logger::debug(BRUSA_DMC5, "torque limit: max positive: %fNm, min negative: %fNm", (float) maxPositiveTorque / 100.0F, (float) minNegativeTorque / 100.0F, limiterStateNumber);
Logger::debug(BRUSA_DMC5, "torque limit: max positive: %fNm, min negative: %fNm", (float) maxPositiveTorque / 10.0F, (float) minNegativeTorque / 10.0F, limiterStateNumber);
break;

case CAN_ID_TEMP:
temperatureInverter = frame->data[1] | (frame->data[0] << 8);
temperatureMotor = frame->data[3] | (frame->data[2] << 8);
temperatureSystem = frame->data[4];

//TODO: replace mapping
motorTemp = temperatureMotor * 5; //temperature of motor in tenths of degree C
inverterTemp = temperatureInverter * 5; //temperature of inverter in tenths deg C
temperatureInverter = (frame->data[1] | (frame->data[0] << 8)) * 5;
temperatureMotor = (frame->data[3] | (frame->data[2] << 8)) * 5;
temperatureSystem = (frame->data[4] - 50) * 10;

if (Logger::isDebug())
Logger::debug(BRUSA_DMC5, "temperature: inverter: %f°C, motor: %f°C, system: %d°C", (float)temperatureInverter / 2.0F, (float)temperatureMotor / 2.0F, temperatureSystem - 50);
Logger::debug(BRUSA_DMC5, "temperature: inverter: %fC, motor: %fC, system: %fC", (float)temperatureInverter / 10.0F, (float)temperatureMotor / 10.0F, (float)temperatureSystem / 10.0F);
break;

default:
Expand Down
33 changes: 14 additions & 19 deletions BrusaMotorController.h
Original file line number Diff line number Diff line change
Expand Up @@ -134,11 +134,6 @@ class BrusaMotorController: public MotorController, CanObserver {
enablePowerStage = 1 << 7 // 0x80
};

enum PowerMode {
modeTorque,
modeSpeed
};

void handleTick();
void handleCanFrame(RX_CAN_FRAME *frame);
void setup();
Expand All @@ -147,24 +142,24 @@ class BrusaMotorController: public MotorController, CanObserver {

private:
// DMC_TRQS
boolean dmcReady; // indicates that the controller is ready, meaning no error is present and HV is available
//boolean running; // indicates that the controller's powerstage is operating
//boolean faulted; // indicates the presence of an error (refer to errorBitField, reported in separate message), enabling powerstage is not possible
boolean dmcWarning; // indicates the presence of a warning (refer to warningBitField, reported in separate message)
int16_t torqueAvailable; // the maximum available torque in 0.01Nm -> divide by 100 to get Nm
int16_t torqueActual; // the actual torque in 0.01Nm -> divide by 100 to get Nm
int16_t speedActual; // the actual speed of the motor in rpm
// boolean dmcReady; // indicates that the controller is ready, meaning no error is present and HV is available
// boolean dmcRunning; // indicates that the controller's powerstage is operating
// boolean dmcError; // indicates the presence of an error (refer to errorBitField, reported in separate message), enabling powerstage is not possible
// boolean dmcWarning; // indicates the presence of a warning (refer to warningBitField, reported in separate message)
// int16_t torqueAvailable; // the maximum available torque in 0.01Nm -> divide by 100 to get Nm
// int16_t torqueActual; // the actual torque in 0.01Nm -> divide by 100 to get Nm
// int16_t speedActual; // the actual speed of the motor in rpm

// DMC_ACTV
uint16_t dcVoltage; // DC voltage in 0.1 Volts -> divide value by 10 to get Volts
int16_t dcCurrent; // DC current in 0.1 Amps -> divide value by 10 to get Amps
uint16_t acCurrent; // AC current in 0.25 Amps -> divide value by 4 to get Amps
int16_t mechanicalPower; // mechanical power of the motor in 0.016 kW -> divide value by 62.5 to get kW
// uint16_t dcVoltage; // DC voltage in 0.1 Volts -> divide value by 10 to get Volts
// int16_t dcCurrent; // DC current in 0.1 Amps -> divide value by 10 to get Amps
// uint16_t acCurrent; // AC current in 0.25 Amps -> divide value by 4 to get Amps
// int16_t mechanicalPower; // mechanical power of the motor in 0.016 kW -> divide value by 62.5 to get kW

// DMC_TEMP
int16_t temperatureInverter; // the temperature of the controller powerstage in 0.5°C -> divide by 2 to get °C
int16_t temperatureMotor; // the motor temperature in 0.5°C
uint8_t temperatureSystem; // the temperature of the controller system in °C with offset of +50°C -> subtract 50°C
// int16_t temperatureInverter; // the temperature of the controller powerstage in 0.5C -> divide by 2 to get C
// int16_t temperatureMotor; // the motor temperature in 0.5C
// uint8_t temperatureSystem; // the temperature of the controller system in C with offset of +50C -> subtract 50C

// DMC_ERR
uint32_t errorBitField; // bits holding the errors defined in enum Error
Expand Down
2 changes: 1 addition & 1 deletion CanThrottle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ void CanThrottle::handleCanFrame(RX_CAN_FRAME *frame) {
}
}

Device::DeviceId CanThrottle::getId() {
DeviceId CanThrottle::getId() {
return CANACCELPEDAL;
}

Expand Down
Loading

0 comments on commit 65a9b58

Please sign in to comment.