merose/diff_drive

lwheel_rate and rwheel_rate for odometry

Closed this issue · 5 comments

how to calculate the lwheel_rate and rwheel_rate for odometry?

hi
request support for a 4- wheeled robot odometry please, it would be a great help. thanks a lot

Sorry to leave this open for so long. diff_drive does not do the PID control needed to control actual motors. You have to supply that part or use another node along with diff_drive. In the code that does PID control you normally calculate the wheel rates by periodically looking at the encoder counts for each wheel, subtracting the last encoder counts seen, to get a delta, then divide by the time between samplings. Something like this pseudocode, which only illustrates what you'd do for one wheel.

last_left_ticks = left_encoder_ticks
last_time = time.time()
while True:
    ... delay for a short time ...
    new_left_ticks = left_encoder_ticks
    new_time = time.time()
    if new_time > last_time:
        left_rate = (new_left_ticks - last_left_ticks) / (new_time - last_time)
        ... adjust motor speed based on current rate and desired rate ...
        ... will also need error first derivative and integral if using I or D part of PID ...
    last_left_ticks = new_left_ticks
    last_time = new_time

Regarding 4-wheel robots, both that and Ackerman drive would be useful, but for both you can use differential-drive approximations. For a 4-wheel skid-steer, for example, take the mean of the left and right pairs of encoders. (Or, maybe, take the minimum delta of each pair, since a larger value probably implies slippage. But I'm not a hardware expert, so that might not be true.)

In any case, I don't plan to expand diff_drive to support other steering mechanisms at this time.

Closing since there is no code change required.