Replies: 4 comments 1 reply
-
|
The nice thing about pybrick is, it uses a PID controller internally if you would use the gypo incombination with DriveBase. Below an example: Have you been using the gyro in your code? |
Beta Was this translation helpful? Give feedback.
-
With the default
It will do this with But note that with |
Beta Was this translation helpful? Give feedback.
-
|
YesBut the question is about which value the gyro will use as target in its internal PID. On Aug 12, 2025, at 9:22 AM, Roy Krikke ***@***.***> wrote:
The nice thing about pybrick is, it uses a PID controller internally if you would use the gypo incombination with DriveBase. Below an example:
from pybricks.hubs import PrimeHub
from pybricks.pupdevices import Motor, ColorSensor, UltrasonicSensor, ForceSensor
from pybricks.parameters import Button, Color, Direction, Port, Side, Stop, Axis
from pybricks.robotics import DriveBase
from pybricks.tools import wait, StopWatch
hub = PrimeHub()
left_motor = Motor(Port.A, Direction.COUNTERCLOCKWISE)
right_motor = Motor(Port.B, Direction.CLOCKWISE)
drive_base = DriveBase(left_motor, right_motor, wheel_diameter=56, axle_track=104)
drive_base.use_gyro(True)
drive_base.turn(90)
Have you been using the gyro in your code?
—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you authored the thread.Message ID: ***@***.***>
|
Beta Was this translation helpful? Give feedback.
-
|
Thanks for the insight. My understanding is that Stop.HOLD is for holding motor position, not holding the (desired) gyro heading, which was influenced by the surface friction. In other words, the motor maybe rotated back to HOLD its desired angle after compensating the extra degrees due to momentum, the gyro heading may not if it slipped, as a result, the robot still need to re-align to its desired target heading during the move. I’ll do some extra runs to see its behavior under different Stop settings On Aug 12, 2025, at 9:45 AM, Laurens Valk ***@***.***> wrote:
My question is: if the robot gets slipped, or hits a barrier during the turn, and it did not actually ended up at the desired target heading accurately (either overshoot or undershoot), will the "straight" command :
A) remembers the desired angle it "supposed to be" heading to and make corrections during the move, so the robot ended at right place even the turn was not perfect
With the default Stop.HOLD, yes, it will. A good way to see this is to put a wait(5000) between two movements and see what happens if you manually turn it while standing still. It should recover.
B). takes whatever heading it got at the beginning of the drive (even it's not exactly the desired heading due the issues in the previous turn), and maintain that wrong heading during the drive, so the robot ended in a wrong position (worsen if the distance is longer) if the turn was not perfect.
It will do this with Stop.COAST and Stop.BRAKE. After all, when the motors are off, it can't assume it is still in the same position for the next move, so it will just start from the current position.
But note that with turn(target_angle - hub.imu.heading()) it doesn't matter which stop mode you choose, since you're telling it to move to the heading regardless of the initial orientation.
—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you authored the thread.Message ID: ***@***.***>
|
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Good morning,
Transition to pybricks from Lego python API here. I have a question for a common move:
The robot needs to drive straight along a specific target angle (e.g 90 deg facing east) for some distance or until hitting a condition. I suppose we can write something either use proportional or PID control to check
hub.imu.heading()and compare to the desired target during the move, then make adjustment accordingly.With pybricks, it seems possible to have the robot just turn to the desired heading first: use
turn(target_angle - hub.imu.heading()), then just dostraight(distance). (BTW, will astraight_until(condition_function)function possible in the future?)My question is: if the robot gets slipped, or hits a barrier during the turn, and it did not actually ended up at the desired target heading accurately (either overshoot or undershoot), will the "
straight" command :A) remembers the desired angle it "supposed to be" heading to and make corrections during the move, so the robot ended at right place even the turn was not perfect
or
B). takes whatever heading it got at the beginning of the drive (even it's not exactly the desired heading due the issues in the previous turn), and maintain that wrong heading during the drive, so the robot ended in a wrong position (worsen if the distance is longer) if the turn was not perfect.
Did some test run, result was not conclusive since it's not easy to simulate the undesired runtime condition.
Thank you!
Beta Was this translation helpful? Give feedback.
All reactions