Industruino Serial com with Odrive

Hello everyone,

I have been experimenting with the Industruino board for my development as it can handle industrial digital and analog I/Os (24v and 0-10v). Also the added robustness of the design is great for industrial use.

Basically I am using the industruino to receive some analog output 0-10v from an industrial kuka robot. this analog ouput will then be used to control the speed of a brushless motor using Odrive. As the industruino is based on arduino it should communicate well with the odrive using the odrivearduino library.

The issue I encounter is that the SoftwareSerial library is not supported by the Industruino (same MCU as Arduino M0). I did some digging on the industruino side and how to use serial communication. The board has built in hardware serial RX and TX pins than can be used directly (D5 and D10 according to https://static.industruino.com/downloads/diagrams/Industruino_INDIO_D21G_pinout_map_April’17_S.pdf).

My knowledge is limited in arduino library but if we could modify the OdriveArduino library to initialize the serial communication without using SoftwareSerial that should work. Someone did something similar for initializing serial using industruino with BoltIOT https://industruino.com/forum/help-1/question/softwareserial-compile-file-not-found-error-workaround-with-d21g-want-to-connect-to-boltiot-device-704 ).

If anyone has any suggestions on modifications to not use SoftwareSerial that would be great ! Thanks !

You can use a hardware Serial instead of SoftwareSerial. At the top of ODriveArduinoTest make odrive_serial be a Serial object instead of a SoftwareSerial object. Just make sure you know which TX and RX pins you need to use.

Thanks Oscar with your help and the industruino team’s I finally managed to get those 2 communicating.
Yep just had to use the hardware serial with Serial1 from the industruino that is linked to pin D10 (RX1) and D05 (TX1), for those who are looking to do the same.

Cheers,

1 Like

Hello again,

I have been trying to use the 2 serials available in the industruino to control 2 different Odrives.

First of all when I use the Serial1 (pin D10/D5), full calibration works but something funny happens : after the beep the motor spins in one direction slowly, then starts to turn slowly in the other direction and after turning 45° or so it accelerates quickly to finish the calibration. There is no error or anything but this does not happen when I calibrate with Odrive tool (constant slow speed throughout the whole full calibration). Is there any explanation for that behaviour ? (video here ).

Secondly when I try to use the other Serial (pin D0/D1), when I do the calibration, it does the whole calibration at low speed but after finishing it takes 1min37s to execute the AXIS_STATE_CLOSED_LOOP_CONTROL (did several tests and that delay is consistant).

I have no idea why I have so many different behaviours between Odrivetool (where everything works fine), using the industruino Serial1 that works fine except the quick spin and the industruino Serial that has this delay in response.
I have checked the grounds and both Serials on the Industruino are connected to the same GND pin which I have connected to the Odrive.

If anyone has a clue I would appreciate it.
Here is the code I use, the only thing changing between using Serial and Serial1 on the industruino is changing the #define odrive_serial :

   //#include <SoftwareSerial.h>
#include <ODriveArduino.h>

// Printing with stream operator
template<class T> inline Print& operator <<(Print &obj,     T arg) { obj.print(arg);    return obj; }
template<>        inline Print& operator <<(Print &obj, float arg) { obj.print(arg, 4); return obj; }

// Serial to the ODrive
//SoftwareSerial odrive_serial(8, 9); //RX (ODrive TX), TX (ODrive RX)

// ODrive object
#define odrive_serial Serial
ODriveArduino odrive(odrive_serial);

void setup() {
  // ODrive uses 115200 baud
  odrive_serial.begin(115200);

  // Serial to PC
  SerialUSB.begin(115200);
  while (!SerialUSB) ; // wait for Arduino Serial Monitor to open

  SerialUSB.println("ODriveArduino");
  SerialUSB.println("Setting parameters...");

  // In this example we set the same parameters to both motors.
  // You can of course set them different if you want.
  // See the documentation or play around in odrivetool to see the available parameters
  for (int axis = 0; axis < 2; ++axis) {
    odrive_serial << "w axis" << axis << ".controller.config.vel_limit " << 40000.0f << '\n';
    odrive_serial << "w axis" << axis << ".motor.config.current_lim " << 10.0f << '\n';
    // This ends up writing something like "w axis0.motor.config.current_lim 10.0\n"
  }

  SerialUSB.println("Ready!");
  SerialUSB.println("Send the character '0' or '1' to calibrate respective motor (you must do this before you can command movement)");
  SerialUSB.println("Send the character 's' to exectue test move");
  SerialUSB.println("Send the character 'b' to read bus voltage");
  SerialUSB.println("Send the character 'p' to read motor positions in a 10s loop");
}

void loop() {

  if (SerialUSB.available()) {
    char c = SerialUSB.read();

    // Run calibration sequence
    if (c == '0' || c == '1') {
      int motornum = c-'0';
      int requested_state;

      requested_state = ODriveArduino::AXIS_STATE_FULL_CALIBRATION_SEQUENCE;
      SerialUSB << "Axis" << c << ": Requesting state " << requested_state << '\n';
      odrive.run_state(motornum, requested_state, true);

      requested_state = ODriveArduino::AXIS_STATE_CLOSED_LOOP_CONTROL;
      SerialUSB << "Axis" << c << ": Requesting state " << requested_state << '\n';
      odrive.run_state(motornum, requested_state, false); // don't wait
    }

    // Sinusoidal test move
     if (c == 's') {
      SerialUSB.println("Executing test move");
        float pos_m0 = 2000.0f;
        float pos_m1 = -2000.0f;
        float pos_m2 = 0.0f;
        odrive.SetPosition(0, pos_m0);
        delay(1000);
        odrive.SetPosition(0, pos_m1);
        delay(1000);
        odrive.SetPosition(0, pos_m2);
        delay(1000);
      
    }

    // Read bus voltage
    if (c == 'b') {
      odrive_serial << "r vbus_voltage\n";
      SerialUSB << "Vbus voltage: " << odrive.readFloat() << '\n';
    }

    // print motor positions in a 10s loop
    if (c == 'p') {
      static const unsigned long duration = 10000;
      unsigned long start = millis();
      while(millis() - start < duration) {
        for (int motor = 0; motor < 2; ++motor) {
          odrive_serial << "r axis" << motor << ".encoder.pos_estimate\n";
          SerialUSB << odrive.readFloat() << '\t';
        }
        SerialUSB << '\n';
      }
    }
  }
}

So when you have just one ODrive connected to Serial1, does it work ok?

I’m not sure if it’s the case on the Industruino, but Serial (D0/D1) on the original ODrives Arduinos is connected to the USB transceiver pins so it’s not a good idea to use them for external comms.

If you’re going to control more than one ODrive from the same Arduino, I encourage you to consider switching to CAN instead of UART.

Hi Wetmelon,

Yes with one Odrive connected to Serial1 it works ok.
The Serial (D0/D1) is primarily connected to a RS485 output which can be uncoupled by a switch to be able to use D0/D1 on the 14pin IDC instead (pin map ) .
So I believe your remark makes sense.
I saw a few posts on the forum about the CAN interface, do you have a link from which I could start to get that interface working ?

Thanks !

I just realized I said ODrives and not Arduinos above (see the edit/strikethrough for correction)

As for CAN, sure! This is the primary thread: CAN Interface Available for Testing

You’ll have to clone and build the repository yourself, unfortunately. I don’t have a binary handy