-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathRobot_Experiments_Turn_Accuracy.py
41 lines (33 loc) · 1.48 KB
/
Robot_Experiments_Turn_Accuracy.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
from pybricks.hubs import PrimeHub
from pybricks.pupdevices import Motor, ColorSensor, UltrasonicSensor, ForceSensor
from pybricks.parameters import Button, Color, Direction, Port, Side, Stop
from pybricks.robotics import DriveBase
from pybricks.tools import wait, StopWatch
hub = PrimeHub()
#Initialisate the robot
# Step 1 - Initialize the drive base
# Step 2 - Initialize the front and right motors
# Step 3 - Initialize the left and right color sensors in the front
#---------------------------------------------------------------------
# Initialize both motors. In this example, the motor on the
# left must turn counterclockwise to make the robot go forward.
left_motor = Motor(Port.A, Direction.COUNTERCLOCKWISE)
right_motor = Motor(Port.B)
# Initialize the drive base.
# In our robot, the wheel diameter is 88mm.
# The distance between the two wheel-ground contact points is 145mm.
drive_base = DriveBase(left_motor, right_motor, wheel_diameter=88, axle_track=145)
# Optionally, ucomment the line below to use the gyro for improved accuracy.
#drive_base.use_gyro(True)
#Initialize the front abnd back motors
front_motor = Motor(Port.D)
back_motor = Motor(Port.C)
# Initialize the color sensors.
right_sensor = ColorSensor(Port.F)
left_sensor = ColorSensor(Port.E)
#------------------------------------------
# Robot experiment for turn accuracy
#------------------------------------------
print(drive_base.settings())
drive_base.settings(turn_rate=300,turn_acceleration=1380)
drive_base.turn(-180)