Fork and fix for mwork
Dependencies: mbed-dev-f303 FastPWM3 millis
Diff: main.cpp
- Revision:
- 55:fee62d8fd8fb
- Parent:
- 54:3e056b097c52
- Child:
- 56:eaf75bcad361
--- a/main.cpp Tue Mar 03 00:53:49 2020 +0000 +++ b/main.cpp Fri Jun 26 01:26:53 2020 +0000 @@ -13,16 +13,11 @@ #define VERSION_NUM "2.0.0" // this sets up the 2 IO modes of the UART connector (UART and Step/Dir) -#define IO_MODE_NONE 0 -#define IO_MODE_SERIAL 1 -#define IO_MODE_STEP_DIR 2 + #define UART_TX PA_2 // define the pins on the connector #define UART_RX PA_3 // define the pins on the connector #define UART_BAUD 230400 -int io_mode = IO_MODE_NONE; // the default mode is serial - -float __float_reg[64]; // Floats stored in flash -int __int_reg[256]; // Ints stored in flash. Includes position sensor calibration lookup table + // Ints stored in flash. Includes position sensor calibration lookup table #include "mbed.h" #include "PositionSensor.h" @@ -40,7 +35,12 @@ #include "PreferenceWriter.h" #include "CAN_com.h" #include "DRV.h" - +#include "mode.h" + +int io_mode = IO_MODE_NONE; // the default mode is serial + +float __float_reg[64]; // Floats stored in flash +int __int_reg[256]; PreferenceWriter prefs(6); GPIOStruct gpio; @@ -107,13 +107,13 @@ } +/* // Checks to see if in Serial mode before printing void cond_printf(const char *format, ...) { if (io_mode != IO_MODE_SERIAL) { return; } - char loc_buf[64]; char * temp = loc_buf; va_list arg; @@ -136,6 +136,8 @@ } } +*/ + // Interupt function for receiving step signal void stepInt() { if (dir) { @@ -147,7 +149,7 @@ // CAN message received void onMsgReceived() { - //msgAvailable = true; + //msgAvailable = true; //0A FF FF FF FF FF //cond_printf("%df\n\r", rxMsg.id); can.read(rxMsg); if((rxMsg.id == CAN_ID)){ @@ -187,8 +189,8 @@ } else if(state == MOTOR_MODE){ unpack_cmd(rxMsg, &controller); - } - + } + cond_printf("CAN BUS: %f ,%f, %f\n\r", rxMsg.data[0], rxMsg.data[1], rxMsg.data[2]); pack_reply(&txMsg, controller.theta_mech, controller.dtheta_mech, controller.i_q_filt*KT_OUT); can.write(txMsg); } @@ -471,16 +473,20 @@ controller.i_d_ref = 0; break; case 'f': // move forward - controller.p_des += 0.02f; + controller.p_des += 0.2f; cond_printf("p_des: %.3f\r\n", controller.p_des); break; - case 'r': // move back - controller.p_des -= 0.02f; + case 'b': // move back + controller.p_des -= 0.2f; cond_printf("p_des: %.3f\r\n", controller.p_des); break; case 'p': // show posiiton cond_printf("Pos: %.3f Vel: %.3f Cur: %.3f\r\n", controller.theta_mech, controller.dtheta_mech, controller.i_q_filt*KT_OUT); break; + case 's': // show posiiton + pack_reply(&txMsg, 0, 0 ,1); + can.write(txMsg); + break; } } @@ -551,7 +557,7 @@ init_controller_params(&controller); - set_io_mode(IO_MODE_SERIAL); + set_io_mode(IO_MODE_STEP_DIR); wait_us(100); cond_printf("\n\r\n\r Hobby King Cheetah\n\r\n\r"); wait_us(10);