Hi,
I am planning to use the CubeMars AK series motors for a robot project. I have the motors and the accompanying R-Link to set up the motors, I have tested the motors with the R-link so I know they work, but now I want to do more control using CAN Bus.
My problem is that when I try to send or receive CAN messages to and from the actuator nothing happens.
I have set up two Arduinos with CAN bus shields to test that the messages are being sent and that they can be received. So I know that the CAN bus is sending the “correct” signal through the CAN bus to the other Arduino since I can read the signal.
From the documentation (page 48 in the manual) it says that to enter the “MIT mode” one needs to send a command and then send the position command, but it is not working for me.
Can someone help me with this?
Motor: AK70-10 V1.1
SparkFun Arduino CAN shield
Arduino CAN-Bus shield: Arduino CAN Bus Shield | MYBOTSHOP.DE, 19,95 €
CubeMars manual: https://store.cubemars.com/images/file/20220225/1645777365858910.pdf
Arduino code
// demo: CAN-BUS Shield, send data
// loovee@seeed.cc
#include <mcp_can.h>
#include <SPI.h>
// #include <CAN.h>
/* core
 *  Test script for motor testing
*/
#ifdef ARDUINO_SAMD_VARIANT_COMPLIANC
    #define SERIAL SerialUSB
#else   
    //#define SERIAL Serial
#endif 
// Define joystick connection pins
#define UP      A1
#define DOWN    A3
#define LEFT    A2
#define RIGHT   A5
#define CLICK   A4
// Define LED pins
#define LED2 8
#define LED3 7
//const int SPI_CS_PIN = 10;
//MCP_CAN CAN(SPI_CS_PIN);
MCP_CAN CAN0(10);     // Set CS to pin 10
void setup()
{ 
    Serial.begin(115200);
   
    //delay(1000);
     /*while (CAN_OK != CAN0.begin(CAN_1000KBPS))
    {
        Serial.println("CAN BUS Shield init fail");
        Serial.println("Iit CAN Bus Shield againg");
        delay(100);
    }*/ 
    // Initialize MCP2515 running at 16MHz with a baudrate of 500kb/s and the masks and filters disabled.
    if(CAN0.begin(MCP_ANY, CAN_500KBPS, MCP_16MHZ) == CAN_OK) Serial.println("MCP2515 Initialized Successfully!");
    else Serial.println("Error Initializing MCP2515...");
    CAN0.setMode(MCP_NORMAL);   // Change to normal mode to allow messages to be transmitted
    Serial.println("CAN BUS enter normal mode");
    // Setup CAN ID
    unsigned char len = 0;
    unsigned char canId = 1;
    Serial.print("Can ID:");
    Serial.println(canId, HEX);
    
    //initialize pins
    pinMode(UP, INPUT);
    pinMode(DOWN, INPUT);
    pinMode(LED2, INPUT);
    pinMode(LED3, INPUT);
    // Pull analoge pins hig to eable reading of joystic movment
    digitalWrite(UP, HIGH);
    digitalWrite(DOWN, HIGH);
        
    // Write LED pins
    digitalWrite(LED2, LOW);
    digitalWrite(LED3, HIGH);
    //Set to MIT mode
    unsigned char MIT[8] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,0XFC};
    CAN0.sendMsgBuf(0x01, 0, 8, MIT);
    Serial.print("MIT mode command sent:");
    Serial.print(MIT[8], HEX); Serial.print(MIT[1], HEX); Serial.print(MIT[2], HEX); Serial.print(MIT[3], HEX);    Serial.print(MIT[4], HEX);      Serial.print(MIT[5], HEX);     Serial.print(MIT[6], HEX);     Serial.print(MIT[7], HEX); 
    
    
}
unsigned char   stmp[8] = {0, 0, 0, 0, 0, 0, 0, 0};
void loop()
{
    long unsigned int rxId;
    unsigned char len = 0;
    unsigned char buf[8];
    unsigned char canId = 0; //CAN0.getCanId();
    //send data
    delay(50);
    
    
    stmp[0] = 0xFF;
    stmp[1] = 0x01;
    stmp[2] = 0x00;
    stmp[3] = 0x24;
    stmp[4] = 0x00;
    stmp[5] = 0x80;
    stmp[6] = 0;
    if (digitalRead(UP) == LOW)
    {
        stmp[7] = stmp[7] + 1;
        Serial.println("Input: UP");
        if (stmp[7] == 255) {
            stmp[7] = 254;
            // stmp[6] = 0;
        }
    }
    if (digitalRead(DOWN) == LOW)
    {
        stmp[7] = stmp[7] - 1;
        Serial.println("Input: DOWN");
        if (stmp[7] == 0) {
            stmp[7] = 1;
            // stmp[6] = 160;
        }
    }
    CAN0.sendMsgBuf(0x01, 0, 8, stmp);
    
    
    if(CAN_MSGAVAIL == CAN0.checkReceive())  // check incoming data
    {
        CAN0.readMsgBuf(&rxId, &len, buf); // read data
        
       // unsigned char canId = 0; //CAN0.getCanId();
        Serial.println("-----------------------");
        Serial.print("get data from ID: 0x");
        Serial.println(canId, HEX);
        for(int i = 0; i<len; i++)  //print the data
        {
            Serial.print(buf[i], HEX);
            Serial.print("\t");
            
        }
        Serial.println();
    }
}