ver CAN
ikarashiMDC.cpp@0:314f2bed3958, 2017-08-07 (annotated)
- Committer:
- WAT34
- Date:
- Mon Aug 07 22:39:44 2017 +0000
- Revision:
- 0:314f2bed3958
- Child:
- 1:5e8014a1adbd
i hope this works
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 | 0:314f2bed3958 | 4 | ikarashiMDC::ikarashiMDC() |
WAT34 | 0:314f2bed3958 | 5 | { |
WAT34 | 0:314f2bed3958 | 6 | serial=NULL; |
WAT34 | 0:314f2bed3958 | 7 | addr = 0; |
WAT34 | 0:314f2bed3958 | 8 | motorNum = 0; |
WAT34 | 0:314f2bed3958 | 9 | } |
WAT34 | 0:314f2bed3958 | 10 | |
WAT34 | 0:314f2bed3958 | 11 | int ikarashiMDC::setMotorinfo(uint8_t _addr,uint8_t _motorNum,Serial *_serial) |
WAT34 | 0:314f2bed3958 | 12 | { |
WAT34 | 0:314f2bed3958 | 13 | serial = _serial; |
WAT34 | 0:314f2bed3958 | 14 | addr = _addr; |
WAT34 | 0:314f2bed3958 | 15 | motorNum = _motorNum; |
WAT34 | 0:314f2bed3958 | 16 | return 0; |
WAT34 | 0:314f2bed3958 | 17 | } |
WAT34 | 0:314f2bed3958 | 18 | |
WAT34 | 0:314f2bed3958 | 19 | int ikarashiMDC::setMotorSpeed(double speed) |
WAT34 | 0:314f2bed3958 | 20 | { |
WAT34 | 0:314f2bed3958 | 21 | uint8_t data[3],dataSpeed; |
WAT34 | 0:314f2bed3958 | 22 | //Limiter |
WAT34 | 0:314f2bed3958 | 23 | if(speed > 1.0) speed = 1.0; |
WAT34 | 0:314f2bed3958 | 24 | if(speed < -1.0) speed = -1.0; |
WAT34 | 0:314f2bed3958 | 25 | |
WAT34 | 0:314f2bed3958 | 26 | //dataspeed 0~253 neutaral 126 |
WAT34 | 0:314f2bed3958 | 27 | dataSpeed = ((speed+1.0)/2.0)*253; |
WAT34 | 0:314f2bed3958 | 28 | //set sending data |
WAT34 | 0:314f2bed3958 | 29 | data[0] = 255; //header |
WAT34 | 0:314f2bed3958 | 30 | data[1] = addr; //address |
WAT34 | 0:314f2bed3958 | 31 | data[2] = dataSpeed; |
WAT34 | 0:314f2bed3958 | 32 | |
WAT34 | 0:314f2bed3958 | 33 | //send data |
WAT34 | 0:314f2bed3958 | 34 | for(int i=0;i<3; i++) |
WAT34 | 0:314f2bed3958 | 35 | { |
WAT34 | 0:314f2bed3958 | 36 | serial->putc(data[i]); |
WAT34 | 0:314f2bed3958 | 37 | } |
WAT34 | 0:314f2bed3958 | 38 | return 0; |
WAT34 | 0:314f2bed3958 | 39 | } |