You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Added a reflectCal method to the Robot class which calibrates the color sensor RLI scale using black and white setpoints. Also added a correctedReflectedLightIntensity property which returns the scaled RLI using the calibration values from reflectCal. Started work on LineStop.
Moves the robot in a specified direction at a specified speed until a line (White-Black) is seen, while using the gyro sensor to keep the robot moving in a straight line.
348
+
349
+
``Heading``: The angle at which to drive, with the direction the gyro was last calibrated in being zero.
350
+
``Speed``: The speed at which to drive, in motor percentage (same speed units as EV3-G). A negative value will make the robot drive backwards.
351
+
``Stop``: Stop motors after completion. If ``FALSE``, motors will continue running after ``Distance`` has been traveled. Otherwise, motors will stop after ``Distance`` cm.
352
+
"""
353
+
# Ensure values are within reasonable limits, and change them if necessary (Idiotproofing).
354
+
ifSpeed>75:
355
+
Speed=75
356
+
print("Speed must be between -75 and 75 (inclusive).")
357
+
elifSpeed<-75:
358
+
Speed=-75
359
+
print("Speed must be between -75 and 75 (inclusive).")
360
+
361
+
sign=Speed/abs(Speed)
362
+
363
+
364
+
365
+
# Initialize variables for PID control
366
+
integral=0.0
367
+
last_error=0.0
368
+
derivative=0.0
369
+
# Check if the motors have gone far enough
370
+
whileavg<target:
371
+
# Read the gyro
372
+
current_angle=self.correctedAngle()
373
+
374
+
# Calculate the PID components
375
+
error=current_angle-Heading
376
+
integral=integral+error
377
+
derivative=error-last_error
378
+
last_error=error
379
+
380
+
# Calculate Steering value based on PID components and kp, ki, and kd
0 commit comments