ver CAN
ikarashiMDC.cpp@13:ea34af94e90c, 2017-11-11 (annotated)
- Committer:
- WAT34
- Date:
- Sat Nov 11 10:50:30 2017 +0000
- Revision:
- 13:ea34af94e90c
- Parent:
- 12:3fa4f849d6f7
- Child:
- 14:b1b58b74dd4c
bugs fixed;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
WAT34 | 0:314f2bed3958 | 1 | #include "ikarashiMDC.h" |
WAT34 | 0:314f2bed3958 | 2 | |
WAT34 | 0:314f2bed3958 | 3 | |
WAT34 | 2:75153205d6e8 | 4 | ikarashiMDC::ikarashiMDC(DigitalOut* serialcontrol,uint8_t taddr,uint8_t tmotorNum,bool tmode,Serial *tserial) |
WAT34 | 0:314f2bed3958 | 5 | { |
WAT34 | 2:75153205d6e8 | 6 | serialControl = serialcontrol; |
WAT34 | 1:5e8014a1adbd | 7 | serialControl->write(true); |
WAT34 | 2:75153205d6e8 | 8 | serial = tserial; |
WAT34 | 2:75153205d6e8 | 9 | addr = taddr; |
WAT34 | 2:75153205d6e8 | 10 | motorNum = tmotorNum; |
WAT34 | 2:75153205d6e8 | 11 | mode = tmode; |
WAT34 | 9:12ea2a3883bb | 12 | braking = true; |
WAT34 | 0:314f2bed3958 | 13 | } |
WAT34 | 0:314f2bed3958 | 14 | |
WAT34 | 2:75153205d6e8 | 15 | int ikarashiMDC::setSpeed(const double& speed) |
WAT34 | 0:314f2bed3958 | 16 | { |
Wataru Nakata |
12:3fa4f849d6f7 | 17 | uint8_t data[4],dataSpeed; |
WAT34 | 2:75153205d6e8 | 18 | //Limiter |
WAT34 | 13:ea34af94e90c | 19 | const double cropped_speed = std::min(1.0,std::max(-1.0,speed)); |
WAT34 | 2:75153205d6e8 | 20 | //dataspeed 0~253 neutaral 126 |
WAT34 | 2:75153205d6e8 | 21 | dataSpeed = ((cropped_speed+1.0)/2.0)*253; |
WAT34 | 2:75153205d6e8 | 22 | //printf("%d\n",dataSpeed); |
WAT34 | 2:75153205d6e8 | 23 | //set sending data |
WAT34 | 2:75153205d6e8 | 24 | data[0] = 255; //header |
WAT34 | 7:a8fcb8df927a | 25 | data[1] = (addr<<5) + motorNum + (mode<<4)+(braking<<3); //address |
WAT34 | 2:75153205d6e8 | 26 | data[2] = dataSpeed; |
Wataru Nakata |
12:3fa4f849d6f7 | 27 | data[3] = data[1]^data[2]; |
WAT34 | 2:75153205d6e8 | 28 | //send data |
Wataru Nakata |
12:3fa4f849d6f7 | 29 | for(int i=0; i<4; i++) { |
WAT34 | 2:75153205d6e8 | 30 | serial->putc(data[i]); |
WAT34 | 2:75153205d6e8 | 31 | } |
WAT34 | 0:314f2bed3958 | 32 | return 0; |
WAT34 | 0:314f2bed3958 | 33 | } |
WAT34 | 0:314f2bed3958 | 34 | |
WAT34 | 2:75153205d6e8 | 35 | |
WAT34 | 2:75153205d6e8 | 36 | void estop(Serial *serial) |
WAT34 | 1:5e8014a1adbd | 37 | { |
WAT34 | 2:75153205d6e8 | 38 | for(int i = 0; i<3; i++) { |
WAT34 | 2:75153205d6e8 | 39 | serial->putc(255); |
WAT34 | 1:5e8014a1adbd | 40 | } |
WAT34 | 2:75153205d6e8 | 41 | |
WAT34 | 5:b43c03ee7f8b | 42 | } |