J L
/
ringBuffer26
ringBuffer26
MotorControl.h@1:0cb065f9d55a, 2020-05-18 (annotated)
- Committer:
- Picmon
- Date:
- Mon May 18 19:04:41 2020 +0000
- Revision:
- 1:0cb065f9d55a
- Parent:
- 0:333434a8611b
ring buffer26;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Picmon | 0:333434a8611b | 1 | #ifndef MOTORCONTROL_H |
Picmon | 0:333434a8611b | 2 | #define MOTORCONTROL_H |
Picmon | 0:333434a8611b | 3 | |
Picmon | 0:333434a8611b | 4 | #include "mbed.h" |
Picmon | 0:333434a8611b | 5 | #include <string> |
Picmon | 0:333434a8611b | 6 | |
Picmon | 1:0cb065f9d55a | 7 | #define DEBUG |
Picmon | 1:0cb065f9d55a | 8 | |
Picmon | 1:0cb065f9d55a | 9 | |
Picmon | 1:0cb065f9d55a | 10 | #define ED_MIN_SPEED 1000 |
Picmon | 1:0cb065f9d55a | 11 | #define ED_MAX_SPEED 3000000 |
Picmon | 1:0cb065f9d55a | 12 | #define N_MIN_SPEED 0.001 |
Picmon | 1:0cb065f9d55a | 13 | #define N_MAX_SPEED 125.000//125.0RPM |
Picmon | 1:0cb065f9d55a | 14 | |
Picmon | 1:0cb065f9d55a | 15 | #define REV_MAX_STEPS -2147483648 |
Picmon | 1:0cb065f9d55a | 16 | #define FWD_MAX_STEPS 2147483648 |
Picmon | 1:0cb065f9d55a | 17 | |
Picmon | 1:0cb065f9d55a | 18 | #define MIN_CURRENT 0 |
Picmon | 1:0cb065f9d55a | 19 | #define MAX_CURRENT 6000//6000mA |
Picmon | 1:0cb065f9d55a | 20 | |
Picmon | 1:0cb065f9d55a | 21 | #define MIN_TORQUE 0 |
Picmon | 1:0cb065f9d55a | 22 | #define MAX_TORQUE 8500//N.m |
Picmon | 1:0cb065f9d55a | 23 | |
Picmon | 1:0cb065f9d55a | 24 | |
Picmon | 1:0cb065f9d55a | 25 | #define SPACE 0x20 |
Picmon | 1:0cb065f9d55a | 26 | #define ACK 0x06 |
Picmon | 1:0cb065f9d55a | 27 | #define NAK 0x15 |
Picmon | 1:0cb065f9d55a | 28 | |
Picmon | 1:0cb065f9d55a | 29 | #define VALID_MSG_LEN 0x03 |
Picmon | 1:0cb065f9d55a | 30 | |
Picmon | 1:0cb065f9d55a | 31 | #define ML_ROTATION 5.6 |
Picmon | 1:0cb065f9d55a | 32 | #define STEPS_PER_ROTATION 1024 |
Picmon | 1:0cb065f9d55a | 33 | |
Picmon | 1:0cb065f9d55a | 34 | #define CW 1 |
Picmon | 1:0cb065f9d55a | 35 | #define CCW 0 |
Picmon | 1:0cb065f9d55a | 36 | |
Picmon | 1:0cb065f9d55a | 37 | #define RX_ECHO_VALID 0 |
Picmon | 1:0cb065f9d55a | 38 | #define RX_ECHO_FAIL 1 |
Picmon | 1:0cb065f9d55a | 39 | #define RX_REGITSER_FAIL 2 |
Picmon | 1:0cb065f9d55a | 40 | #define RX_REGITSER_VALID 3 |
Picmon | 1:0cb065f9d55a | 41 | #define MSG_RESEND 4 |
Picmon | 0:333434a8611b | 42 | |
Picmon | 1:0cb065f9d55a | 43 | #define REBOOT 5 |
Picmon | 1:0cb065f9d55a | 44 | |
Picmon | 1:0cb065f9d55a | 45 | #define MSG_RETRY_COUNT 3 |
Picmon | 1:0cb065f9d55a | 46 | |
Picmon | 1:0cb065f9d55a | 47 | #define NOT_USED 0 |
Picmon | 1:0cb065f9d55a | 48 | #define STOP_NO_RAMP 0 |
Picmon | 1:0cb065f9d55a | 49 | #define STOP_WITH_RAMP 1 |
Picmon | 1:0cb065f9d55a | 50 | #define STOP_WITH_STEPS 2 |
Picmon | 1:0cb065f9d55a | 51 | |
Picmon | 1:0cb065f9d55a | 52 | #define BUFFER_SIZE 50//command message + data |
Picmon | 1:0cb065f9d55a | 53 | #define DATA_BUFFER_SIZE 20//characters |
Picmon | 1:0cb065f9d55a | 54 | #define DATA_ITEMS 19 |
Picmon | 1:0cb065f9d55a | 55 | |
Picmon | 1:0cb065f9d55a | 56 | //////////////////////////////////////////// |
Picmon | 1:0cb065f9d55a | 57 | // MOTOR COMMAND RESPONSE DATA STORAGE |
Picmon | 1:0cb065f9d55a | 58 | /////////////////////////////////////////// |
Picmon | 1:0cb065f9d55a | 59 | #define READ_DIG_IN 0 |
Picmon | 1:0cb065f9d55a | 60 | #define READ_DIG_OUT 1 |
Picmon | 1:0cb065f9d55a | 61 | #define READ_CURRENT 2 |
Picmon | 1:0cb065f9d55a | 62 | #define READ_DRV_REG 3 |
Picmon | 1:0cb065f9d55a | 63 | #define READ_DRV_REG_EXT 4 |
Picmon | 1:0cb065f9d55a | 64 | #define READ_DRV_TEMP 5 |
Picmon | 1:0cb065f9d55a | 65 | #define READ_DRV_VOLTAGE 6 |
Picmon | 1:0cb065f9d55a | 66 | #define READ_DRV_WORKING_SET 7 |
Picmon | 1:0cb065f9d55a | 67 | #define READ_DRV_WORKING_SET_EXT 8 |
Picmon | 1:0cb065f9d55a | 68 | #define READ_ERROR_REG 9 |
Picmon | 1:0cb065f9d55a | 69 | #define READ_FB_BOOST_CUR 10 |
Picmon | 1:0cb065f9d55a | 70 | #define READ_FB_STATUS 11 |
Picmon | 1:0cb065f9d55a | 71 | #define READ_FW_VERSION 12 |
Picmon | 1:0cb065f9d55a | 72 | #define READ_FW_CHECKSUM 13 |
Picmon | 1:0cb065f9d55a | 73 | #define READ_MASTER_REG 14 |
Picmon | 1:0cb065f9d55a | 74 | #define READ_MIN_CURRENT 15 |
Picmon | 1:0cb065f9d55a | 75 | #define READ_MAX_CURRENT 16 |
Picmon | 1:0cb065f9d55a | 76 | #define READ_BOOST_CURRENT 17 |
Picmon | 1:0cb065f9d55a | 77 | #define READ_NOM_CURRENT 18 |
Picmon | 1:0cb065f9d55a | 78 | |
Picmon | 1:0cb065f9d55a | 79 | #define COMMANDS_TO_TEST 10 |
Picmon | 0:333434a8611b | 80 | |
Picmon | 1:0cb065f9d55a | 81 | |
Picmon | 1:0cb065f9d55a | 82 | //////////////////////////////////////////// |
Picmon | 1:0cb065f9d55a | 83 | // BAUD RATES |
Picmon | 1:0cb065f9d55a | 84 | /////////////////////////////////////////// |
Picmon | 1:0cb065f9d55a | 85 | #define SLOW_BAUD 9600 |
Picmon | 1:0cb065f9d55a | 86 | #define MED_BAUD 115200 |
Picmon | 1:0cb065f9d55a | 87 | #define FAST_BAUD 921600 |
Picmon | 1:0cb065f9d55a | 88 | |
Picmon | 1:0cb065f9d55a | 89 | #define MOT_AL_PDT 0x0001//Protection Drive Thermal |
Picmon | 1:0cb065f9d55a | 90 | #define MOT_AL_PDV 0x0002//Protection Drive Voltage |
Picmon | 1:0cb065f9d55a | 91 | #define MOT_AL_PDC 0x0004//Protection Drive Current |
Picmon | 1:0cb065f9d55a | 92 | #define MOT_AL_POP 0x0008//Protection Open Phase |
Picmon | 1:0cb065f9d55a | 93 | #define MOT_AL_UNUSED1 0x0010//NOT USED |
Picmon | 1:0cb065f9d55a | 94 | #define MOT_AL_FE 0x0020//Feedback Error |
Picmon | 1:0cb065f9d55a | 95 | #define MOT_AL_PCR 0x0040//Protection Current Regulation |
Picmon | 1:0cb065f9d55a | 96 | #define MOT_AL_POT 0x0080//Protection Open Transistor |
Picmon | 1:0cb065f9d55a | 97 | #define MOT_AL_UNUSED2 0x0100//NOT USED |
Picmon | 1:0cb065f9d55a | 98 | #define MOT_AL_SWER 0x0200//Protection Software Error |
Picmon | 1:0cb065f9d55a | 99 | #define MOT_AL_UNUSED3 0x0400//NOT USED |
Picmon | 1:0cb065f9d55a | 100 | #define MOT_AL_MC 0x0800//Missing Calibration |
Picmon | 1:0cb065f9d55a | 101 | #define MOT_AL_WDG 0x1000//Watchdog |
Picmon | 1:0cb065f9d55a | 102 | #define MOT_AL_EEF 0x2000//EEPROM Fail |
Picmon | 1:0cb065f9d55a | 103 | #define MOT_AL_I2T 0x4000//I2T Potection |
Picmon | 1:0cb065f9d55a | 104 | #define MOT_AL_UNUSED4 0x8000//NOT USED |
Picmon | 1:0cb065f9d55a | 105 | |
Picmon | 0:333434a8611b | 106 | |
Picmon | 1:0cb065f9d55a | 107 | #define D3_BUTTON D3 |
Picmon | 1:0cb065f9d55a | 108 | #define D4_BUTTON D4 |
Picmon | 1:0cb065f9d55a | 109 | #define D5_BUTTON D5 |
Picmon | 1:0cb065f9d55a | 110 | #define D6_BUTTON D6 |
Picmon | 1:0cb065f9d55a | 111 | #define D7_BUTTON D7 |
Picmon | 1:0cb065f9d55a | 112 | #define D8_BUTTON D8 |
Picmon | 1:0cb065f9d55a | 113 | #define D9_BUTTON D9 |
Picmon | 1:0cb065f9d55a | 114 | #define D10_BUTTON D10 |
Picmon | 1:0cb065f9d55a | 115 | #define D11_BUTTON D11 |
Picmon | 1:0cb065f9d55a | 116 | #define D12_BUTTON D12 |
Picmon | 0:333434a8611b | 117 | |
Picmon | 1:0cb065f9d55a | 118 | #define A7_OUT1 A7 |
Picmon | 1:0cb065f9d55a | 119 | #define A6_OUT2 A6 |
Picmon | 1:0cb065f9d55a | 120 | #define A5_OUT3 A5 |
Picmon | 1:0cb065f9d55a | 121 | |
Picmon | 1:0cb065f9d55a | 122 | #define A4_IN1 A4 |
Picmon | 1:0cb065f9d55a | 123 | #define A3_IN2 A3 |
Picmon | 1:0cb065f9d55a | 124 | #define A2_IN3 A2 |
Picmon | 1:0cb065f9d55a | 125 | |
Picmon | 1:0cb065f9d55a | 126 | #define A1_OUT A1 |
Picmon | 1:0cb065f9d55a | 127 | #define A0_OUT A0 |
Picmon | 1:0cb065f9d55a | 128 | |
Picmon | 1:0cb065f9d55a | 129 | extern DigitalIn d3_button; |
Picmon | 1:0cb065f9d55a | 130 | extern DigitalIn d4_button; |
Picmon | 1:0cb065f9d55a | 131 | extern DigitalIn d5_button; |
Picmon | 1:0cb065f9d55a | 132 | extern DigitalIn d6_button; |
Picmon | 1:0cb065f9d55a | 133 | extern DigitalIn d7_button; |
Picmon | 1:0cb065f9d55a | 134 | extern DigitalIn d8_button; |
Picmon | 1:0cb065f9d55a | 135 | extern DigitalIn d9_button; |
Picmon | 1:0cb065f9d55a | 136 | extern DigitalIn d10_button; |
Picmon | 1:0cb065f9d55a | 137 | extern DigitalIn d11_button; |
Picmon | 1:0cb065f9d55a | 138 | extern DigitalIn d12_button; |
Picmon | 1:0cb065f9d55a | 139 | |
Picmon | 1:0cb065f9d55a | 140 | extern DigitalOut a7_out1; |
Picmon | 1:0cb065f9d55a | 141 | extern DigitalOut a6_out2; |
Picmon | 1:0cb065f9d55a | 142 | extern DigitalOut a5_out3; |
Picmon | 1:0cb065f9d55a | 143 | extern DigitalIn a4_in1; |
Picmon | 1:0cb065f9d55a | 144 | extern DigitalIn a3_in2; |
Picmon | 1:0cb065f9d55a | 145 | extern DigitalIn a2_in3; |
Picmon | 1:0cb065f9d55a | 146 | |
Picmon | 1:0cb065f9d55a | 147 | extern DigitalOut a1_out; |
Picmon | 1:0cb065f9d55a | 148 | extern DigitalOut a0_out; |
Picmon | 1:0cb065f9d55a | 149 | |
Picmon | 1:0cb065f9d55a | 150 | extern char motData[][DATA_BUFFER_SIZE];//data only |
Picmon | 1:0cb065f9d55a | 151 | |
Picmon | 1:0cb065f9d55a | 152 | extern char binBuffer[]; |
Picmon | 1:0cb065f9d55a | 153 | extern uint8_t cnt; |
Picmon | 0:333434a8611b | 154 | extern const string rxMsgTable[]; |
Picmon | 0:333434a8611b | 155 | extern char rxMsgStore[];//received local message store |
Picmon | 0:333434a8611b | 156 | extern char mc_Tx_Buffer[];//transmitted message buffer |
Picmon | 1:0cb065f9d55a | 157 | extern char mc_Rx_Buffer[];//received message buffer |
Picmon | 0:333434a8611b | 158 | extern volatile unsigned char mc_Rx_Rd_Ptr;//circulare buffer read pointer |
Picmon | 0:333434a8611b | 159 | extern volatile unsigned char mc_Rx_Wr_Ptr;//circulare buffer write pointer |
Picmon | 0:333434a8611b | 160 | extern unsigned int rx_int;//received integer / character |
Picmon | 1:0cb065f9d55a | 161 | extern volatile bool rxMsgValid;//message received flag |
Picmon | 1:0cb065f9d55a | 162 | extern bool msgRdy; |
Picmon | 0:333434a8611b | 163 | |
Picmon | 1:0cb065f9d55a | 164 | void motEncoderISR(void); |
Picmon | 1:0cb065f9d55a | 165 | |
Picmon | 1:0cb065f9d55a | 166 | void int2bin(int value, char* buffer, int bufferSize); |
Picmon | 0:333434a8611b | 167 | |
Picmon | 1:0cb065f9d55a | 168 | void rstPointers(void); |
Picmon | 1:0cb065f9d55a | 169 | |
Picmon | 1:0cb065f9d55a | 170 | void readCurrent(char *array); |
Picmon | 1:0cb065f9d55a | 171 | bool setDigOutput(uint8_t par1, char *array); |
Picmon | 1:0cb065f9d55a | 172 | void readDigInput(char *array); |
Picmon | 1:0cb065f9d55a | 173 | void clrRxMsg(char *array); |
Picmon | 0:333434a8611b | 174 | void motMsg_RX_ISR(void); |
Picmon | 1:0cb065f9d55a | 175 | uint8_t getMotMsg(char *txReadCmd, char *rxRegArray); |
Picmon | 1:0cb065f9d55a | 176 | |
Picmon | 0:333434a8611b | 177 | |
Picmon | 0:333434a8611b | 178 | |
Picmon | 0:333434a8611b | 179 | |
Picmon | 1:0cb065f9d55a | 180 | bool set_mL(bool direction, uint32_t mL, char *array); |
Picmon | 1:0cb065f9d55a | 181 | bool setRotMotor(bool direction, char *array); |
Picmon | 1:0cb065f9d55a | 182 | |
Picmon | 1:0cb065f9d55a | 183 | void initBuffer(string s, char *array, char character, uint8_t size); |
Picmon | 1:0cb065f9d55a | 184 | |
Picmon | 1:0cb065f9d55a | 185 | void dispBuffer(string s, uint8_t size, char array[]); |
Picmon | 1:0cb065f9d55a | 186 | void dispMotReg(string s, uint8_t regSel, char regArray[9][BUFFER_SIZE]); |
Picmon | 1:0cb065f9d55a | 187 | |
Picmon | 1:0cb065f9d55a | 188 | |
Picmon | 1:0cb065f9d55a | 189 | uint8_t procMotMsg(char *txMsg, char *rxMsg, char motReg[9][BUFFER_SIZE]); |
Picmon | 1:0cb065f9d55a | 190 | void dispRegDec(string s, uint8_t regSel, char regArray[9][BUFFER_SIZE]); |
Picmon | 1:0cb065f9d55a | 191 | void dispRegHex(string s, uint8_t regSel, char regArray[9][BUFFER_SIZE]); |
Picmon | 1:0cb065f9d55a | 192 | |
Picmon | 1:0cb065f9d55a | 193 | |
Picmon | 1:0cb065f9d55a | 194 | void data2mem(uint8_t dataLoc, char destMemArray[][DATA_BUFFER_SIZE], char sourceMemArray[BUFFER_SIZE]);//for command with <CR><VALUE> |
Picmon | 1:0cb065f9d55a | 195 | void Init(void); |
Picmon | 1:0cb065f9d55a | 196 | |
Picmon | 1:0cb065f9d55a | 197 | long mapI(long x, long in_min, long in_max, long out_min, long out_max); |
Picmon | 1:0cb065f9d55a | 198 | float mapF(float in, float inMin, float inMax, float outMin, float outMax); |
Picmon | 1:0cb065f9d55a | 199 | |
Picmon | 0:333434a8611b | 200 | #endif |