Why doesn't motor hold its position even though I used the hold function ? #1906
Replies: 1 comment 1 reply
-
Robots are mechanical systems with some inertia. In your code when it reaches the target, the robot is still turning at your given speed. Forcing the motors to hold won't stop the robot immediately, but rather just slip a bit further due to the inertia. The builtin That said, for individual moves, a 1-degree error is not bad at all as long as the next move will take this into account, and continue to correct it. This is what the
It does. But holding the motor position doesn't mean the heading stays constant if the wheels slip due to physics. To see this, perhaps also print out the |
Beta Was this translation helpful? Give feedback.
-
I was transferring our turn function from last season's Spike Prime to Pybricks. The function is using left motor and right motor run in different direction at the same speed to make spin turn. And it is also using the hub.imu.heading() to compare with the target heading degree and stop the movement when the difference of these 2 values is within a tolerance range.
Although I used the the motor.hold() function to stop the motor and hold its position, the hub.imu.heading() still changes ( it becomes stable after around 30 ms , but the heading is way off the target heading I set for the turn)
Here is the code:
I added the last piece to keep on printing heading every 10 ms and here is top part of the output:
60.10498
60.60291
61.09998
61.46851
61.67529
61.78113
61.77881
61.71069
61.6438
61.61548
.....
As you can see, the function worked well and the heading was close to the target (60 degrees). But it is still increasing until stabilized at 61.5 degrees.
Could someone explain to me why it doesn't work as I expected? The only thing I can think off is motors were still moving in the first 30 ms, and the hold function worked after that. But why it didn't hold right away?
(I thought even the built-in drive_base.turn() function might be implemented with the same mechanism (running left and right wheels at different speed). How does it work if the motor can only hold the position after ~30 ms ? )
Thanks for your help!
Beta Was this translation helpful? Give feedback.
All reactions