ver CAN
ikarashiMDC.cpp@6:342e3a4f4a8d, 2017-08-29 (annotated)
- Committer:
- WAT34
- Date:
- Tue Aug 29 17:03:29 2017 +0900
- Revision:
- 6:342e3a4f4a8d
- Parent:
- 5:b43c03ee7f8b
- Parent:
- 4:d6f0b74affd7
- Child:
- 8:626daa6d81ac
debuged
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 | 0:314f2bed3958 | 12 | } |
WAT34 | 0:314f2bed3958 | 13 | |
WAT34 | 2:75153205d6e8 | 14 | int ikarashiMDC::setSpeed(const double& speed) |
WAT34 | 0:314f2bed3958 | 15 | { |
WAT34 | 4:d6f0b74affd7 | 16 | uint8_t data[3],dataSpeed; |
WAT34 | 2:75153205d6e8 | 17 | //Limiter |
WAT34 | 2:75153205d6e8 | 18 | const double cropped_speed = -1 < speed ? |
WAT34 | 2:75153205d6e8 | 19 | 1 > speed ? |
WAT34 | 2:75153205d6e8 | 20 | speed:1 |
WAT34 | 2:75153205d6e8 | 21 | :-1; |
WAT34 | 2:75153205d6e8 | 22 | |
WAT34 | 2:75153205d6e8 | 23 | //dataspeed 0~253 neutaral 126 |
WAT34 | 2:75153205d6e8 | 24 | dataSpeed = ((cropped_speed+1.0)/2.0)*253; |
WAT34 | 2:75153205d6e8 | 25 | //printf("%d\n",dataSpeed); |
WAT34 | 2:75153205d6e8 | 26 | //set sending data |
WAT34 | 2:75153205d6e8 | 27 | data[0] = 255; //header |
WAT34 | 2:75153205d6e8 | 28 | data[1] = (addr<<5) + motorNum + (mode<<4); //address |
WAT34 | 2:75153205d6e8 | 29 | data[2] = dataSpeed; |
WAT34 | 2:75153205d6e8 | 30 | //send data |
WAT34 | 4:d6f0b74affd7 | 31 | for(int i=0; i<3; i++) { |
WAT34 | 2:75153205d6e8 | 32 | serial->putc(data[i]); |
WAT34 | 2:75153205d6e8 | 33 | } |
WAT34 | 0:314f2bed3958 | 34 | return 0; |
WAT34 | 0:314f2bed3958 | 35 | } |
WAT34 | 0:314f2bed3958 | 36 | |
WAT34 | 2:75153205d6e8 | 37 | |
WAT34 | 2:75153205d6e8 | 38 | void estop(Serial *serial) |
WAT34 | 1:5e8014a1adbd | 39 | { |
WAT34 | 2:75153205d6e8 | 40 | for(int i = 0; i<3; i++) { |
WAT34 | 2:75153205d6e8 | 41 | serial->putc(255); |
WAT34 | 1:5e8014a1adbd | 42 | } |
WAT34 | 2:75153205d6e8 | 43 | |
WAT34 | 5:b43c03ee7f8b | 44 | } |