@@ -12,7 +12,7 @@ Let's identify the terms we'll need to use in our code:
1212**Set Point ** or desired value: In this example, this is some set distance from the rangefinder we want the robot to be at.
1313For this example, let's say 20cm.
1414
15- **Process Variable ** or current value: We obtain our measured value from polling the rangerfinder. This is
15+ **Process Variable ** or current value: We obtain our measured value from reading the rangerfinder value . This is
1616:code: `rangefinder.distance() `.
1717
1818Our goal is for our process variable (the rangefinder distance) to approach the set point (20 cm).
@@ -22,7 +22,7 @@ is also "correct". The distinction in sign is simply whichever makes more sense
2222we would want to drive forward 10cm, so we would want a positive error to make our motors spin forward.
2323
2424**Control Output **: In this case, this is our motor effort. This is because we want to drive with a speed proportional
25- to the distance error. As a reminder for P control, this will be calculated as :code: `motorEffort = Kp * error `.
25+ to the distance error. As a reminder for P control, this will be calculated as :code: `motor_effort = Kp * error `.
2626
2727**Kp **: This is our proportional gain. Though we will need to tune this value, we can guess a somewhat reasonable value
2828by considering the range of values our error can take, and the domain of our control output. In this case, if we're 30cm away
@@ -44,14 +44,14 @@ Let's start by defining our proportional gain and our set point:
4444 .. code-block :: python
4545
4646 Kp = 0.1
47- desiredDistance = 20
47+ desired_distance = 20
4848
4949 .. tab-item :: Blockly
5050
5151 .. image :: media/variables.png
5252 :width: 300
5353
54- Next, we want to enter some sort of loop to continuously poll our rangefinder and update our motor effort from our controller output.
54+ Next, we want to enter some sort of loop to continuously read our rangefinder value and update our motor effort from our controller output.
5555
5656.. tab-set ::
5757
@@ -60,11 +60,11 @@ Next, we want to enter some sort of loop to continuously poll our rangefinder an
6060 .. code-block :: python
6161
6262 Kp = 0.1
63- desiredDistance = 20
63+ desired_distance = 20
6464 while True :
65- error = rangefinder.distance() - desiredDistance
66- motorEffort = Kp * error
67- drivetrain.set_effort(motorEffort, motorEffort )
65+ error = rangefinder.distance() - desired_distance
66+ motor_effort = Kp * error
67+ drivetrain.set_effort(motor_effort, motor_effort )
6868 time.sleep(0.05 )
6969
7070 .. tab-item :: Blockly
@@ -73,7 +73,7 @@ Next, we want to enter some sort of loop to continuously poll our rangefinder an
7373 :width: 500
7474
7575Each iteration of the loop consists of the following steps:
76- #. Poll the rangefinder to get the current distance
76+ #. Read the rangefinder value to get the current distance
7777 #. Calculate the error
7878 #. Calculate the control output through Kp * error
7979 #. Set the drivetrain motor efforts to the control output
0 commit comments