Hello all!
I have been busy last weeks creating a mechanism with lots of gears, levers, cam-followers etc… Almost everything has been 3d printed and the idea is to actuate the mechanism with just one motor, which is installed on the side. I am using the following:
- Odrive v3.6
- Arduino UNO
- Mean Well LRS 350 48 Power Supply 350 W
- Dual Shaft Motor - D5065 270kv
- CUIAMT102 encoder
FYI, I am a total beginner when it comes to programming Arduino and in general electronics. I am more a mechanical guy…
I would like to just try and let the motor rotate a couple of times. Everything seems well connected and working. However during calibration the motor does only rotate a little bit and then reverses. Seems like there isn’t enough torque.
here is also a little video: https://youtu.be/trgmmyzzNlI
I am trying the following modified example code (I changed a couple of things and included the calibration_current to try and enhance the torque during calibration):
#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)
// Note: you must also connect GND on ODrive to GND on Arduino!
// ODrive object
ODriveArduino odrive(odrive_serial);
void setup() {
// ODrive uses 115200 baud
odrive_serial.begin(115200);
// Serial to PC
Serial.begin(115200);
while (!Serial) ; // wait for Arduino Serial Monitor to open
Serial.println("ODriveArduino");
Serial.println("Setting parameters...");
// Setting motor parameters
odrive_serial << "w axis0.controller.config.vel_limit " << 22000.0f << '\n';
odrive_serial << "w axis0.controller.config.current_lim " << 30.0f << '\n';
odrive_serial << "w axis0.controller.config.calibration_current " << 30.0f << '\n'; //to increase torque during calibration?
Serial.println("Ready!");
Serial.println("Send the character '0' to calibrate the motor (you must do this before you can command movement)");
Serial.println("Send the character 'r' to rotate motor");
Serial.println("Send the character 'b' to read bus voltage");
Serial.println("Send the character 'p' to read motor positions in a 10s loop");
}
void loop() {
if (Serial.available()) {
char c = Serial.read();
// Run calibration sequence
if (c == '0' || c == '1') {
int motornum = c-'0';
int requested_state;
requested_state = ODriveArduino::AXIS_STATE_MOTOR_CALIBRATION;
Serial << "Axis" << c << ": Requesting state " << requested_state << '\n';
odrive.run_state(motornum, requested_state, true);
requested_state = ODriveArduino::AXIS_STATE_ENCODER_OFFSET_CALIBRATION;
Serial << "Axis" << c << ": Requesting state " << requested_state << '\n';
odrive.run_state(motornum, requested_state, true);
requested_state = ODriveArduino::AXIS_STATE_CLOSED_LOOP_CONTROL;
Serial << "Axis" << c << ": Requesting state " << requested_state << '\n';
odrive.run_state(motornum, requested_state, false); // don't wait
}
// velocity test move
if (c == 'r') {
Serial.println("rotate motor");
odrive.SetVelocity(0, 10000, 30);
}
// stop rotating
if (c == 'q') {
Serial.println("Stopping motor");
odrive.SetVelocity(0, 0, 10);
}
// Read bus voltage
if (c == 'b') {
odrive_serial << "r vbus_voltage\n";
Serial << "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";
Serial << odrive.readFloat() << '\t';
}
Serial << '\n';
}
}
}
}
FYI I don’t know exactly which torque is required at the moment, but I can operate the mechanism by hand and in my opinion the torque does not seem too high, I think the motor should be able to do this…
I anyone has any tips or help on how to let me rotate the motor with a higher torque? Or for me to do /try anything else?
thank you!
Sven