diff --git a/powerboardcode/powerboard/powerboard.h b/powerboardcode/powerboard/powerboard.h index 5e15ccd..e02c80a 100644 --- a/powerboardcode/powerboard/powerboard.h +++ b/powerboardcode/powerboard/powerboard.h @@ -1,62 +1,107 @@ - -#include "Energia.h" +#ifndef POWERBOARD_H +#define POWERBOARD_H #include "RoveComm.h" + +// Numbers of Toggleable Ports +#define NUM_12V_PORTS 8 // Everything except Aux cuz Manifest +#define NUM_MOTORS 7 + +IntervalTimer Telemetry; + //12V Current Sensing -#define AUX_MOUNT_SENSE PK_3 -#define MULTIMEDIA_SENSE PK_2 -#define LOW_CURRENT_SENSE PK_1 -#define GIMBAL_SENSE PK_0 + +#define MULTIMEDIA_SENSE A11 +#define NAV_SENSE A12 +#define GIMBAL_ACT_SENSE A10 +#define DRIVE_SENSE A0 +#define CAM1_SENSE A2 +#define CAM2_SENSE A1 +#define BBB_SENSE A3 +#define AUX_SENSE A4 +#define SPARE_12V_SENSE A13 + +#define OVERCURRENT_PACK 19500 //mA +#define OVERCURRENT_12V 4800 //mA +#define CURRENT_ADC_MIN 0 +#define CURRENT_ADC_MAX 4096 +#define CURRENT_mA_MIN 0 +#define CURRENT_mA_MAX 20000 //12V CTL -#define MULTIMEDIA_LOG_CTL PK_5 -#define MULTIMEDIA_ACT_CTL PM_0 -#define AUX_LOG_CTL PM_1 -#define AUX_ACT_CTL PM_2 -#define GIMBAL_LOG_CTL PH_0 -#define GIMBAL_ACT_CTL PH_1 -#define NAV_BOARD_CTL PK_7 -#define CAM_CTL PP_3 -#define EXTRA_CTL PQ_1 -#define DRIVE_CTL PM_6 +#define SPARE_CTL 0 +#define NAV_CTL 1 +#define MULTIMEDIA_CTL 2 +#define GIMBAL_CTL 3 +#define DRIVE_CTL 4 +#define CAM2_CTL 5 +#define CAM1_CTL 6 +#define BBB_CTL 7 +#define AUX_CTL 8 + //PACK CURRENT -#define P_MOTOR1_SENSE PD_5 -#define P_MOTOR2_SENSE PD_4 -#define P_MOTOR3_SENSE PD_2 -#define P_MOTOR4_SENSE PD_3 -#define P_SPARE_SENSE PE_4 -#define P_ROCKET_SENSE PD_0 -#define P_TWELVE_SENSE PD_1 -#define P_VACUUM_SENSE PE_1 -#define P_DRIVE_SENSE PE_5 -#define P_AUX_SENSE PE_3 +#define P_MOTOR1_SENSE A14 +#define P_MOTOR2_SENSE A15 +#define P_MOTOR3_SENSE A16 +#define P_MOTOR4_SENSE A17 +#define P_MOTOR5_SENSE A5 +#define P_MOTOR6_SENSE A6 +#define P_MOTOR7_SENSE A7 +#define P_POE_SENSE A8 + +// Current sensing variables + +float MOTORBUSSENSEPINS[NUM_MOTORS] = {P_MOTOR1_SENSE, P_MOTOR2_SENSE, P_MOTOR3_SENSE, P_MOTOR4_SENSE, P_MOTOR5_SENSE, P_MOTOR6_SENSE, P_MOTOR7_SENSE}; +float TWELVELOGICBUSPINS[NUM_12V_PORTS] = {GIMBAL_ACT_SENSE, DRIVE_SENSE, MULTIMEDIA_SENSE, NAV_SENSE, CAM1_SENSE, CAM2_SENSE, BBB_SENSE, SPARE_12V_SENSE}; + +float P_MOTOR1_CURRENT = 0; +float P_MOTOR2_CURRENT = 0; +float P_MOTOR3_CURRENT = 0; +float P_MOTOR4_CURRENT = 0; +float P_MOTOR5_CURRENT = 0; +float P_MOTOR6_CURRENT = 0; +float P_MOTOR7_CURRENT = 0; + +float AUX_CURRENT = 0; + +float GIMBAL_ACT_CURRENT = 0; +float DRIVE_CURRENT = 0; +float MULTIMEDIA_CURRENT = 0; +float NAV_CURRENT = 0; +float CAM1_CURRENT = 0; +float CAM2_CURRENT = 0; +float BBB_CURRENT = 0; +float SPARE_12V_CURRENT = 0; + +float MOTORBUSCURRENTS[NUM_MOTORS] = {P_MOTOR1_CURRENT, P_MOTOR2_CURRENT, P_MOTOR3_CURRENT, P_MOTOR4_CURRENT, P_MOTOR5_CURRENT, P_MOTOR6_CURRENT, P_MOTOR7_CURRENT}; +float TWELVELOGICBUSCURRENTS[NUM_12V_PORTS] = {GIMBAL_ACT_CURRENT, DRIVE_CURRENT, MULTIMEDIA_CURRENT, NAV_CURRENT, CAM1_CURRENT, CAM2_CURRENT, BBB_CURRENT, SPARE_12V_CURRENT}; + +uint8_t motorOverCurrent = 0; +uint8_t twelveActOverCurrent = 0; +uint8_t twelveLogicOverCurrent = 0; //PACK BUSSES -#define P_MOTOR1_CTL PQ_0 -#define P_MOTOR2_CTL PP_1 -#define P_MOTOR3_CTL PP_0 -#define P_MOTOR4_CTL PC_7 -#define P_SPARE_CTL PC_4 -#define P_ROCKET_CTL PN_2 -#define P_TWELVE_CTL PH_3 -#define P_VACUUM_CTL PE_0 -#define P_DRIVE_CTL PC_6 -#define P_AUX_CTL PE_2 - -#define MOTOR_DELAY 5000 -#define DRIVE_DELAY 5000 - -uint8_t currentSense12V[4] = { AUX_MOUNT_SENSE, MULTIMEDIA_SENSE, GIMBAL_SENSE, LOW_CURRENT_SENSE}; -uint8_t actuation12V[3] = { GIMBAL_ACT_CTL, MULTIMEDIA_ACT_CTL, AUX_ACT_CTL}; -uint8_t logic12V[7] = {GIMBAL_LOG_CTL, MULTIMEDIA_LOG_CTL, AUX_LOG_CTL, DRIVE_CTL, NAV_BOARD_CTL, CAM_CTL, EXTRA_CTL}; -uint8_t drivePack = P_DRIVE_CTL; -uint8_t currentSensePack[10] = { P_MOTOR1_SENSE, P_MOTOR2_SENSE, P_MOTOR3_SENSE, P_MOTOR4_SENSE, P_SPARE_SENSE, P_ROCKET_SENSE, P_TWELVE_SENSE, P_VACUUM_SENSE, P_DRIVE_SENSE, P_AUX_SENSE}; -uint8_t bussesPackStart[3] = { P_ROCKET_CTL, P_TWELVE_CTL, P_AUX_CTL}; -uint8_t bussesPack[4] = { P_TWELVE_CTL, P_ROCKET_CTL, P_AUX_CTL, P_DRIVE_CTL}; -uint8_t vacuumCtrl[1] = {P_VACUUM_CTL}; -uint8_t bussesMotor[5] = {P_MOTOR1_CTL, P_MOTOR2_CTL, P_MOTOR3_CTL, P_MOTOR4_CTL, P_SPARE_CTL}; +#define POE_CTL 29 +#define PACK_SPARE_CTL 37 + +#define MOTOR1_CTL 33 +#define MOTOR2_CTL 32 +#define MOTOR3_CTL 34 +#define MOTOR4_CTL 31 +#define MOTOR5_CTL 35 +#define MOTOR6_CTL 30 +#define MOTORS_CTL 36 + +#define MOTOR_DELAY 500 + +//uint8_t currentSense12V[] = {MULTIMEDIA_SENSE, NAV_SENSE, GIMBAL_ACT_SENSE, DRIVE_SENSE, SCISENSOR_ACT_SENSE, NETSWITCH_SENSE, CAM1_SENSE, CAM2_SENSE, BBB_SENSE, AUX_LOG_SENSE}; +uint8_t twelveVoltBusses[NUM_12V_PORTS] = {GIMBAL_CTL, DRIVE_CTL, MULTIMEDIA_CTL, NAV_CTL, CAM1_CTL, CAM2_CTL, BBB_CTL, SPARE_CTL}; +//uint8_t currentSensePack[9] = {P_MOTOR1_SENSE, P_MOTOR2_SENSE, P_MOTOR3_SENSE, P_MOTOR4_SENSE, P_MOTOR5_SENSE, P_MOTOR6_SENSE, P_MOTOR7_SENSE, P_POE_SENSE, P_AUX_SENSE}; +uint8_t motorBusses[NUM_MOTORS] = {MOTOR1_CTL, MOTOR2_CTL, MOTOR3_CTL, MOTOR4_CTL, MOTOR5_CTL, MOTOR6_CTL, MOTORS_CTL}; RoveCommEthernet RoveComm; rovecomm_packet packet; +uint8_t* data; EthernetServer TCPServer(RC_ROVECOMM_POWERBOARD_PORT); +#endif \ No newline at end of file diff --git a/powerboardcode/powerboard/powerboard.ino b/powerboardcode/powerboard/powerboard.ino index b7721ef..28ce03c 100644 --- a/powerboardcode/powerboard/powerboard.ino +++ b/powerboardcode/powerboard/powerboard.ino @@ -1,206 +1,214 @@ #include "powerboard.h" void setup() { - Serial.begin(9600); + Serial.begin(115200); setPins(); setPinStates(); - Serial.begin(9600); - RoveComm.begin(RC_POWERBOARD_FOURTHOCTET, &TCPServer); - delay(100); + RoveComm.begin(RC_POWERBOARD_FOURTHOCTET, &TCPServer, RC_ROVECOMM_POWERBOARD_MAC); + Telemetry.begin(telemetry, 1500000); } void loop() { packet = RoveComm.read(); + data = (uint8_t*)packet.data; if(packet.data_id != 0) { switch(packet.data_id) { case RC_POWERBOARD_MOTORBUSENABLE_DATA_ID: - Serial.println("Enable/Disable Motor Busses"); - for(int i = 0; i < 5; i++) + Serial.println("Enable/Disable Motor Busses: "); + for(int i = 0; i < NUM_MOTORS; i++) { - if (packet.data[0] & 1< OVERCURRENT_PACK) + { + motorOverCurrent |= (1 << i); + digitalWrite(motorBusses[i], LOW); + delay(1000); + digitalWrite(motorBusses[i], HIGH); + } + else + { + motorOverCurrent &= !(1 << i); + } } - // turn on 12 volt busses - for (int i = 0 ; i < 3 ; i++) + + AUX_CURRENT = senseCurrent(AUX_SENSE); + if (AUX_CURRENT > OVERCURRENT_12V) { - digitalWrite(actuation12V[i], HIGH); + twelveActOverCurrent = 1; + digitalWrite(AUX_CTL, LOW); + delay(1000); + digitalWrite(AUX_CTL, HIGH); } - // turns on Pack busses - for (int i = 0 ; i < 3 ; i++) + else { - digitalWrite(bussesPackStart[i], HIGH); + twelveActOverCurrent = 0; } - //turns off pack drive board bus - digitalWrite(drivePack, LOW); - digitalWrite(vacuumCtrl[0], LOW); - delay(MOTOR_DELAY); - // turns on motor busses after a delay - for (int i = 0 ; i < 5 ; i++) + + for (uint8_t i = 0; i < 8; i++) { - digitalWrite(bussesMotor[i], HIGH); + TWELVELOGICBUSCURRENTS[i] = senseCurrent(TWELVELOGICBUSPINS[i]); + + if (TWELVELOGICBUSCURRENTS[i] > OVERCURRENT_12V) + { + twelveLogicOverCurrent |= (1 << i); + digitalWrite(twelveVoltBusses[i], LOW); + delay(1000); + digitalWrite(twelveVoltBusses[i], HIGH); + } + else + { + twelveLogicOverCurrent &= !(1 << i); + } } - delay(DRIVE_DELAY); - // turns on pack drive bus - digitalWrite(drivePack, HIGH); + return; } -void read_CurrentSense() +void overCurrent() { - int motor1_sense = analogRead(P_MOTOR1_SENSE); - int motor2_sense = analogRead(P_MOTOR2_SENSE); - int motor3_sense = analogRead(P_MOTOR3_SENSE); - int motor4_sense = analogRead(P_MOTOR4_SENSE); - int spare_sense = analogRead(P_SPARE_SENSE); - int rocket_sense = analogRead(P_ROCKET_SENSE); - int twelve_sense = analogRead(P_TWELVE_SENSE); - int vacuum_sense = analogRead(P_VACUUM_SENSE); - int drive_sense = analogRead(P_DRIVE_SENSE); - int aux_sense = analogRead(P_AUX_SENSE); - - Serial.println("Motor 1 sense: "); - Serial.println(motor1_sense); - Serial.println("Motor 2 sense: "); - Serial.println(motor2_sense); - Serial.println("Motor 3 sense: "); - Serial.println(motor3_sense); - Serial.println("Motor 4 sense: "); - Serial.println(motor4_sense); - Serial.println("Spare sense: "); - Serial.println(spare_sense); - Serial.println("Rocket sense: "); - Serial.println(rocket_sense); - Serial.println("Twelve sense: "); - Serial.println(twelve_sense); - Serial.println("Vacuum sense: "); - Serial.println(vacuum_sense); - Serial.println("Drive sense: "); - Serial.println(drive_sense); - Serial.println("Aux sense: "); - Serial.println(aux_sense); + if (motorOverCurrent) + { + RoveComm.write(RC_POWERBOARD_MOTORBUSOVERCURRENT_DATA_ID, RC_POWERBOARD_MOTORBUSOVERCURRENT_DATA_COUNT, motorOverCurrent); + } + if (twelveActOverCurrent) + { + RoveComm.write(RC_POWERBOARD_TWELVEVACTBUSOVERCURRENT_DATA_ID, RC_POWERBOARD_TWELVEVACTBUSOVERCURRENT_DATA_COUNT, twelveActOverCurrent); + } + if (twelveLogicOverCurrent) + { + RoveComm.write(RC_POWERBOARD_TWELVEVLOGICBUSOVERCURRENT_DATA_ID, RC_POWERBOARD_TWELVEVLOGICBUSOVERCURRENT_DATA_COUNT, twelveLogicOverCurrent); + } + return; +} + +void telemetry() +{ + RoveComm.write(RC_POWERBOARD_MOTORBUSCURRENT_DATA_ID, RC_POWERBOARD_MOTORBUSCURRENT_DATA_COUNT, MOTORBUSCURRENTS); + delay(100); + RoveComm.write(RC_POWERBOARD_TWELVEVACTBUSCURRENT_DATA_ID, RC_POWERBOARD_TWELVEVACTBUSCURRENT_DATA_COUNT, AUX_CURRENT); + delay(100); + RoveComm.write(RC_POWERBOARD_TWELVEVLOGICBUSCURRENT_DATA_ID, RC_POWERBOARD_TWELVEVLOGICBUSCURRENT_DATA_COUNT, TWELVELOGICBUSCURRENTS); + delay(100); } \ No newline at end of file