ev3dev / ev3dev-lang-python

Pure python bindings for ev3dev
MIT License
425 stars 144 forks source link

MoveDifferential.on_to_coordinates in reverse doesn't work #720

Open kpu979 opened 4 years ago

kpu979 commented 4 years ago

There may be times when driving backwards to a coordinate is appropriate.

(our tank's wheels are mounted backwards to save space, hence the 'inversed' polarity)

This code drives the tank in a square (almost perfectly...almost). It starts north, then east, south and west. It then turns 90deg to end up in the same position it started.... almost.

class MCTire(Wheel): def init(self): Wheel.init(self, 100.3, 17)

mdiff = MoveDifferential(OUTPUT_C, OUTPUT_B, MCTire, 129.3)
mdiff.set_polarity('inversed')
mdiff.odometry_start()
side=200
speed=30
mdiff.on_to_coordinates(SpeedRPM(speed), 0, side,brake='false')
mdiff.on_to_coordinates(SpeedRPM(speed), side, side,brake='false')
mdiff.on_to_coordinates(SpeedRPM(speed), side, 0,brake='false')
mdiff.on_to_coordinates(SpeedRPM(speed), 0, 0,brake='false')
mdiff.turn_right(SpeedRPM(speed), 90)

mdiff.odometry_stop()

HOWEVER, when I change the speed=-30, I would expect the robot to traverse the same path, only backwards, but instead, it took a much different path. It rolls to (0,-200), then makes a ~30deg turn rolls to about (100,-300), then to about (150,-350) etc. (this is the point where it hits a wall, or closet , or sleeping dog)

I hope this explains the issue, but if not, let me know. Perhaps a video would work?

ev3dev version: 4.14.117-ev3dev-2.3.4-ev3 ev3dev-lang-python version: +++-====================================-=======================-=======================-============================================================================== ii micropython-ev3dev2 2.0.0 all Python language bindings for ev3dev for MicroPython ii python3-ev3dev 1.2.0 all Python language bindings for ev3dev ii python3-ev3dev2 2.0.0 all Python language bindings for ev3dev

dwalton76 commented 4 years ago

Hmm, I am sure the combo of negative speeds with on_to_coordinates is something I did not test when working on odometry. It could be made to work though...we start out by calculating what angle to turn to before driving forwards, we would just need to add 180 to that before driving backwards.

For now I would stick to positive speed...the dog will be happier that way :)

kpu979 commented 4 years ago

quick q: where is the log file that gets written to by odometry? I'd like to understand this, and perhaps make an attempt at getting this fixed.

I think it's more than calculating the angle to turn. _odometry_monitor need to know the speed (positive or negative) to calculate the true positional movement across a grid.

dwalton76 commented 4 years ago

https://stackoverflow.com/questions/6386698/how-to-write-to-a-file-using-the-logging-python-module

Is what you want to do in your program