LEGO Medium Motor/Servo Motor
monsfortis1940 opened this issue · 6 comments
#!/usr/bin/env Python3 version:**
hello
For a linefollowing program I like to use a LEGO MediumMotor for streering a robot by (fast !) turning the front wheels to the left or to the right. (parallel steering)
Can I "change"/use the MediumMotor in/as a motor with ServoMotor properties (fi zero point correction)
kind regards
Mario
If the question is for a way to request that a MediumMotor
rotate to a particular angle, you can use on_to_position
: https://ev3dev-lang.readthedocs.io/projects/python-ev3dev/en/ev3dev-stretch/motors.html#ev3dev2.motor.Motor.on_to_position
I think that should be sufficiently responsive for this use case. You'd probably want to set it to non-blocking mode so you can continue operating your robot while the motor turns.
It looks like you're using on_for_rotations
, which moves it the specified amount relative to where it currently is rather than relative to some consistent reference point. You're going to want on_to_position
, which moves the motor to a particular position relative to a known starting position when the EV3 turned on.
Note that you might not want to use the position the motor was in at the time the EV3 booted as the "zero point"; I recommend you have some known position the motor can be moved into, and then set m.position = 0
before starting your main code. That will tell the motor to start at the position it is currently at when being commanded with on_to_position
. Again, remember that this position is forgotten every time the EV3 turns off.
Yeah, unfortunately the medium/large motors don't have a way to "remember" a position across reboots; they only measure deltas. That being said, the typical solution is to have a hard-stop at the extreme of your motor's travel (e.g. at 45° to the side) and then have your code start by turning all the way until the motor stops moving and save that position as 45°. So every time your code starts, it would calibrate itself. If that isn't an option, you'll probably need a different motor.