Motors still have velocity, but buffers are set to 128

Questions about using encoders with the Roboclaw product line
Post Reply
hopkira
Posts: 1
Joined: Sat Mar 17, 2018 11:26 am

Motors still have velocity, but buffers are set to 128

Post by hopkira » Sun Jan 26, 2020 2:36 am

Hi, I'm trying to control the distance my robot travels by issuing a non-buffered command for acceleration, followed by a buffered one for deceleration. I want to detect when the robot finishes those two movements. The PID controller has been autotuned. I am using the latest Basicmicro program and firmware. These are the two commands:

rc.SpeedAccelDistanceM1M2(address=rc_address,
accel=accel,
speed1=int(round(click_vel)),
distance1=int(abs(clicks/2)),
speed2=int(round(click_vel)),
distance2=int(abs(clicks/2)),
buffer=1)
rc.SpeedAccelDistanceM1M2(address=rc_address,
accel=accel,
speed1=0,
distance1=int(abs(clicks/2)),
speed2=0,
distance2=int(abs(clicks/2)),
buffer=0)

When allowed to complete, they correctly move the robot the right distance, but the when I read the buffers using this command:

buffers = rc.ReadBuffers(rc_address)

and test buffer[1] and buffer[2] for the value 128, it is clear that buffers[1] and buffers[2] are set to 128 well before the wheels stop moving (we're talking not long after the deceleration command is issued). Eyeballing the print statements, suggests the buffer jumps almost immediately from 1 to 128, bypassing 0.

What am I doing wrong? My current solution is to combine reading the buffer state with the encoder speeds - when both buffers are 128 and both motors have zero velocity, then the movement is complete - however I'm not sure how reliable that is and my understanding from this forum and the manual is that ReadBuffers should be sufficient and accurate. Before I start building in autonomic control, I'd like to ensure I understand whether I've done anything wrong.

User avatar
Basicmicro Support
Posts: 1323
Joined: Thu Feb 26, 2015 9:45 pm

Re: Motors still have velocity, but buffers are set to 128

Post by Basicmicro Support » Tue Jan 28, 2020 10:36 am

Your last distance command should leave the distance values set to 0. When target speed is 0 the command will automatically decelerate to 0 speed no matter what the distance is. It is possible/probable that if you set a distance shorter than that needed to stop under the given decel rate(but not 0 distance) that it will actual end the command at that distance. In that case the motors would still be moving and Roboclaw would add an additional command to stop the motors. That command would calculate a decel rate that would stop the motors in 1 second with whatever the leftover speed is. From the point that added command was added the ReadBuffers would return 128.

Take a look at this post. It explains how to handle point to point moves with speed/distance commands: viewtopic.php?f=2&t=46&p=158&hilit=calculating#p158

After reading through that and changing your distance commands accordingly let me know the results.

Post Reply