Change default PID values using blocks coding #2380
-
|
Currently, I'm using a solution, but I'm not sure if it's the most efficient one. My workflow is to create the code using blocks, then copy and paste it into a Python file where I have to manually change the default PID values. I would prefer to input these values directly within the block code interface. Is it possible? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 4 replies
-
|
Yes! You can make it work with one Python function that you never have to change. You can just enter your values in the blocks. Here is an example for a single motor: The meaning of the values is given here. In this example we only set the first 3 values. The rest remains unchanged.
You can see the original values and the new ones at the bottom. For a drivebase you can change the controls for the distance and heading:
To make these examples work, create an additional Python file called from pybricks.tools import run_task
async def awaitable():
return None
def set_pid(control, *values):
print("Original", control.pid())
control.pid(*values)
print("New ", control.pid())
if run_task():
return awaitable()
def motor_pid(motor, *values):
return set_pid(motor.control, *values)
def distance_pid(drivebase, *values):
return set_pid(drivebase.distance_control, *values)
def heading_pid(drivebase, *values):
return set_pid(drivebase.heading_control, *values)So it will look like this:
|
Beta Was this translation helpful? Give feedback.



Yes! You can make it work with one Python function that you never have to change.
You can just enter your values in the blocks. Here is an example for a single motor:
The meaning of the values is given here. In this example we only set the first 3 values. The rest remains unchanged.
You can see the original values and the new ones at the bottom.
For a drivebase you can change the controls for the distance and heading:
To make these examples work, create an additional Python file called
pid_pythonwith the following contents: