Hey guys!
I know this isn’t much, but I thought it was kind of cool. I am using a CMU Pixy camera for object tracking connected through Arduino and then connected to the Odrive using UART. It works as expected but if anyone has any ideas how to reduce the latency that would be awesome! The Arduino code is below:
#include <SoftwareSerial.h>
#include <ODriveArduino.h>
#include <SPI.h>
#include <Pixy.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
ODriveArduino odrive(odrive_serial);
int test = 10;
int ledPin = 5;
int buttonApin = 2;
int buttonBpin = 3;
byte leds = 0;
Pixy pixy;
void setup() {
pixy.init();
{
pinMode(ledPin, OUTPUT);
pinMode(buttonApin, INPUT_PULLUP);
pinMode(buttonBpin, INPUT_PULLUP);
}
// 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 alpha.");
Serial.println("Setting parameters...");
// In this example we set the same parameters to both motors.
// You can of course set them different if you want.
for (int motor = 0; motor < 2; ++motor) {
odrive.SetParameter(motor, odrive.PARAM_FLOAT_CURRENT_CONTROL_CURRENT_LIM, 10.0f); // [A]
odrive.SetParameter(motor, odrive.PARAM_FLOAT_VEL_LIMIT, 15000.0f); // [counts/s]
odrive.SetParameter(motor, odrive.PARAM_FLOAT_POS_GAIN, 20.0f); // [(counts/s) / counts]
odrive.SetParameter(motor, odrive.PARAM_FLOAT_VEL_GAIN, 20.0f/10000.0f); // [A/(counts/s)]
odrive.SetParameter(motor, odrive.PARAM_FLOAT_VEL_INTEGRATOR_GAIN, 0.0f/10000.0f); // [A/(counts/s * s)]
}
Serial.println("Ready!");
Serial.println("Send the character 's' to exectue test move");
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() {
static int i = 0;
int j;
uint16_t blocks;
char buf[32];
blocks = pixy.getBlocks();
{
if (digitalRead(buttonApin) == HIGH)
{
float pos_m0= (0,pixy.blocks[0].y*-2+1370) ;
odrive.SetPosition(0,pos_m0);
}
if (digitalRead(buttonBpin) == LOW)
{
float pos_m0= (0,1000) ;
odrive.SetPosition(0,pos_m0);
}
}
}