Skip to content
Open
Show file tree
Hide file tree
Changes from 2 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
3 changes: 0 additions & 3 deletions include/motor_control.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,4 @@ PDCStates get_state();
extern volatile float rpm;
extern volatile float motorSpeedSetpoint;

// cruise control variables
PID *curr_PID;

#endif
74 changes: 72 additions & 2 deletions src/main.cpp
Original file line number Diff line number Diff line change
@@ -1,16 +1,86 @@
#include <Arduino.h>
#include "IOManagement.h"
#include "const.h"

#include "canPDC.h"
#include "const.h"
#include "IOManagement.h"
#include "motor_control.h"
#include "adc.h"

//For random
#include <stdlib.h>
#include <time.h>

int counter;
Comment thread
YVishere marked this conversation as resolved.
Outdated

//Counter for debug prints 20 ticks equates to a second
int counterExpiry = 20;
Comment thread
YVishere marked this conversation as resolved.
Outdated
CANPDC canBus(CAN1, DEF);


#if DEBUG_TECHNIQUE == 1
void initData() {
Comment thread
YVishere marked this conversation as resolved.
Outdated
// Generate a random float between 0 and 100
acc_out = ((float)rand() / RAND_MAX) * 100;
regen_brake = ((float)rand() / RAND_MAX) * 100;
lv_12V_telem = ((float)rand() / RAND_MAX) * 100;
lv_5V_telem = ((float)rand() / RAND_MAX) * 100;
lv_5V_current = ((float)rand() / RAND_MAX) * 100;
current_in_telem = ((float)rand() / RAND_MAX) * 100;
brake_pressure_telem = ((float)rand() / RAND_MAX) * 100;

//Random boolean
brakeLED = rand() % 2;

//Random digital data
digital_data.direction = rand() % 2;
digital_data.mc_speed_sig = rand() % 2;
digital_data.eco_mode = rand() % 2;
digital_data.mcu_mc_on = rand() % 2;
digital_data.park_brake = rand() % 2;
}
void debugPrint() {
Serial.printf("acc_out: %f\n", acc_out);
Serial.printf("regen_brake: %f\n", regen_brake);
Serial.printf("lv_12V_telem: %f\n", lv_12V_telem);
Serial.printf("lv_5V_telem: %f\n", lv_5V_telem);
Serial.printf("lv_5V_current: %f\n", lv_5V_current);
Serial.printf("current_in_telem: %f\n", current_in_telem);
Serial.printf("brake_pressure_telem: %f\n", brake_pressure_telem);
Serial.printf("brakeLED: %i\n", brakeLED);
Serial.printf("digital_data.direction: %i\n", digital_data.direction);
Serial.printf("digital_data.mc_speed_sig: %i\n", digital_data.mc_speed_sig);
Serial.printf("digital_data.eco_mode: %i\n", digital_data.eco_mode);
Serial.printf("digital_data.mcu_mc_on: %i\n", digital_data.mcu_mc_on);
Serial.printf("digital_data.park_brake: %i\n", digital_data.park_brake);
}
#endif


void setup() {
#if DEBUG_TECNIQUE
Comment thread
YVishere marked this conversation as resolved.
Outdated
int counter = 0;
Comment thread
YVishere marked this conversation as resolved.
Outdated
#endif

Serial.begin(115200);
initADC(ADC1);
initIO();
initPDCState();

//initialize random
srand(time(NULL));
}

void loop() {
// Display digital and analog values every second (for testing)
if (DEBUG_TECHNIQUE == 1){
if (counter >= counterExpiry) {
debugPrint();
counter = 0;
}
counter++;
}

initData();
Comment thread
YVishere marked this conversation as resolved.
Outdated
canBus.sendPDCData();
canBus.runQueue(DATA_SEND_PERIOD);
}
3 changes: 3 additions & 0 deletions src/motor_control.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@

#include "motor_control.h"

// cruise control variables
PID *curr_PID;

volatile PDCStates pdcState = PDCStates::OFF;
volatile CRUZ_MODE cruzMode = CRUZ_MODE::OFF;

Expand Down