Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -945,6 +945,7 @@ _deps
##### C++
# Prerequisites
*.d
*.clangd

# Compiled Object files
*.slo
Expand Down
2 changes: 2 additions & 0 deletions GEVCU7.ino
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,8 @@ void testGEVCUHardware()
Serial.print(val);
Serial.print(" ");
}

Serial.print("ADC19: " + systemIO.getAnalogIn(19));
Serial.println();

Serial.print("DIN: ");
Expand Down
1 change: 1 addition & 0 deletions bms.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
//
11 changes: 6 additions & 5 deletions src/Heartbeat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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", ((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),
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<BatteryManager *>(deviceManager.getDeviceByType(DEVICE_BMS));
if (!bms) {
Expand Down
39 changes: 30 additions & 9 deletions src/devices/io/PotThrottle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -226,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;
}

Expand Down Expand Up @@ -254,14 +262,24 @@ 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("ThrottleMin2", (uint16_t *)&config->minimumLevel2, 0);
prefsHandler->read("ThrottleMax2", (uint16_t *)&config->maximumLevel2, 0);
prefsHandler->read("NumThrottles", &config->numberPotMeters, 1);
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, 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);
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
Expand Down Expand Up @@ -304,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;

Expand Down
4 changes: 3 additions & 1 deletion src/devices/io/PotThrottle.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,13 @@ class PotThrottle: public Throttle {

void loadConfiguration();
void saveConfiguration();

int16_t getLevel();

protected:
bool validateSignal(RawSignalData *);
int16_t calculatePedalPosition(RawSignalData *);
String describeThrottleType();
int16_t calculatePedalPosition(RawSignalData *);

private:
RawSignalData rawSignal;
Expand Down
2 changes: 1 addition & 1 deletion src/devices/io/Throttle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/devices/io/Throttle.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
43 changes: 43 additions & 0 deletions src/devices/misc/CANRecieveTest.cpp
Original file line number Diff line number Diff line change
@@ -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;
33 changes: 33 additions & 0 deletions src/devices/misc/CANRecieveTest.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#ifndef CANRecieveTest_H_
#define CANRecieveTest_H_

#include <Arduino.h>
#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
Empty file added src/devices/misc/analogTest.cpp
Empty file.
65 changes: 65 additions & 0 deletions src/devices/misc/testDevice.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
#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 = 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;
25 changes: 25 additions & 0 deletions src/devices/misc/testDevice.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#ifndef testDevice_H_
#define testDevice_H_

#include <Arduino.h>
#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
Loading