Skip to content

Commit

Permalink
Fixed timeRunning, sped up and reorganized characteristic updates
Browse files Browse the repository at this point in the history
  • Loading branch information
collin80 committed Aug 3, 2016
1 parent 6f0b32e commit 9a5e162
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 36 deletions.
4 changes: 2 additions & 2 deletions TestMotorController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,8 @@ void TestMotorController::handleTick() {
//Assume ambient temperature is 18C
//These numbers are horrifically off from realistic physics at this point
//but we're trying to aid debugging, not making a perfect physics model.
temperatureMotor = 180 + abs(mechanicalPower);
temperatureInverter = 190 + abs(mechanicalPower);
temperatureMotor = 180 + abs(mechanicalPower * 2);
temperatureInverter = 190 + abs(mechanicalPower * 3) / 2;
temperatureSystem = (temperatureInverter + temperatureMotor) / 2;

Logger::debug(TESTINVERTER, "PowerMode: %i, Gear: %i", powerMode, selectedGear);
Expand Down
53 changes: 31 additions & 22 deletions adafruitBLE.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ uint8_t BLETYPE=1; //Type 1 is SPI type 2 is UART
*/
Characteristic characteristics[] =
{
{BLE_DATATYPE_INTEGER, 4, 4, 0x12, "TimeRunning", {GATT_PRESENT_FORMAT_UINT32, 0, GATT_PRESENT_UNIT_TIME_SECOND, 1, 0}}, //MeasureCharId[0]
{BLE_DATATYPE_BYTEARRAY, 4, 4, 0x12, "TimeRunning", {GATT_PRESENT_FORMAT_UINT32, 0, GATT_PRESENT_UNIT_TIME_SECOND, 1, 0}}, //MeasureCharId[0]

//Requested torque followed by actual torque, both signed 16 bit
{BLE_DATATYPE_BYTEARRAY, sizeof(BLETrqReqAct) - 1, sizeof(BLETrqReqAct) - 1, 0x12, "TrqReqAct", {GATT_PRESENT_FORMAT_STRUCT, -1, GATT_PRESENT_UNIT_MOMENT_OF_FORCE_NEWTON_METRE, 1, 0}}, //1
Expand Down Expand Up @@ -135,7 +135,7 @@ void ADAFRUITBLE::setup() {
setupBLEservice();
Logger::debug(ADABLUE, "BluefruitLE Initialization Complete....");

TickHandler::getInstance()->attach(this, CFG_TICK_INTERVAL_WIFI);
TickHandler::getInstance()->attach(this, CFG_TICK_INTERVAL_BLE);
}

void ADAFRUITBLE::setupBLEservice()
Expand Down Expand Up @@ -397,15 +397,22 @@ void ADAFRUITBLE::handleTick() {
// DeviceManager::getInstance()->updateWifiByID(BRUSA_DMC5);
didParamLoad = true;
}

// make small slices so the main loop is not blocked for too long
if (tickCounter == 1) {

if (paramCache.timeRunning != (ms / 1000))
{
paramCache.timeRunning = ms / 1000;
if (!gatt.setChar(MeasureCharId[0], (uint8_t*)&paramCache.timeRunning, 4))
{
Logger::error("Could not update timeRunning");
}
else Logger::debug(ADABLUE, "Updated timeRunning");
dumpRawData((uint8_t *)&paramCache.timeRunning, 4);
}

//every other time - 80ms by default
if (tickCounter & 1)
{
if (motorController) {
//Logger::console("Wifi tick counter 1...");

paramCache.timeRunning = ms / 1000;
gatt.setChar(MeasureCharId[0], (uint8_t *)&paramCache.timeRunning, 4);

if ( bleTrqReqAct.torqueRequested != motorController->getTorqueRequested() ) {
bleTrqReqAct.torqueRequested = motorController->getTorqueRequested();
bleTrqReqAct.doUpdate = 1;
Expand All @@ -414,7 +421,17 @@ void ADAFRUITBLE::handleTick() {
bleTrqReqAct.torqueActual = motorController->getTorqueActual();
bleTrqReqAct.doUpdate = 1;
}
if ( bleSpeeds.speedRequested != motorController->getSpeedRequested() ) {
bleSpeeds.speedRequested = motorController->getSpeedRequested();
bleSpeeds.doUpdate = 1;
}

if ( bleSpeeds.speedActual != motorController->getSpeedActual() ) {
bleSpeeds.speedActual = motorController->getSpeedActual();
bleSpeeds.doUpdate = 1;
}
}

if (accelerator) {
RawSignalData *rawSignal = accelerator->acquireRawSignal();
if ( bleThrBrkLevels.throttleRawLevel1 != rawSignal->input1)
Expand Down Expand Up @@ -451,7 +468,9 @@ void ADAFRUITBLE::handleTick() {
bleThrBrkLevels.doUpdate = 1;
}
}
} else if (tickCounter == 2) {
}

if (tickCounter == 2) {
if (bms)
{
if (blePowerStatus.SOC != bms->getSOC())
Expand All @@ -461,17 +480,7 @@ void ADAFRUITBLE::handleTick() {
}
}
if (motorController) {
//Logger::console("Wifi tick counter 2...");
if ( bleSpeeds.speedRequested != motorController->getSpeedRequested() ) {
bleSpeeds.speedRequested = motorController->getSpeedRequested();
bleSpeeds.doUpdate = 1;
}

if ( bleSpeeds.speedActual != motorController->getSpeedActual() ) {
bleSpeeds.speedActual = motorController->getSpeedActual();
bleSpeeds.doUpdate = 1;
}

//Logger::console("Wifi tick counter 2...");
if ( blePowerStatus.busVoltage != motorController->getDcVoltage() ) {
blePowerStatus.busVoltage = motorController->getDcVoltage();
if(blePowerStatus.busVoltage<0) blePowerStatus.busVoltage=0;
Expand Down
25 changes: 13 additions & 12 deletions config.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,18 +56,19 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
* try to use the same numbers for several devices because then they will share
* the same timer (out of a limited number of 9 timers).
*/
#define CFG_TICK_INTERVAL_HEARTBEAT 2000000
#define CFG_TICK_INTERVAL_POT_THROTTLE 40000
#define CFG_TICK_INTERVAL_CAN_THROTTLE 40000
#define CFG_TICK_INTERVAL_MOTOR_CONTROLLER 40000
#define CFG_TICK_INTERVAL_MOTOR_CONTROLLER_DMOC 40000
#define CFG_TICK_INTERVAL_MOTOR_CONTROLLER_CODAUQM 10000
#define CFG_TICK_INTERVAL_MOTOR_CONTROLLER_BRUSA 20000
#define CFG_TICK_INTERVAL_MEM_CACHE 40000
#define CFG_TICK_INTERVAL_BMS_THINK 500000
#define CFG_TICK_INTERVAL_WIFI 200000
#define CFG_TICK_INTERVAL_DCDC 200000
#define CFG_TICK_INTERVAL_EVIC 100000
#define CFG_TICK_INTERVAL_HEARTBEAT 2000000
#define CFG_TICK_INTERVAL_POT_THROTTLE 40000
#define CFG_TICK_INTERVAL_CAN_THROTTLE 40000
#define CFG_TICK_INTERVAL_MOTOR_CONTROLLER 40000
#define CFG_TICK_INTERVAL_MOTOR_CONTROLLER_DMOC 40000
#define CFG_TICK_INTERVAL_MOTOR_CONTROLLER_CODAUQM 10000
#define CFG_TICK_INTERVAL_MOTOR_CONTROLLER_BRUSA 20000
#define CFG_TICK_INTERVAL_MEM_CACHE 40000
#define CFG_TICK_INTERVAL_BMS_THINK 500000
#define CFG_TICK_INTERVAL_WIFI 200000
#define CFG_TICK_INTERVAL_BLE 40000
#define CFG_TICK_INTERVAL_DCDC 200000
#define CFG_TICK_INTERVAL_EVIC 100000


/*
Expand Down

0 comments on commit 9a5e162

Please sign in to comment.