Please contact oka_kurniawan [at] sutd [dot] edu [dot] sg for the solutions.
from robotar import RobotAR
robot = RobotAR()
def reverse(): #turn on red color
robot.leds_top(32,0,0)
robot.sleep(1)
def turn_left(): #turn on led0
robot.leds_circle(32,0,0,0,0,0,0,0)
robot.sleep(0.5)
def turn_right(): #turn on led7
robot.leds_circle(0,0,0,0,0,0,0,32)
robot.sleep(0.5)
while True:
#assigning each sensor value to a variable
sensor_left_front=robot.prox_horizontal[0]
sensor_front_centre=robot.prox_horizontal[2]
sensor_right_front=robot.prox_horizontal[4]
ground_sensor_delta=robot.prox_ground.delta[0]
#when an obstacle is detected, the robot will move backwards
if sensor_left_front!=0 or sensor_front_centre!=0 or sensor_right_front!=0:
robot.wheels(-50,-50)
robot.sleep(1)
reverse()
#when the ground is black, the robot will move backwards and turn slightly to the left
elif ground_sensor_delta<=600:
robot.wheels(-50,-50)
robot.sleep(1)
reverse()
robot.wheels(0,50)
robot.sleep(0.1)
turn_left()
#if above conditions are not fulfilled, robot move forward
else:
robot.wheels(50,50)
robot.sleep(0.1)
from robotar import RobotAR
robot = RobotAR()
def reverse(): #turn on red color and move backwards
robot.leds_top(32,0,0)
robot.sleep(1)
robot.wheels(-50,-50)
robot.sleep(1)
def turn_left(): #turn on led0 and turn left
robot.leds_circle(32,0,0,0,0,0,0,0)
robot.sleep(0.1)
robot.wheels(0,50)
robot.sleep(0.1)
while True:
#assigning each sensor value to a variable
sensor_left_front=robot.prox_horizontal[0]
sensor_front_centre=robot.prox_horizontal[2]
sensor_right_front=robot.prox_horizontal[4]
ground_sensor_delta=robot.prox_ground.delta[0]
#if an obstacle is detected or the ground is black, the robot will move backwards and turn slightly to the left
if sensor_left_front!=0 or sensor_front_centre!=0 or sensor_right_front!=0 or ground_sensor_delta<=600:
reverse()
turn_left()
#if backward button is pressed, the loop is terminated
elif robot.button_backward == 1:
break
#if above conditions are not fulfilled, robot moves forward
else:
robot.wheels(50,50)
robot.sleep(0.1)