9 years, 9 months ago.

Using Mbed with Elmo Motor Controllers

I think the mbed CAN coding example listed here was useless. I previously had no understanding of CAN before viewing this page and all I learned from reading the example was to initialize the CAN pins 29 & 30 and send a message over CAN using can.write(CANMessage).

I needed to learn about CAN arguments and this page doesn't even explain the CANMessage arguments used in the example. For example what the heck do the arguments for this CANMessage found on line mean?

CANMessage(1337, &counter, 1)

I know they are the ID, data, and length but I don't understand what they do in this example or why they were chosen?

Anyway, on behalf of my frustration with this example I would like to start a thread on a robotics project I am working on using ELMO motor controllers in a CAN.

I found the following sites most useful during my research about creating messages for ELMO motor controllers using CAN:

http://robotsforroboticists.com/can-bus/ http://www.elmomc.com/support/manuals/MAN-SIMCR.pdf http://www.elmomc.com/support/manuals/MAN-CAN301IG.pdf

I am still not really sure of what needs to be done in which order to make the motors start, but I think I may have a better understanding of how to format the CANMessage. Here is the code I have written so far. If anyone can read please let me know if I have done something wrong?

Briefly before the code I also want to actually explain why I chose the CANMessage arguments that I did.

Firstly I defined "int const ca = 0x300 (01100000000 in binary)" to be the permanent recipient device id of my messages. This is based on a 11 bit ID which I read about on the first link above. The first four bits (0110) are the communication object (COB) ID for PDO2 which is mentioned near the end of that webpage to be the default address for the binary interpreter which is useful for interpreting CAN messages for ELMO motor controllers. The last 7 bits are the device number from 0-127. I read on that webpage that the ID 0 (0000000 in binary) will transmit your CAN message to all recipients. Hence the combined 11 bit ID converted to hex is 0x300.

Secondly the 4 char arrays AC, BG, DM, and UM I defined at the start of main() are based on a 2 byte command ID that the EMLO motor controllers recognize as part of a library (read the second wepage link to see more about them), a 2 byte reference for arrays with multiple elements (unused in my code so always 0x0), and a 4 byte data entry (these are arguments like the acceleration value of the motors which I want to be 150000 (0x0249F0 converted to hex) in the case of the AC array). The idea is that the library will recognize the 2 byte commands and do something with that command according to the 4 byte data that came with it.

Finally, I made the third CANMessage argument (char length) equal to either 4 or 8 depending on the length in bytes of the data being sent and I also used CANData because I want to send data to the motor controllers and I used CANStandard because I want to send a standard CAN message with and 11 bit ID.

From there I just plug arguments into the CANMessages in my code using variables.

  1. include "mbed.h"

CAN can(p30, p29); int const ca = 0x300; CANType const cd = CANData; CANFormat const cs = CANStandard;

int main() { char AC[8] = {0x41,0x43,0x0,0x0,0xF0,0x49,0x02,0x0}; (byte 1&2 -> AC, byte 3&4 -> 0, byte 5-8 ->150000) char BG[4] = {0x42,0x47,0x0,0x0}; (byte 1&2 -> BG, byte 3&4 -> 0) char RM[8] = {0x52,0x4d,0x0,0x0,0x30,0x0,0x0,0x0}; (byte 1&2 -> RM, byte 3&4 -> 0, byte 5-8 -> 0) char UM[8] = {0x55,0x4d,0x0,0x0,0x32,0x0,0x0,0x0}; (byte 1&2 -> UM, byte 3&4 -> 0, byte 5-8 -> 2)

can.write(CANMessage(ca,RM,8,cd,cs)); wait(1000); can.write(CANMessage(ca,UM,8,cd,cs)); wait(1000); can.write(CANMessage(ca,AC,8,cd,cs)); wait(1000); can.write(CANMessage(ca,BG,4,cd,cs)); wait(1000); }

Question relating to:

.

posted by kyle johnson 28 Jul 2014
Be the first to answer this question.