diff --git a/PowerBoardSoftware/PowerBoardSoftware.ino b/PowerBoardSoftware/PowerBoardSoftware.ino deleted file mode 100644 index 3daf712..0000000 --- a/PowerBoardSoftware/PowerBoardSoftware.ino +++ /dev/null @@ -1,430 +0,0 @@ -/* -* POWERBOARD SOFTWARE -* Patrick Sanchez -* Missouri University of Science and Technology -* Mars Rover Design Team -* 2020, Revision 1 -*/ - -//C types -#include -#include -#include -#include "Energia.h" - -//RoveComm -#include - -RoveCommEthernet RoveComm; -rovecomm_packet packet; - -const uint16_t ROVECOMM_TELEM_RATE = 1000; -const uint16_t NO_ROVECOMM_MESSAGE = 0; - -//Current readings -const uint16_t MOTOR_CURRENT_READING = 3105; //M1,M2,M3,M4,M5,M6,M7,Spare (last 2 unused atm) -const uint16_t ACT_LOG_CURRENT_READING = 3106; //Actuation, Logic -const uint16_t MISC_30V_CURRENT_READING = 3107; //12V Board, Rockets, Auxiliary -const uint16_t VAC_CURRENT_READING = 3108; //Vacuum - -//Bus control -//Disable = 0, Enable = 1 -const uint16_t MOTOR_ENABLE = 3100; //M1,M2,M3,M4,M5,M6,M7,Spare (last 2 unused atm) -const uint16_t ACT_LOG_ENABLE = 3101; //Actuation,Logic -const uint16_t MISC_30V_ENABLE = 3102; //12V Board, Rockets, Auxiliary -const uint16_t VAC_ENABLE = 3103; //Vacuum -const uint16_t PATCH_ENABLE = 3104; //PB1,PB2,PB3,PB4,PB5,PB6,PB7,PB8 - - -//TIVA PIN MAPPINGS -//ANALOG PINS -//30V -#define RKT_ISENSE PE_4 -#define TWV_ISENSE PE_5 -#define AUX_ISENSE PD_3 -#define VAC_ISENSE PE_2 -#define M1_ISENSE PD_4 -#define M2_ISENSE PK_1 -#define M3_ISENSE PK_3 -#define M4_ISENSE PD_2 -#define M5_ISENSE PB_4 -#define M6_ISENSE PE_1 -//12V -#define LOG_ISENSE PD_7 -#define ACT_ISENSE PE_3 - -//TEMPORARY MAPPINGS BECAUSE I DID BAD -#define LOG_EN PA_6 -#define ACT_EN PD_7 -//end temp stuff - -//DIGITAL PINS -//Error LED -#define ERROR PB_3 -//30V -#define RKT_EN PB_2 -#define TWV_EN PC_6 -#define AUX_EN PC_7 -#define VAC_EN PC_5 -#define M1_EN PP_1 -#define M2_EN PD_5 -#define M3_EN PQ_0 -#define M4_EN PN_5 -#define M5_EN PP_0 -#define M6_EN PE_0 -//12V -//#define LOG_EN PM_4 -//#define ACT_EN PA_6 -#define VOUT_EN PM_5 -//Patch Panel -#define PB1_EN PL_3 -#define PB2_EN PF_3 -#define PB3_EN PL_2 -#define PB4_EN PG_0 -#define PB5_EN PL_1 -#define PB6_EN PL_4 -#define PB7_EN PL_0 -#define PB8_EN PL_5 - -//Current sense mapping values -const uint16_t ADCMin = 330; -const uint16_t ADCMax = 4095; -const uint16_t ISENSEMin = 0; -const uint16_t ISENSEMax = 40000; -const float CURR_SCALER = 1.15; - -//Overcurrent constants (amps) -const uint8_t OCP_MOTOR = 180; //temp fix due to inaccurate current readings on Motor busses -const uint8_t OCP_12V = 18; -const uint8_t OCP_30V = 18; -const uint8_t OCP_RKT = 4; -const uint8_t OCP_VAC = 13; -const uint16_t RESET_TIME = 5000; //ms between tripping OCP and turn on - - -struct Bus -{ - int EN_PIN; - int ISENSE_PIN = -1;//default for busses without ISENSE pins - bool enabled = false; - - Bus(const int en, const int isense) - { - EN_PIN = en; - ISENSE_PIN = isense; - pinMode(ISENSE_PIN,INPUT); - pinMode(EN_PIN,OUTPUT); - } - - Bus(const int en) - { - EN_PIN = en; - pinMode(EN_PIN,OUTPUT); - } - -}; - -Bus busses_Motor[6] = {Bus(M1_EN,M1_ISENSE),Bus(M2_EN,M2_ISENSE),Bus(M3_EN,M3_ISENSE),Bus(M4_EN,M4_ISENSE),Bus(M5_EN,M5_ISENSE),Bus(M6_EN,M6_ISENSE)}; -Bus busses_12V[3] = {Bus(ACT_EN,ACT_ISENSE),Bus(LOG_EN,LOG_ISENSE),Bus(VOUT_EN)}; -Bus busses_30V[3] = {Bus(TWV_EN,TWV_ISENSE),Bus(RKT_EN,RKT_ISENSE),Bus(AUX_EN,AUX_ISENSE)}; -Bus vac = Bus(VAC_EN,VAC_ISENSE); -//the last time in millis() when telemetry was sent -unsigned long lastTelemTime = 0; - - -void setup() { - Serial.begin(9600); - RoveComm.begin(RC_POWERBOARD_FOURTHOCTET, RC_ROVECOMM_ETHERNET_POWERBOARD_PORT); - delay(100); - Serial.println("Started"); - - //turning on all 30V busses - for(int i = 0; i < 3; i++) - { - digitalWrite(busses_30V[i].EN_PIN,HIGH); - busses_30V[i].enabled = true; - } - - //turning on all 12V busses - for(int i = 0; i < 3; i++) - { - digitalWrite(busses_12V[i].EN_PIN,HIGH); - busses_12V[i].enabled = true; - } - - //turning on the ACT bus as well - pinMode(PD_7, OUTPUT); - digitalWrite(PD_7, HIGH); - - delay(3000); - - //turning on all motor busses - for(int i = 0; i < 6; i++) - { - digitalWrite(busses_Motor[i].EN_PIN,HIGH); - busses_Motor[i].enabled = true; - } - delay(500); -} - -void loop() -{ - //read - packet = RoveComm.read(); - //Serial.println(packet.data_id); - - //Motor bus switches - switch(packet.data_id) - { - case RC_POWERBOARD_MOTOR_BUSENABLE_DATAID: - { - //expects data to be an array with a single uint8 - //checks each bit. Bit 0 is M1, bit 1 is M2, etc. - for(int i = 0; i < 6; i++) - { - if(packet.data[0] & 1<= OCP_MOTOR) - { - //disable bus - digitalWrite(busses_Motor[i].EN_PIN,LOW); - busses_Motor[i].enabled = false; - //save error - error_motor |= 1<= OCP_MOTOR) - { - //disable bus - digitalWrite(busses_12V[i].EN_PIN,LOW); - busses_12V[i].enabled = false; - //save error - error_12V |= 1<= OCP_MOTOR || (i==1 && curr_30V[i] >= OCP_RKT)) - { - //disable bus - digitalWrite(busses_30V[i].EN_PIN,LOW); - busses_30V[i].enabled = false; - //save error - error_30V |= 1<= OCP_VAC) - { - //disable bus - digitalWrite(vac.EN_PIN,LOW); - vac.enabled = false; - //save error - error_vac = true; - } - - - if(error_motor /*|| error_12V*/ || error_30V || error_vac) - { - //NEED ERROR LED ACTIVATION ONCE THE LED WORKS - if(error_motor) - { - RoveComm.write(RC_POWERBOARD_MOTOR_BUS_OVERCURRENT_DATAID, RC_POWERBOARD_MOTOR_BUS_OVERCURRENT_DATACOUNT, error_motor); - } - /* - if(error_12V) - { - RoveComm.write(RC_POWERBOARD_12V_BUS_OVERCURRENT_DATAID, RC_POWERBOARD_12V_BUS_OVERCURRENT_DATACOUNT, error_12V); - } - */ - if(error_30V) - { - RoveComm.write(RC_POWERBOARD_30V_BUS_OVERCURRENT_DATAID, RC_POWERBOARD_30V_BUS_OVERCURRENT_DATACOUNT, error_30V); - //check if the error is on Rockets - if(error_30V & 1<<1) - { - //wait, then reenable - delay(RESET_TIME); - digitalWrite(busses_30V[1].EN_PIN,HIGH); - busses_30V[1].enabled = true; - } - } - if(error_vac) - { - RoveComm.write(RC_POWERBOARD_VACUUM_OVERCURRENT_DATAID, RC_POWERBOARD_VACUUM_OVERCURRENT_DATACOUNT, error_motor); - } - } - - //send the telemetry at the specified rate - if((millis() - lastTelemTime) >= ROVECOMM_TELEM_RATE) - { - //write the telemetry as a batch - Serial.println("Sending telemetry"); - RoveComm.write(RC_POWERBOARD_MOTOR_BUS_CURRENT_DATAID, RC_POWERBOARD_MOTOR_BUS_CURRENT_DATACOUNT, curr_motor); - RoveComm.write(RC_POWERBOARD_MOTOR_BUSENABLED_DATAID, RC_POWERBOARD_MOTOR_BUSENABLED_DATACOUNT, en_motor); - RoveComm.write(RC_POWERBOARD_VACUUM_CURRENT_DATAID, RC_POWERBOARD_VACUUM_CURRENT_DATACOUNT, curr_vac); - RoveComm.write(RC_POWERBOARD_VACUUM_ENABLED_DATAID, RC_POWERBOARD_VACUUM_ENABLED_DATACOUNT, en_vac); - lastTelemTime = millis(); - } -} \ No newline at end of file diff --git a/powerboardcode/powerboard/powerboard.h b/powerboardcode/powerboard/powerboard.h new file mode 100644 index 0000000..5e15ccd --- /dev/null +++ b/powerboardcode/powerboard/powerboard.h @@ -0,0 +1,62 @@ + +#include "Energia.h" +#include "RoveComm.h" +//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 + +//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 + +//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 + +//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}; + +RoveCommEthernet RoveComm; +rovecomm_packet packet; +EthernetServer TCPServer(RC_ROVECOMM_POWERBOARD_PORT); + diff --git a/powerboardcode/powerboard/powerboard.ino b/powerboardcode/powerboard/powerboard.ino new file mode 100644 index 0000000..b7721ef --- /dev/null +++ b/powerboardcode/powerboard/powerboard.ino @@ -0,0 +1,206 @@ +#include "powerboard.h" +void setup() +{ + Serial.begin(9600); + setPins(); + setPinStates(); + Serial.begin(9600); + RoveComm.begin(RC_POWERBOARD_FOURTHOCTET, &TCPServer); + delay(100); +} + +void loop() +{ + packet = RoveComm.read(); + 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++) + { + if (packet.data[0] & 1<