From bac3fb09d117a3cd1b1fbcd6906e0296f450a7a0 Mon Sep 17 00:00:00 2001 From: Steven Chan Date: Thu, 14 Sep 2023 23:29:36 -0700 Subject: [PATCH 01/14] create device to test CAN recieve functionality --- src/devices/misc/CANRecieveTest.cpp | 43 +++++++++++++++++++++++++++++ src/devices/misc/CANRecieveTest.h | 33 ++++++++++++++++++++++ 2 files changed, 76 insertions(+) create mode 100644 src/devices/misc/CANRecieveTest.cpp create mode 100644 src/devices/misc/CANRecieveTest.h diff --git a/src/devices/misc/CANRecieveTest.cpp b/src/devices/misc/CANRecieveTest.cpp new file mode 100644 index 0000000..acc2f59 --- /dev/null +++ b/src/devices/misc/CANRecieveTest.cpp @@ -0,0 +1,43 @@ +#include "CANRecieveTest.h" + +CANRecieveTest::CANRecieveTest() : Device() { + commonName = "CAN Recieve Test"; + shortName = "CAN"; +} + +void CANRecieveTest::earlyInit() +{ + prefsHandler = new PrefHandler(CANRecieveTestID); +} + +void CANRecieveTest::setup() { + + Logger::info("add device: CANRecieveTest (id: %X, %X)", CANRecieveTestID, this); + + + Device::setup(); // run the parent class version of this function + + setAttachedCANBus(0); + + //Relevant BMS messages are 0x300 - 0x30F + attachedCANBus->attach(this, 0x300, 0x7f0, false); +} + +/*For all multibyte integers the format is MSB first, LSB last +*/ +void CANRecieveTest::handleCanFrame(const CAN_message_t &frame) { + Logger::info("Test id=%X len=%X data=%X,%X,%X,%X,%X,%X,%X,%X", + frame.id, frame.len, + frame.buf[0], frame.buf[1], frame.buf[2], frame.buf[3], + frame.buf[4], frame.buf[5], frame.buf[6], frame.buf[7]); +} + +DeviceId CANRecieveTest::getId() { + return (CANRecieveTestID); +} + +DeviceType CANRecieveTest::getType() { + return (DEVICE_MISC); +} + +CANRecieveTest canRecieveTest; \ No newline at end of file diff --git a/src/devices/misc/CANRecieveTest.h b/src/devices/misc/CANRecieveTest.h new file mode 100644 index 0000000..8410aa4 --- /dev/null +++ b/src/devices/misc/CANRecieveTest.h @@ -0,0 +1,33 @@ +#ifndef CANRecieveTest_H_ +#define CANRecieveTest_H_ + +#include +#include "../../config.h" +#include "../Device.h" +#include "../../DeviceManager.h" +#include "../../CanHandler.h" + +#define CANRecieveTestID 0x1234 + +class CANRecieveTestConfiguration: DeviceConfiguration +{ +public: + uint8_t canbusNum; +}; + + +class CANRecieveTest : public Device, CanObserver +{ +public: + CANRecieveTest(); + void setup(); + void earlyInit(); + void handleCanFrame(const CAN_message_t &frame); + DeviceId getId(); + DeviceType getType(); + +protected: +private: +}; + +#endif \ No newline at end of file From c011a28741e8e0cfa2a553255cd15fbbd93544ce Mon Sep 17 00:00:00 2001 From: Carina Curiel Alaniz Date: Thu, 21 Sep 2023 19:29:59 -0700 Subject: [PATCH 02/14] test device --- src/devices/misc/testDevice.cpp | 55 +++++++++++++++++++++++++++++++++ src/devices/misc/testDevice.h | 25 +++++++++++++++ 2 files changed, 80 insertions(+) create mode 100644 src/devices/misc/testDevice.cpp create mode 100644 src/devices/misc/testDevice.h diff --git a/src/devices/misc/testDevice.cpp b/src/devices/misc/testDevice.cpp new file mode 100644 index 0000000..4988444 --- /dev/null +++ b/src/devices/misc/testDevice.cpp @@ -0,0 +1,55 @@ +#include "testDevice.h" + +testDevice::testDevice() : Device() { + commonName = "testDevice"; + shortName = "test"; +} + +void testDevice::earlyInit() +{ + prefsHandler = new PrefHandler(testDeviceID); +} + +void testDevice::setup() { + tickHandler.detach(this); + Logger::info("add device: testDevice (id: %X, %X)", testDeviceID, this); + + + Device::setup(); // run the parent class version of this function + + setAttachedCANBus(0); + + //Relevant BMS messages are 0x300 - 0x30F + attachedCANBus->attach(this, 0x200, 0x7f0, false); + tickHandler.attach(this, testDeviceTickInt); +} + +/*For all multibyte integers the format is MSB first, LSB last +*/ +void testDevice::handleCanFrame(const CAN_message_t &frame) { + Logger::info("Test id=%X len=%X data=%X,%X,%X,%X,%X,%X,%X,%X", + frame.id, frame.len, + frame.buf[0], frame.buf[1], frame.buf[2], frame.buf[3], + frame.buf[4], frame.buf[5], frame.buf[6], frame.buf[7]); +} + +DeviceId testDevice::getId() { + return (testDeviceID); +} + +DeviceType testDevice::getType() { + return (DEVICE_MISC); +} + +void testDevice::handleTick() +{ + var.len = 3; + var.id = 0x729; + var.buf[0] = 1; + var.buf[1] = 2; + var.buf[2] = 3; + attachedCANBus->sendFrame(var); + +} + +testDevice test_device; \ No newline at end of file diff --git a/src/devices/misc/testDevice.h b/src/devices/misc/testDevice.h new file mode 100644 index 0000000..063e2fd --- /dev/null +++ b/src/devices/misc/testDevice.h @@ -0,0 +1,25 @@ +#ifndef testDevice_H_ +#define testDevice_H_ + +#include +#include "../Device.h" +#include "../../DeviceManager.h" +#include "../../CanHandler.h" + +#define testDeviceID 0x321 +#define testDeviceTickInt 1000000 + +class testDevice: public Device, CanObserver{ +public: + testDevice(); //called nearly immediately to initialize your own variables + void setup(); //called only if the device is actually enabled + void earlyInit(); //called early and whether or not the device is enabled. Just used to setup configuration + void handleTick(); + void handleCanFrame(const CAN_message_t &frame); + DeviceId getId(); + DeviceType getType(); +private: + CAN_message_t var; + +}; +#endif From 5152dd25b28da3307c907bdd437e9e86586a48ef Mon Sep 17 00:00:00 2001 From: Carina Curiel Alaniz Date: Thu, 5 Oct 2023 19:59:30 -0700 Subject: [PATCH 03/14] analog input --- GEVCU7.ino | 2 ++ bms.cpp | 1 + src/Heartbeat.cpp | 11 ++++++----- src/devices/misc/analogTest.cpp | 0 src/sys_io.cpp | 8 +++++--- 5 files changed, 14 insertions(+), 8 deletions(-) create mode 100644 bms.cpp create mode 100644 src/devices/misc/analogTest.cpp diff --git a/GEVCU7.ino b/GEVCU7.ino index 9d12a15..89151dd 100644 --- a/GEVCU7.ino +++ b/GEVCU7.ino @@ -239,6 +239,8 @@ void testGEVCUHardware() Serial.print(val); Serial.print(" "); } + + Serial.print("ADC19: " + systemIO.getAnalogIn(19)); Serial.println(); Serial.print("DIN: "); diff --git a/bms.cpp b/bms.cpp new file mode 100644 index 0000000..ab0c014 --- /dev/null +++ b/bms.cpp @@ -0,0 +1 @@ +// \ No newline at end of file diff --git a/src/Heartbeat.cpp b/src/Heartbeat.cpp index 5eb5aaa..e920b16 100644 --- a/src/Heartbeat.cpp +++ b/src/Heartbeat.cpp @@ -76,16 +76,17 @@ void Heartbeat::handleTick() { Logger::console("Motor Controller Status-> isRunning: %u isFaulted: %u", motorController->isRunning(), motorController->isFaulted()); } - Logger::console("AIN0: %i, AIN1: %i, AIN2: %i, AIN3: %i, AIN4: %i, AIN5: %i, AIN6: %i, AIN7: %i", - systemIO.getAnalogIn(0), systemIO.getAnalogIn(1), systemIO.getAnalogIn(2), systemIO.getAnalogIn(3), - systemIO.getAnalogIn(4), systemIO.getAnalogIn(5), systemIO.getAnalogIn(6), systemIO.getAnalogIn(7)); - Logger::console("DIN0: %d, DIN1: %d, DIN2: %d, DIN3: %d, DIN4: %d, DIN5: %d, DIN6: %d, DIN7: %d, DIN8: %d, DIN9: %d, DIN10: %d, DIN11: %d", + // , AIN1: %i, AIN2: %i", + + Logger::console("AIN0: %g, AIN1: %g, AIN2: %g, AIN3: %g, AIN4: %g, AIN5: %g, AIN6: %g, AIN7: %g", ((double)(analogRead(0))*5)/4096, ((double)(analogRead(1))*5)/4096, ((double)(analogRead(2))*5)/4096, ((double)(analogRead(3))*5)/4096, + ((double)(analogRead(4))*5)/4096, ((double)(analogRead(5))*5)/4096, ((double)(analogRead(6))*5)/4096, ((double)(analogRead(7))*5)/4096); + /* Logger::console("DIN0: %d, DIN1: %d, DIN2: %d, DIN3: %d, DIN4: %d, DIN5: %d, DIN6: %d, DIN7: %d, DIN8: %d, DIN9: %d, DIN10: %d, DIN11: %d", systemIO.getDigitalIn(0), systemIO.getDigitalIn(1), systemIO.getDigitalIn(2), systemIO.getDigitalIn(3), systemIO.getDigitalIn(4), systemIO.getDigitalIn(5), systemIO.getDigitalIn(6), systemIO.getDigitalIn(7), systemIO.getDigitalIn(8), systemIO.getDigitalIn(9), systemIO.getDigitalIn(10), systemIO.getDigitalIn(11)); Logger::console("DOUT0: %d, DOUT1: %d, DOUT2: %d, DOUT3: %d,DOUT4: %d, DOUT5: %d, DOUT6: %d, DOUT7: %d", systemIO.getDigitalOutput(0), systemIO.getDigitalOutput(1), systemIO.getDigitalOutput(2), systemIO.getDigitalOutput(3), - systemIO.getDigitalOutput(4), systemIO.getDigitalOutput(5), systemIO.getDigitalOutput(6), systemIO.getDigitalOutput(7)); + systemIO.getDigitalOutput(4), systemIO.getDigitalOutput(5), systemIO.getDigitalOutput(6), systemIO.getDigitalOutput(7));*/ //Logger::console("SD-Detect: %u", digitalRead(5)); BatteryManager *bms = reinterpret_cast(deviceManager.getDeviceByType(DEVICE_BMS)); if (!bms) { diff --git a/src/devices/misc/analogTest.cpp b/src/devices/misc/analogTest.cpp new file mode 100644 index 0000000..e69de29 diff --git a/src/sys_io.cpp b/src/sys_io.cpp index ccdca7a..47c5919 100644 --- a/src/sys_io.cpp +++ b/src/sys_io.cpp @@ -45,7 +45,7 @@ SystemIO::SystemIO() numDigIn = NUM_DIGITAL; numDigOut = NUM_OUTPUT; - numAnaIn = NUM_ANALOG; + numAnaIn = 6; numAnaOut = 0; pcaDigitalOutputCache = 0; //all outputs off by default adcMuxSelect = 0; @@ -320,11 +320,13 @@ get value of one of the analog inputs int16_t SystemIO::getAnalogIn(uint8_t which) { int valu; + //numAnaIn = 6 if (which > numAnaIn) { return 0; - } - + } + + //num_analog = 8 if (which < NUM_ANALOG) { valu = _pGetAnalogRaw(which); From 8ba737617524af6c35c11ddcf8ffd16f48f03c2b Mon Sep 17 00:00:00 2001 From: Carina Curiel Alaniz Date: Thu, 19 Oct 2023 19:53:43 -0700 Subject: [PATCH 04/14] analog readings --- src/Heartbeat.cpp | 6 +++--- src/devices/io/PotThrottle.cpp | 24 +++++++++++++++++------- src/devices/io/Throttle.h | 2 +- 3 files changed, 21 insertions(+), 11 deletions(-) diff --git a/src/Heartbeat.cpp b/src/Heartbeat.cpp index e920b16..27ddde6 100644 --- a/src/Heartbeat.cpp +++ b/src/Heartbeat.cpp @@ -77,9 +77,9 @@ void Heartbeat::handleTick() { } // , AIN1: %i, AIN2: %i", - - Logger::console("AIN0: %g, AIN1: %g, AIN2: %g, AIN3: %g, AIN4: %g, AIN5: %g, AIN6: %g, AIN7: %g", ((double)(analogRead(0))*5)/4096, ((double)(analogRead(1))*5)/4096, ((double)(analogRead(2))*5)/4096, ((double)(analogRead(3))*5)/4096, - ((double)(analogRead(4))*5)/4096, ((double)(analogRead(5))*5)/4096, ((double)(analogRead(6))*5)/4096, ((double)(analogRead(7))*5)/4096); + Logger::console("AIN0: %g, AIN1: %g", ((double)(analogRead(0))*5)/4096, ((double)(analogRead(1))*5)/4096); + // Logger::console("AIN0: %g, AIN1: %g, AIN2: %g, AIN3: %g, AIN4: %g, AIN5: %g, AIN6: %g, AIN7: %g", ((double)(analogRead(0))*5)/4096, ((double)(analogRead(1))*5)/4096, ((double)(analogRead(2))*5)/4096, ((double)(analogRead(3))*5)/4096, + // ((double)(analogRead(4))*5)/4096, ((double)(analogRead(5))*5)/4096, ((double)(analogRead(6))*5)/4096, ((double)(analogRead(7))*5)/4096); /* Logger::console("DIN0: %d, DIN1: %d, DIN2: %d, DIN3: %d, DIN4: %d, DIN5: %d, DIN6: %d, DIN7: %d, DIN8: %d, DIN9: %d, DIN10: %d, DIN11: %d", systemIO.getDigitalIn(0), systemIO.getDigitalIn(1), systemIO.getDigitalIn(2), systemIO.getDigitalIn(3), systemIO.getDigitalIn(4), systemIO.getDigitalIn(5), systemIO.getDigitalIn(6), systemIO.getDigitalIn(7), diff --git a/src/devices/io/PotThrottle.cpp b/src/devices/io/PotThrottle.cpp index 599cad0..08e6ece 100644 --- a/src/devices/io/PotThrottle.cpp +++ b/src/devices/io/PotThrottle.cpp @@ -104,8 +104,9 @@ RawSignalData *PotThrottle::acquireRawSignal() { bool PotThrottle::validateSignal(RawSignalData *rawSignal) { PotThrottleConfiguration *config = (PotThrottleConfiguration *) getConfiguration(); int32_t calcThrottle1, calcThrottle2; - - calcThrottle1 = normalizeInput(rawSignal->input1, config->minimumLevel1, config->maximumLevel1); + + calcThrottle1 = normalizeInput(rawSignal->input1, config->minimumLevel1, config->maximumLevel1 ); + //Logger::console("Value is %d", calcThrottle1); if (config->numberPotMeters == 1 && config->throttleSubType == 2) { // inverted calcThrottle1 = 1000 - calcThrottle1; } @@ -254,14 +255,23 @@ void PotThrottle::loadConfiguration() { //if (prefsHandler->checksumValid()) { //checksum is good, read in the values stored in EEPROM Logger::debug(POTACCELPEDAL, Constants::validChecksum); - prefsHandler->read("ThrottleMin1", (uint16_t *)&config->minimumLevel1, 20); - prefsHandler->read("ThrottleMax1", (uint16_t *)&config->maximumLevel1, 3150); + prefsHandler->read("ThrottleMin1", (uint16_t *)&config->minimumLevel1, 0); + //figure out this number --> 3150 + //3150 milivolts --> + + //1 volt around 818 + + //5 volts = 818 when max is 5000 + //5 volts = 1000 when max is 4090 + //910 dif = 18.2% dif + + prefsHandler->read("ThrottleMax1", (uint16_t *)&config->maximumLevel1, 4090); prefsHandler->read("ThrottleMin2", (uint16_t *)&config->minimumLevel2, 0); - prefsHandler->read("ThrottleMax2", (uint16_t *)&config->maximumLevel2, 0); - prefsHandler->read("NumThrottles", &config->numberPotMeters, 1); + prefsHandler->read("ThrottleMax2", (uint16_t *)&config->maximumLevel2, 4090); + prefsHandler->read("NumThrottles", &config->numberPotMeters, 2); prefsHandler->read("ThrottleType", &config->throttleSubType, 1); prefsHandler->read("ADC1", &config->AdcPin1, 0); - prefsHandler->read("ADC2", &config->AdcPin2, 1); + prefsHandler->read("ADC2", &config->AdcPin2, 4); // ** This is potentially a condition that is only met if you don't have the EEPROM hardware ** // If preferences have never been set before, numThrottlePots and throttleSubType diff --git a/src/devices/io/Throttle.h b/src/devices/io/Throttle.h index c6c7c38..a37d903 100644 --- a/src/devices/io/Throttle.h +++ b/src/devices/io/Throttle.h @@ -57,7 +57,7 @@ //these two should be configuration options instead. #define CFG_CANTHROTTLE_MAX_NUM_LOST_MSG 3 // maximum number of lost messages allowed #define CFG_THROTTLE_TOLERANCE 150 //the max that things can go over or under the min/max without fault - 1/10% each # -#define ThrottleMaxErrValue 150 //tenths of percentage allowable deviation between pedals +#define ThrottleMaxErrValue 100 //tenths of percentage allowable deviation between pedals /* * Data structure to hold raw signal(s) of the throttle. From cec13f3780eb26fed849916b00ea01276dbdfeba Mon Sep 17 00:00:00 2001 From: Lucas Otanez Date: Thu, 2 Nov 2023 19:53:42 -0700 Subject: [PATCH 05/14] enable motor and send speed --- .gitignore | 1 + src/devices/misc/CANRecieveTest.h | 2 +- src/devices/misc/testDevice.cpp | 20 +++++++++++++++----- 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/.gitignore b/.gitignore index b37af3b..ccad7a1 100644 --- a/.gitignore +++ b/.gitignore @@ -945,6 +945,7 @@ _deps ##### C++ # Prerequisites *.d +*.clangd # Compiled Object files *.slo diff --git a/src/devices/misc/CANRecieveTest.h b/src/devices/misc/CANRecieveTest.h index 8410aa4..4011e71 100644 --- a/src/devices/misc/CANRecieveTest.h +++ b/src/devices/misc/CANRecieveTest.h @@ -30,4 +30,4 @@ class CANRecieveTest : public Device, CanObserver private: }; -#endif \ No newline at end of file +#endif diff --git a/src/devices/misc/testDevice.cpp b/src/devices/misc/testDevice.cpp index 4988444..6674a53 100644 --- a/src/devices/misc/testDevice.cpp +++ b/src/devices/misc/testDevice.cpp @@ -44,12 +44,22 @@ DeviceType testDevice::getType() { void testDevice::handleTick() { var.len = 3; - var.id = 0x729; - var.buf[0] = 1; - var.buf[1] = 2; - var.buf[2] = 3; + var.id = 0x201; + var.buf[0] = 0x51; + // 0x04 to DISABLE + var.buf[1] = 0x04; + // 0x00 to ENABLE + //var.buf[1] = 0x00; + var.buf[2] = 0x00; attachedCANBus->sendFrame(var); + + // send 5% speed + var.buf[0] = 0x31; + var.buf[1] = 0x66; + var.buf[2] = 0x06; + attachedCANBus->sendFrame(var); + } -testDevice test_device; \ No newline at end of file +testDevice test_device; From 4b2e45a86d0461fc131825ed31f68b56ed8d9934 Mon Sep 17 00:00:00 2001 From: Steven Chan Date: Tue, 7 Nov 2023 19:15:31 -0800 Subject: [PATCH 06/14] bamocar init --- .../motorctrl/BamocarMotorController.cpp | 95 +++++++++++++++++++ .../motorctrl/BamocarMotorController.h | 54 +++++++++++ 2 files changed, 149 insertions(+) create mode 100644 src/devices/motorctrl/BamocarMotorController.cpp create mode 100644 src/devices/motorctrl/BamocarMotorController.h diff --git a/src/devices/motorctrl/BamocarMotorController.cpp b/src/devices/motorctrl/BamocarMotorController.cpp new file mode 100644 index 0000000..70ff46f --- /dev/null +++ b/src/devices/motorctrl/BamocarMotorController.cpp @@ -0,0 +1,95 @@ +/* + * BamocarMotorController.cpp + */ + +#include "BamocarMotorController.h" + +BamocarMotorController::BamocarMotorController() : MotorController() { + selectedGear = DRIVE; + commonName = "Bamocar Inverter"; + shortName = "BamocarInverter"; +} + +void BamocarMotorController::earlyInit() +{ + prefsHandler = new PrefHandler(BAMOCARINVERTER); +} + +void BamocarMotorController::setup() { + tickHandler.detach(this); + + Logger::info("add device: Bamocar Inverter (id:%X, %X)", BAMOCARINVERTER, this); + + loadConfiguration(); + MotorController::setup(); // run the parent class version of this function + + running = true; + setPowerMode(modeTorque); + setSelectedGear(DRIVE); + setOpState(ENABLE); + + tickHandler.attach(this, CFG_TICK_INTERVAL_MOTOR_CONTROLLER_BAMOCAR); +} + +void BamocarMotorController::handleTick() { + BamocarMotorControllerConfiguration *config = (BamocarMotorControllerConfiguration *)getConfiguration(); + + MotorController::handleTick(); + + var.len = 3; + var.id = 0x201; + var.buf[0] = 0x51; + // 0x04 to DISABLE + var.buf[1] = 0x04; + // 0x00 to ENABLE + //var.buf[1] = 0x00; + var.buf[2] = 0x00; + attachedCANBus->sendFrame(var); + + // send 5% speed + var.buf[0] = 0x31; + var.buf[1] = 0x66; + var.buf[2] = 0x06; + attachedCANBus->sendFrame(var); +} + +void handleCanFrame(const CAN_message_t &frame) { + +} + +void BamocarMotorController::setGear(Gears gear) { + selectedGear = gear; + //if the gear was just set to drive or reverse and the DMOC is not currently in enabled + //op state then ask for it by name + if (selectedGear != NEUTRAL) { + operationState = ENABLE; + } + //should it be set to standby when selecting neutral? I don't know. Doing that prevents regen + //when in neutral and I don't think people will like that. +} + +DeviceId BamocarMotorController::getId() { + return (BAMOCARINVERTER); +} + +uint32_t BamocarMotorController::getTickInterval() +{ + return CFG_TICK_INTERVAL_MOTOR_CONTROLLER_BAMOCAR; +} + +void BamocarMotorController::loadConfiguration() { + BamocarMotorControllerConfiguration *config = (BamocarMotorControllerConfiguration *)getConfiguration(); + + if (!config) { + config = new BamocarMotorControllerConfiguration(); + setConfiguration(config); + } + + MotorController::loadConfiguration(); // call parent +} + +void BamocarMotorController::saveConfiguration() { + MotorController::saveConfiguration(); +} + +BamocarMotorController bamocarMC; \ No newline at end of file diff --git a/src/devices/motorctrl/BamocarMotorController.h b/src/devices/motorctrl/BamocarMotorController.h new file mode 100644 index 0000000..fbb0755 --- /dev/null +++ b/src/devices/motorctrl/BamocarMotorController.h @@ -0,0 +1,54 @@ +/* + * BamocarMotorController.h + */ + +#ifndef _BAMOCARINVERTER_H_ +#define _BAMOCARINVERTER_H_ + +#include +#include "../../config.h" +#include "MotorController.h" +#include "../../sys_io.h" +#include "../../TickHandler.h" +#include "../../CanHandler.h" + +#define BAMOCARINVERTER 0x1010 +#define CFG_TICK_INTERVAL_MOTOR_CONTROLLER_BAMOCAR 40000 + +/* + * Class for DMOC specific configuration parameters + */ +class BamocarMotorControllerConfiguration : public MotorControllerConfiguration { +public: +}; + +class BamocarMotorController: public MotorController, CanObserver { +public: + +public: + virtual void handleTick(); + virtual void setup(); + void earlyInit(); + void setGear(Gears gear); + + BamocarMotorController(); + DeviceId getId(); + uint32_t getTickInterval(); + + void handleCanFrame(const CAN_message_t &frame); + + virtual void loadConfiguration(); + virtual void saveConfiguration(); + +private: + + uint16_t torqueCommand; + void timestamp(); + + CAN_message_t var; // delete this when handleTick is fully functional +}; + +#endif /* DMOC_H_ */ + + + From 79e3b7a9bcb4f00ac9d65221526c343358fe08fe Mon Sep 17 00:00:00 2001 From: Steven Chan Date: Thu, 9 Nov 2023 20:15:12 -0800 Subject: [PATCH 07/14] fix compiler error --- src/devices/motorctrl/BamocarMotorController.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/devices/motorctrl/BamocarMotorController.cpp b/src/devices/motorctrl/BamocarMotorController.cpp index 70ff46f..5a2f873 100644 --- a/src/devices/motorctrl/BamocarMotorController.cpp +++ b/src/devices/motorctrl/BamocarMotorController.cpp @@ -53,7 +53,7 @@ void BamocarMotorController::handleTick() { attachedCANBus->sendFrame(var); } -void handleCanFrame(const CAN_message_t &frame) { +void BamocarMotorController::handleCanFrame(const CAN_message_t &frame) { } From d8750935f6429924623565f23c1312d258c6853e Mon Sep 17 00:00:00 2001 From: Carina Curiel Alaniz Date: Tue, 14 Nov 2023 20:10:07 -0800 Subject: [PATCH 08/14] updated bamocar --- src/devices/motorctrl/BamocarMotorController.cpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/devices/motorctrl/BamocarMotorController.cpp b/src/devices/motorctrl/BamocarMotorController.cpp index 5a2f873..03e4452 100644 --- a/src/devices/motorctrl/BamocarMotorController.cpp +++ b/src/devices/motorctrl/BamocarMotorController.cpp @@ -3,6 +3,7 @@ */ #include "BamocarMotorController.h" +#include BamocarMotorController::BamocarMotorController() : MotorController() { selectedGear = DRIVE; @@ -35,6 +36,21 @@ void BamocarMotorController::handleTick() { BamocarMotorControllerConfiguration *config = (BamocarMotorControllerConfiguration *)getConfiguration(); MotorController::handleTick(); + int percent = torqueRequested; + + //rounding to nearest 10th + int a = (percent/10)*10; + int b = a + 10; + percent = (percent - a > b - percent)? b : a; + int input = percent*327; + + //convert to hex + std::stringstream ss; + ss << "0x" << std::hex << input; + std::string res (ss.str()); + + //parse string to int + var.len = 3; var.id = 0x201; From e50235b946af6d4776edf4782f0c7cc879be9241 Mon Sep 17 00:00:00 2001 From: atsai488 Date: Thu, 16 Nov 2023 19:26:20 -0800 Subject: [PATCH 09/14] percentage to hex value to add to can message --- src/devices/motorctrl/BamocarMotorController.cpp | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/src/devices/motorctrl/BamocarMotorController.cpp b/src/devices/motorctrl/BamocarMotorController.cpp index 03e4452..1ee8a40 100644 --- a/src/devices/motorctrl/BamocarMotorController.cpp +++ b/src/devices/motorctrl/BamocarMotorController.cpp @@ -44,12 +44,8 @@ void BamocarMotorController::handleTick() { percent = (percent - a > b - percent)? b : a; int input = percent*327; - //convert to hex - std::stringstream ss; - ss << "0x" << std::hex << input; - std::string res (ss.str()); - - //parse string to int + uint32_t firsthalf = (input & 0xFF); + uint32_t secondhalf = ((input >> 8) & 0xFF); var.len = 3; @@ -64,8 +60,8 @@ void BamocarMotorController::handleTick() { // send 5% speed var.buf[0] = 0x31; - var.buf[1] = 0x66; - var.buf[2] = 0x06; + var.buf[1] = secondhalf; + var.buf[2] = firsthalf; attachedCANBus->sendFrame(var); } From ccb45ee609bf7869b2cccf221cab226a718bc8c4 Mon Sep 17 00:00:00 2001 From: atsai488 Date: Thu, 16 Nov 2023 19:58:27 -0800 Subject: [PATCH 10/14] Update BamocarMotorController.cpp --- src/devices/motorctrl/BamocarMotorController.cpp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/devices/motorctrl/BamocarMotorController.cpp b/src/devices/motorctrl/BamocarMotorController.cpp index 1ee8a40..647a1c3 100644 --- a/src/devices/motorctrl/BamocarMotorController.cpp +++ b/src/devices/motorctrl/BamocarMotorController.cpp @@ -34,7 +34,15 @@ void BamocarMotorController::setup() { void BamocarMotorController::handleTick() { BamocarMotorControllerConfiguration *config = (BamocarMotorControllerConfiguration *)getConfiguration(); - + //if the brake is pressed beyond a certain point set the speed back down to 0 + //if the brake is pressed also send a speed signal but lower than the current speed + //if the throttle is released a little then the speed should still be similar, not immediately down to 0 + //max press accelerate max + //make it as close to a regular car + //brakes regular car as well + //willl never really have a cruising speed + //linear + //max push max acceleration MotorController::handleTick(); int percent = torqueRequested; @@ -46,7 +54,7 @@ void BamocarMotorController::handleTick() { uint32_t firsthalf = (input & 0xFF); uint32_t secondhalf = ((input >> 8) & 0xFF); - + // check if the motor will still spin even if the pedal is released all the way up var.len = 3; var.id = 0x201; From 10d12eb6c7c9c76260473b8f91882c0d6ba54a00 Mon Sep 17 00:00:00 2001 From: atsai488 Date: Tue, 30 Jan 2024 20:13:19 -0800 Subject: [PATCH 11/14] Get values from Potthrottle.cpp to bamocarMotorController.cpp and validated hex values work --- src/devices/io/PotThrottle.h | 3 ++- src/devices/motorctrl/BamocarMotorController.cpp | 10 ++++------ 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/src/devices/io/PotThrottle.h b/src/devices/io/PotThrottle.h index 051c1ef..f6ab331 100644 --- a/src/devices/io/PotThrottle.h +++ b/src/devices/io/PotThrottle.h @@ -69,10 +69,11 @@ class PotThrottle: public Throttle { void loadConfiguration(); void saveConfiguration(); + + int16_t calculatePedalPosition(RawSignalData *); protected: bool validateSignal(RawSignalData *); - int16_t calculatePedalPosition(RawSignalData *); String describeThrottleType(); private: diff --git a/src/devices/motorctrl/BamocarMotorController.cpp b/src/devices/motorctrl/BamocarMotorController.cpp index 647a1c3..703c27c 100644 --- a/src/devices/motorctrl/BamocarMotorController.cpp +++ b/src/devices/motorctrl/BamocarMotorController.cpp @@ -1,7 +1,7 @@ /* * BamocarMotorController.cpp */ - +#include "../PotThrottle.h" #include "BamocarMotorController.h" #include @@ -44,13 +44,11 @@ void BamocarMotorController::handleTick() { //linear //max push max acceleration MotorController::handleTick(); - int percent = torqueRequested; + PotThrottle throttle; + int percent = throttle.calculatePedalPosition(throttle.acquireRawSignal()); //rounding to nearest 10th - int a = (percent/10)*10; - int b = a + 10; - percent = (percent - a > b - percent)? b : a; - int input = percent*327; + int a = (percent/10); uint32_t firsthalf = (input & 0xFF); uint32_t secondhalf = ((input >> 8) & 0xFF); From 70c6c1edc83282cc3c8e9d75bcdf9c5c9164fc75 Mon Sep 17 00:00:00 2001 From: atsai488 Date: Thu, 1 Feb 2024 19:35:45 -0800 Subject: [PATCH 12/14] added the correct voltage configurations for the pedals --- src/devices/io/PotThrottle.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/devices/io/PotThrottle.cpp b/src/devices/io/PotThrottle.cpp index 08e6ece..b85b32a 100644 --- a/src/devices/io/PotThrottle.cpp +++ b/src/devices/io/PotThrottle.cpp @@ -265,9 +265,10 @@ void PotThrottle::loadConfiguration() { //5 volts = 1000 when max is 4090 //910 dif = 18.2% dif - prefsHandler->read("ThrottleMax1", (uint16_t *)&config->maximumLevel1, 4090); - prefsHandler->read("ThrottleMin2", (uint16_t *)&config->minimumLevel2, 0); - prefsHandler->read("ThrottleMax2", (uint16_t *)&config->maximumLevel2, 4090); + prefsHandler->read("ThrottleMax1", (uint16_t *)&config->maximumLevel1, 3353); + prefsHandler->read("ThrottleMin2", (uint16_t *)&config->minimumLevel2, 298); + prefsHandler->read("ThrottleMax2", (uint16_t *)&config->maximumLevel2, 1680); + prefsHandler->read("ThrottleMin1", (uint16_t *)&config->minimumLevel1, 598); prefsHandler->read("NumThrottles", &config->numberPotMeters, 2); prefsHandler->read("ThrottleType", &config->throttleSubType, 1); prefsHandler->read("ADC1", &config->AdcPin1, 0); From 45f5d4d51b69dca5b01147a93bf789e364f0b8f5 Mon Sep 17 00:00:00 2001 From: atsai488 Date: Thu, 1 Feb 2024 19:43:38 -0800 Subject: [PATCH 13/14] updated inlucde tag that was on the wrong file path --- src/devices/motorctrl/BamocarMotorController.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/devices/motorctrl/BamocarMotorController.cpp b/src/devices/motorctrl/BamocarMotorController.cpp index 703c27c..130ee39 100644 --- a/src/devices/motorctrl/BamocarMotorController.cpp +++ b/src/devices/motorctrl/BamocarMotorController.cpp @@ -1,7 +1,7 @@ /* * BamocarMotorController.cpp */ -#include "../PotThrottle.h" +#include "../io/PotThrottle.h" #include "BamocarMotorController.h" #include From cd347b9814896dea516dcf4501be2c6f745dc9c9 Mon Sep 17 00:00:00 2001 From: atsai488 Date: Tue, 6 Feb 2024 20:42:38 -0800 Subject: [PATCH 14/14] CAN messages to motor controller from pedal with linear mapping and kick notch --- src/devices/io/PotThrottle.cpp | 12 +++++++++++- src/devices/io/PotThrottle.h | 3 ++- src/devices/io/Throttle.cpp | 2 +- .../motorctrl/BamocarMotorController.cpp | 18 ++++++++++++------ src/devices/motorctrl/MotorController.cpp | 18 +++++++++--------- 5 files changed, 35 insertions(+), 18 deletions(-) diff --git a/src/devices/io/PotThrottle.cpp b/src/devices/io/PotThrottle.cpp index b85b32a..abe6875 100644 --- a/src/devices/io/PotThrottle.cpp +++ b/src/devices/io/PotThrottle.cpp @@ -227,6 +227,13 @@ int16_t PotThrottle::calculatePedalPosition(RawSignalData *rawSignal) { calcThrottle2 = 1000 - calcThrottle2; calcThrottle1 = (calcThrottle1 + calcThrottle2) / 2; // now the average of the two } + + // int a = (calcThrottle1/10); + // uint32_t firsthalf = (a & 0xFF); + // uint32_t secondhalf = ((a >> 8) & 0xFF); + + + return calcThrottle1; } @@ -315,7 +322,10 @@ String PotThrottle::describeThrottleType() if (config->throttleSubType == 2) return String("Inverse Linear"); return String("Invalid Value!"); } - +int16_t PotThrottle::getLevel() +{ + return calculatePedalPosition(acquireRawSignal()); +} //creation of a global variable here causes the driver to automatically register itself without external help PotThrottle potThrottle; diff --git a/src/devices/io/PotThrottle.h b/src/devices/io/PotThrottle.h index f6ab331..7ae65ce 100644 --- a/src/devices/io/PotThrottle.h +++ b/src/devices/io/PotThrottle.h @@ -70,11 +70,12 @@ class PotThrottle: public Throttle { void loadConfiguration(); void saveConfiguration(); - int16_t calculatePedalPosition(RawSignalData *); + int16_t getLevel(); protected: bool validateSignal(RawSignalData *); String describeThrottleType(); + int16_t calculatePedalPosition(RawSignalData *); private: RawSignalData rawSignal; diff --git a/src/devices/io/Throttle.cpp b/src/devices/io/Throttle.cpp index 3d142c5..42a5261 100644 --- a/src/devices/io/Throttle.cpp +++ b/src/devices/io/Throttle.cpp @@ -155,7 +155,7 @@ int16_t Throttle::mapPedalPosition(int16_t pedalPosition) { status = ERR_MISC; } - if (throttleLevel > 1050) { + if (throttleLevel > 1300) { Logger::error("Generated throttle level (%i) was way too high!", throttleLevel); throttleLevel = 0; status = ERR_MISC; diff --git a/src/devices/motorctrl/BamocarMotorController.cpp b/src/devices/motorctrl/BamocarMotorController.cpp index 130ee39..a0b261c 100644 --- a/src/devices/motorctrl/BamocarMotorController.cpp +++ b/src/devices/motorctrl/BamocarMotorController.cpp @@ -43,15 +43,21 @@ void BamocarMotorController::handleTick() { //willl never really have a cruising speed //linear //max push max acceleration + MotorController::handleTick(); - PotThrottle throttle; - int percent = throttle.calculatePedalPosition(throttle.acquireRawSignal()); + if (throttleRequested < 0) throttleRequested = 0; + if (throttleRequested > 1000 && throttleRequested < 1300) throttleRequested = 1000; + if (throttleRequested > 1400) throttleRequested = 0; - //rounding to nearest 10th - int a = (percent/10); + - uint32_t firsthalf = (input & 0xFF); - uint32_t secondhalf = ((input >> 8) & 0xFF); + // //rounding to nearest 10th + int a = (throttleRequested/10); + a = a*327; + uint32_t firsthalf = (a & 0xFF); + uint32_t secondhalf = ((a >> 8) & 0xFF); + + // Logger::warn("First half %i | Second half %i", firsthalf, secondhalf); // check if the motor will still spin even if the pedal is released all the way up var.len = 3; diff --git a/src/devices/motorctrl/MotorController.cpp b/src/devices/motorctrl/MotorController.cpp index 55cb69b..a417ce3 100644 --- a/src/devices/motorctrl/MotorController.cpp +++ b/src/devices/motorctrl/MotorController.cpp @@ -149,19 +149,19 @@ void MotorController::handleTick() { //Throttle check Throttle *accelerator = deviceManager.getAccelerator(); - Throttle *brake = deviceManager.getBrake(); + //Throttle *brake = deviceManager.getBrake(); if (accelerator) throttleRequested = accelerator->getLevel(); - if (brake && brake->getLevel() < -10 && brake->getLevel() < accelerator->getLevel()) //if the brake has been pressed it overrides the accelerator. - throttleRequested = brake->getLevel(); + // if (brake && brake->getLevel() < -10 && brake->getLevel() < accelerator->getLevel()) //if the brake has been pressed it overrides the accelerator. + // throttleRequested = brake->getLevel(); //Logger::debug("Throttle: %d", throttleRequested); - if(skipcounter++ > 30) //A very low priority loop for checks that only need to be done once per second. - { - skipcounter=0; //Reset our laptimer - checkEnableInput(); - checkReverseInput(); - } + // if(skipcounter++ > 30) //A very low priority loop for checks that only need to be done once per second. + // { + // skipcounter=0; //Reset our laptimer + // checkEnableInput(); + // checkReverseInput(); + // } } /*