RobotAR()
This is used to instantiate an object to control the virtual robot in AR.
# instantiate the robot object
robot = RobotAR()
robot.wheels(left_speed=0, right_speed=0)
Set the left and right wheels' speed. The integer value ranges from -500 to 500. A negative value means the wheels will rotate on the opposite direction. This can be used to move backward or to turn. A speed of 500 on both wheels will move the robot at about 20 cm/s. A speed of 0 will stop the wheel.
Any value that is more than 0 but less than 50 will be clamped to 50.
Any value that is less than 0 but more than -50 will be clamped to -50.
Speed of around 100-200 would be advisable for most cases.
robot.wheels(100, 100) # move straight
robot.wheels(100, 0) # turn right
robot.wheels(0, 0) # stop
robot.halt()
Stops the robot. The shorthand function of robot.wheels(0, 0).
robot.sleep(t=0.0)
Suspends (waits) execution of the current thread for a given number of seconds. The shorthand function of time.sleep(t).
# move straight for 3 seconds then stop
robot.wheels(100, 100)
robot.sleep(3)
robot.halt()
robot.leds_top(r=0, g=0, b=0)
Sets the intensity of the top RGB LED. The integer value ranges from 0 to 32.
robot.leds_top(32, 32, 0) # yellow led colour
robot.leds_circle(led0=0, led1=0, led2=0, led3=0, led4=0, led5=0, led6=0, led7=0)
Sets the intensity of the circle LEDs where led0 is for the front of the robot and the others are numbered clockwise. The integer value ranges from 0 to 32.
robot.leds_circle(0, 0, 32, 0, 0, 0, 0, 0) # turn on right led
robot.prox_horizontal
Returns the horizontal proximity sensors as a list of seven integers. A non-zero value means there is an obstacle detected. The closer the obstacle is to the robot, the higher the values of these sensors be.
index 0: front left
index 1: front middle-left
index 2: front centre
index 3: front middle-right
index 4: front right
index 5: back left
index 6: back right
# get the front centre sensor value
h = robot.prox_horizontal[2]
robot.prox_ground
Returns a ProxGround object which contains the following attributes:
delta: difference between the reflected light and the ambient light, linked to the distance and to the ground colour.
reflected: amount of light received when the sensor emits infrared, varies between 0 (no reflected light) and 1023 (maximum reflected light). Normal floor.
ambiant: ambient light intensity at the ground, varies between 0 (no light) and 1023 (maximum light)
For each array, index 0 refers to the left sensor, and index 1 refers to the right sensor.
# get delta value of the right sensor
r = robot.prox_ground.delta[1]
# get reflected value of the left sensor
l = robot.prox_ground.reflected[0]
# get ambiant value of the right sensor
a = robot.prox_ground.ambiant[1]
robot.accelerometer
Returns a tuple of three elements which are the x, y, and z acceleration from the accelerometer. On normal condition, the value is [0, 0, 23]. When the robot collides with something or being tapped, the value will be [32, 32, 32] for a brief period.
# get y acceleration value
y = robot.accelerometer[1]
robot.button_forward
Returns 1 if the forward button is pressed on the screen, 0 otherwise.
robot.button_backward
Returns 1 if the backward button is pressed on the screen, 0 otherwise.
robot.button_left
Returns 1 if the left button is pressed on the screen, 0 otherwise.
robot.button_right
Returns 1 if the right button is pressed on the screen, 0 otherwise.