Hi all,
I am trying to make UART communication faster for high update counts by modifying the ASCII protocol file to accept one character for an instruction. I am using a Teensy 3.2 with HW serial. And using ODive v3.5
Say I want read the encoder position of axis 0.
Using the Arduino library provided, we use the commnd:
if (Serial.available()) {
char c = Serial.read();
if (c == 's') {
odrive_serial << "r axis0.encoder.pos_estimate\n";
odriveResponse();
}
This of course works, and it gives me the value I am looking for. The problem for me however, is that this command took 2.5ms to be sent.
A work around to this problem is to modify the ASCII file and add the following code:
if (cmd[0] == 's') { // status; position, velocity, current
unsigned motor_number;
int numscan = sscanf(cmd, "s %u", &motor_number);
if (numscan < 1) {
respond(response_channel, use_checksum, "invalid command format");
} else if (motor_number >= AXIS_COUNT) {
respond(response_channel, use_checksum, "invalid motor %u", motor_number);
} else {
respond(response_channel, use_checksum, "%f",
(double)axes[motor_number]->encoder_.pos_estimate_);
}
Now using the Teensy, I can send the following:
if (Serial.available()) {
char c = Serial.read();
if (c == 's') {
odrive_serial << "s 0\n";
odriveResponse();
}
This results in the command being sent in 370us, so about 7 times faster!!
Now that this works. I need help getting other reading and writing commands to work using the above mentioned method.
I need to be able to WRITE commands for:
1- axis0.requested_state = value
2- axis0.trap_traj.config.vel_limit = value
3- axis0.controller.input_pos = value (RazorsEdge firmware)
4- axis0.error = 0
I need to be able to READ the following values:
1- axis0.requested_state (I need to know what state the axis is in)
2- axis0.trap_traj.config.vel_limit
3- axis0.motor.config.current_lim
4- axis0.controller.trajectory_done (need to know if motion has ended (boolean))
5- axis.0.motor.is_calibrated (boolean)
6- axis0.error
I wanna thank @mike for helping me with the above code.
Thanks in advance to all that help.
Jamil