![](/media/cache/group/11700697_10200701668420946_8214886085951071495_o.jpg.50x50_q85.jpg)
โปรแกรมของบอร์ด Motion
Dependencies: BEAR_Reciever Motor eeprom iSerial mbed
Fork of DogPID by
Diff: main.cpp
- Revision:
- 11:3dd92d1d542c
- Parent:
- 10:3b3d6bc88677
- Child:
- 12:6b3b997dd7c2
--- a/main.cpp Sat Jan 16 12:06:59 2016 +0000 +++ b/main.cpp Thu Jan 21 14:49:40 2016 +0000 @@ -20,11 +20,13 @@ //*****************************************************/ // Global // +Ticker Recieve; //-- Communication -- Serial PC(D1,D0); -ANDANTE_PROTOCOL_PACKET command; Bear_Receiver com(Tx,Rx,115200); -#define MY_ID 0x01 +int8_t MY_ID = 0x01; +//-- Memorry -- +EEPROM memory(PB_4,PA_8,0); //-- encoder -- int Upper_Position; int Lower_Position; @@ -134,7 +136,7 @@ } //******************************************************/ -void CmdCheck(uint8_t *cmd) +void CmdCheck(uint8_t *cmd,uint8_t ins) { switch(cmd[0]) { case SET_MOTOR_UPPER_ANG : { @@ -182,15 +184,38 @@ } } } - - +/******************************************************/ +void Start_Up ()// load parameter from eeprom before start +{ + // wait for reciever + memory.read(0x00,MY_ID); + memory.read(0x04,Upper_SetPoint); + memory.read(0x08,Lower_SetPoint); + memory.read(0x10,U_Kc); + memory.read(0x14,U_Ti); + memory.read(0x18,U_Td); + memory.read(0x1c,L_Kc); + memory.read(0x20,L_Ti); + memory.read(0x24,L_Td); + +} +/*******************************************************/ +void Rc () +{ + uint8_t data_array[10]; + int8_t ins; + + com.ReceiveCommand(MY_ID,data_array); + CmdCheck(data_array,ins); +} +/*******************************************************/ int main() { - uint8_t id; - uint8_t data_array[10]; + Recieve.attach(&Rc,0.2); + Start_Up(); SET_UpperPID(); SET_LowerPID(); - /* + while(1) { //Set Set_point Up_PID.setSetPoint(Upper_SetPoint); @@ -200,9 +225,9 @@ Move_Upper(); Move_Lower(); } - */ + - com.ReceiveCommand(id,data_array); + //com.ReceiveCommand(id,data_array); }