from robotar import RobotAR
robot = RobotAR()
while True:
# Get the front centre sensor value and assign the value to 'front_sensor'
front_sensor = robot.prox_horizontal[2]
# If an obstacle is detected, the robot will stop.
if front_sensor !=0: # Detecting if an obstacle is ahead
robot.halt() # Stops the robot
else:
robot.wheels(50,50) # Moves in a straight line at a speed of 50 units
robot.sleep(0.1)
from robotar import RobotAR
robot = RobotAR()
while True:
# Get the left ground delta sensor value and assign the value to 'ground_sensor_delta'
ground_sensor_delta = robot.prox_ground.delta[0]
# If the ground below the robot is dark, the robot will stop.
if ground_sensor_delta <=600:
robot.halt() # Stops the robot
else:
robot.wheels(50,50) # Moves in a straight line at a speed of 50 units
robot.sleep(0.1)
from robotar import RobotAR
robot = RobotAR()
while True:
# Get the left ground delta sensor value and assign the value to 'ground_sensor_delta'
ground_sensor_delta = robot.prox_ground.delta[0]
# If the ground below the robot is dark, the robot will slow down.
if ground_sensor_delta <=600: # Increase the value to increase the sensitivity
robot.wheels(50,50) # Moves in a straight line at a speed of 15 units
robot.sleep(0.1)
else:
robot.wheels(150, 150) # Moves in a straight line at a speed of 80 units
robot.sleep(0.1)
from robotar import RobotAR
robot = RobotAR()
while True:
# Get the accelerometer value and assign the value to 'acceleration_value'
acceleration_value = robot.accelerometer[1]
# If the robot collides with an obstacle, the robot will move backward.
if acceleration_value == [32,32,32]:
robot.wheels(-50,-50)
robot.sleep(5)
else:
# Moves in a straight line at a speed of 50 units
robot.wheels(50, 50)
robot.sleep(0.1)