What are you Looking for?
Robocup Junior Rescue Simulation Platform
E: Email:
The Python API consists of the following files that each will be explained here.
client
|
|- player.py (The Main player file that you should fill) ** Change This **
|- simplus.proto (Protobuf Message) ** Don't Change **
|- requirements.txt (list of requirements ) ** Don't Change **
|- sample.py (The Sample player file that filled for you) ** Don't Change **
|- client.py (The main python application that should run) ** Don't Change **
|- simplus_pb2.py (Auto-generated file from the protobuf) ** Don't Change **
|_ simplus_pb2_grpc.py (Auto-generated file from the grpc) ** Don't Change **
Please first look at messages.
This file consists of three functions:
You Received world info from the first argument and should fill your team info in the next one.
def Start(world_info, team_info): """ THIS FUNCTION WILL BE CALLED IN THE BEGINING world_info : IN {team_count, robot_per_team, color_sensors, distance_sensors, check_points} team_info : OUT {name} """ global info info = world_info # Fill your team information team_info.name = 'my_team_name'
You Received robot observation and server info then you should fill your robot command in the next one. The id shows the ID of your robot in case you have more than one robot in the world.
def Play(id, server, observation, command): """ THIS FUNCTION WILL BE CALLED FOR EACH ROBOT id : IN robot ID server : IN server Infomation {time, score, state} observation: IN {camera, position, color[], distance[]} command : OUT {linear, angular, LED, actions[]} """ # Your code will be here
You Received server info from the first argument and should fill your result in the next one.
def End(server, result): """ THIS FUNCTION WILL BE CALLED AT THE END server : IN server Infomation {time, score, state} result : OUT {message, map} """ # Get ending server info from server # Fill your final result here result.message = 'The Ending Message'
# Check if proximity sensor1 detect an obstacle that is in less than 0.3 distance from the robot. check=False if observation.distances[1].detected==1 and observation.distances[1].distance<0.3 : check=True
# forward command.linear = 0.05 command.angular = 0.0 # turn right command.linear = 0.0 command.angular = -0.5 # turn left command.linear = 0.0 command.angular = 0.5
# get red, green and blue value in range of (0,255) from color sensor # [0]-> center [1]-> left [2]-> right red = observation.colors[0].r green = observation.colors[0].g blue = observation.colors[0].b
x = observation.pos.x y = observation.pos.y x = observation.pos.z
# 'exit' Action command.actions.append(Action(x=observation.pos.x,y=observation.pos.y,z=observation.pos.z,type='exit'))
# change the LED color to red # ['red'] -> red, ['green'] -> green, ['blue'] -> blue,['']-> off command.LED = col['red']
def convert_to_cv_img(img_raw, h, w):
img_array = np.frombuffer(img_raw, dtype=np.uint8)
img = img_array.reshape(h, w, 3)
img_center = (w / 2, h / 2)
mirrored_img = cv2.getRotationMatrix2D(img_center, 180.0, 1.0)
main_img = cv2.warpAffine(img, mirrored_img, (w, h))
main_img = cv2.flip(main_img, 1)
return main_img
camera_img = convert_to_cv_img(observation.camera.raw, observation.camera.h, observation.camera.w)
thermal_img = convert_to_cv_img(observation.thermalCamera.raw, observation.thermalCamera.h, observation.thermalCamera.w)