How to interface CAN Bus with Smart Actuator

Hi I’m new to Mbed
Is there anyone have ever interface a smart actuator(RMD-X8) with CAN bus.
Right now I know protocol of the actuator but I don’t know how to start coding to drive this actuator and there is no tutorial too.
I’m using NUCLEO F446RE
Thank you.

Hi there,

if you are newbie, it is good to start with Mbed’s documentation - Mbed OS quick start.
I saw a video about that part and it looks like a nice toy but a little expensive for me.

For the start you need next to your board:

I tried to write only a simple program, which ask about a current PID setting of servo, it wait for response and then it end. Keep it mind it is only experimental code according to documents above, I not have this hardware.

#include "mbed.h"

#define DEVICE_CAN_ID 141 //identifier: 0x140+ID(1-32)

DigitalOut led1(LED1);
CAN can(PB_8,PB_9,1000000); //I am not sure with with frequency but  in the video 1000kbps is used
char data[] = {0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; //read PID param. cmd

int main()
{
    printf("CanTest\n");
    ThisThread::sleep_for(500ms);
    if (can.write(CANMessage(DEVICE_CAN_ID, data))) { 
        CANMessage msg;
        while (1) {
            if (can.read(msg)) {
                // Printing what was read
                printf("Message received:[ ID: %9x", msg.id);
                printf(" Length: %d", msg.len);
                printf(" Command: %2x", msg.data[0]);
                //printf(" %2x", msg.data[1]); // Null
                printf("Position loop Kp %2x", msg.data[2]);
                printf("Position loop Ki %2x", msg.data[3]);
                printf("Speed loop Kp %2x", msg.data[4]);
                printf("Speed loop Ki %2x", msg.data[5]);
                printf("Torque loop Kp %2x", msg.data[6]);
                printf("Torque loop Ki %2x", msg.data[7]);
                printf("CanBus Type: %d", msg.type);           // 0 = data, 1 = remote
                printf("Format: %d ]\r\n", msg.format);        // 0 = standard, 1 = extended
                ThisThread::sleep_for(500ms);
                break;
            }
            ThisThread::sleep_for(100ms);
            led1 = !led1;
        }
    }else{
        printf("Write error\n");
    }
    printf("Rrogram end!\n");
}

BR, Jan

1 Like

Thank you so much.