ver CAN

Files at this revision

API Documentation at this revision

Comitter:
tknara
Date:
Tue Nov 27 06:19:29 2018 +0000
Parent:
13:ea34af94e90c
Commit message:
RS-485 > comment out; CAN > add

Changed in this revision

ikarashiMDC.cpp Show annotated file Show diff for this revision Revisions of this file
ikarashiMDC.h Show annotated file Show diff for this revision Revisions of this file
--- a/ikarashiMDC.cpp	Sat Nov 11 10:50:30 2017 +0000
+++ b/ikarashiMDC.cpp	Tue Nov 27 06:19:29 2018 +0000
@@ -1,6 +1,6 @@
+#include "mbed.h"
 #include "ikarashiMDC.h"
 
-
 ikarashiMDC::ikarashiMDC(DigitalOut* serialcontrol,uint8_t taddr,uint8_t tmotorNum,bool tmode,Serial *tserial)
 {
     serialControl = serialcontrol;
@@ -11,7 +11,14 @@
     mode = tmode;
     braking = true;
 }
-
+ikarashiMDC::ikarashiMDC(uint8_t taddr,uint8_t tmotorNum,bool tmode,CAN *can)
+{
+    can_driver = can;
+    addr = taddr;
+    motorNum = tmotorNum;
+    mode = tmode;
+    braking = true;
+}
 int ikarashiMDC::setSpeed(const double& speed)
 {
     uint8_t data[4],dataSpeed;
@@ -21,14 +28,17 @@
     dataSpeed = ((cropped_speed+1.0)/2.0)*253;
     //printf("%d\n",dataSpeed);
     //set sending data
-    data[0] = 255; //header
-    data[1] = (addr<<5) + motorNum + (mode<<4)+(braking<<3); //address
-    data[2] = dataSpeed;
-    data[3] = data[1]^data[2];
+    //msg.data[0] = 255; //header
+    msg.data[0] = (addr<<5) + motorNum + (mode<<4)+(braking<<3); //address
+    msg.data[1] = dataSpeed;
+    msg.data[2] = data[1]^data[2];
+    msg.id = 1;
+    msg.len=3;
+    can_driver->write(msg);
     //send data
-    for(int i=0; i<4; i++) {
-        serial->putc(data[i]);
-    }
+    //for(int i=0; i<4; i++) {
+        //serial->putc(data[i]);
+    //}
     return 0;
 }
 
--- a/ikarashiMDC.h	Sat Nov 11 10:50:30 2017 +0000
+++ b/ikarashiMDC.h	Tue Nov 27 06:19:29 2018 +0000
@@ -55,7 +55,7 @@
     * @param  address of serial object
     **/
     ikarashiMDC(DigitalOut* serialcontrol,uint8_t taddr,uint8_t tmotorNum,bool tmode,Serial *tserial);
-    
+    ikarashiMDC(uint8_t taddr,uint8_t tmotorNum,bool tmode,CAN *can);
     /** drive motor
     * @param speed of motor -1 to 1
     **/
@@ -68,7 +68,8 @@
     bool mode;
     Serial* serial;
     DigitalOut *serialControl;
-    
+    CAN* can_driver;
+    CANMessage msg;
 };
 void estop(Serial *serial);