ver CAN

Committer:
WAT34
Date:
Mon Aug 28 12:56:38 2017 +0000
Revision:
4:d6f0b74affd7
Parent:
2:75153205d6e8
Child:
6:342e3a4f4a8d
????

Who changed what in which revision?

UserRevisionLine numberNew 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 4:d6f0b74affd7 17 double cropped_speed;
WAT34 2:75153205d6e8 18 //Limiter
WAT34 4:d6f0b74affd7 19 if(speed > 1.0)
WAT34 4:d6f0b74affd7 20 cropped_speed = 1.0;
WAT34 4:d6f0b74affd7 21 if(speed < -1.0)
WAT34 4:d6f0b74affd7 22 cropped_speed = -1.0;
WAT34 4:d6f0b74affd7 23 cropped_speed =speed;
WAT34 2:75153205d6e8 24 //dataspeed 0~253 neutaral 126
WAT34 2:75153205d6e8 25 dataSpeed = ((cropped_speed+1.0)/2.0)*253;
WAT34 4:d6f0b74affd7 26 printf("%d\n",dataSpeed);
WAT34 2:75153205d6e8 27 //set sending data
WAT34 2:75153205d6e8 28 data[0] = 255; //header
WAT34 2:75153205d6e8 29 data[1] = (addr<<5) + motorNum + (mode<<4); //address
WAT34 2:75153205d6e8 30 data[2] = dataSpeed;
WAT34 2:75153205d6e8 31 //send data
WAT34 4:d6f0b74affd7 32 for(int i=0; i<3; i++) {
WAT34 2:75153205d6e8 33 serial->putc(data[i]);
WAT34 2:75153205d6e8 34 }
WAT34 0:314f2bed3958 35 return 0;
WAT34 0:314f2bed3958 36 }
WAT34 0:314f2bed3958 37
WAT34 2:75153205d6e8 38
WAT34 2:75153205d6e8 39 void estop(Serial *serial)
WAT34 1:5e8014a1adbd 40 {
WAT34 2:75153205d6e8 41 for(int i = 0; i<3; i++) {
WAT34 2:75153205d6e8 42 serial->putc(255);
WAT34 1:5e8014a1adbd 43 }
WAT34 2:75153205d6e8 44
WAT34 1:5e8014a1adbd 45 }