PybotARena Documentation
Import
from pybotarena import RobotAR, PlatformAR
Setup
RobotAR(ip_address, port_number, robot_id)
This is used to instantiate an object to control the virtual robot in AR.
Example code:
ip_address = "10.19.27.227" # enter the IP address you see on the iPad
port_number = 49277 # enter the port number you see on the iPad
robot_id = 0 # choose the robot using their id from the iPad's screen (id range from 0 to 3)
# instantiate the robot object
robot = RobotAR(ip_address, port_number, robot_id)
Actuators
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()
Sensors
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)
Use delta only in your coding.
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]
delta values can be used to detect various Platform objects on the floor. See Platform Code.
Example code:
if robot.get_prox_ground().delta[0] == PlatformAR.platform_code['exit']:
# do something
Platform Code
PlatformAR class contains a dictionary that can be used to detect various platform object in the ARena. The dictionary pairs the keyword of the various platform' objects and the delta light detected by the ProxGround object.
'path': user generated path object.
'item': object that can either be a weapon or item to create a weapon.
'crafting': object to craft weapon.
'launch': object to launch attack.
'teleport': object to teleport to another teleport object.
'exit': object on the platform to exit the stage.
'none' : AR generated ground floor.
Example code:
if robot.get_prox_ground().delta[0] == PlatformAR.platform_code['item']:
# do something