Skip to content

C & CPP API

Fatemeh Pahlevan Aghababa edited this page Jan 4, 2020 · 16 revisions

Overview

This video tutorial covers the full process of install and run the server. If you are using mac or Ubuntu please skip the Cygwin installation process and take a look at Installation section. Also, It should be mention that after running the compilation script in ubuntu or mac, the player.dll will be replaced with player.dylib in mac and player.so in ubuntu.

Installation

In order to use the C/C++ API, you only need to have a g++ compiler:

  • Windows: Download the Cygwin and watch this video tutorial on how to install it properly.
  • mac: Apple's XCode tools package already contains g++.
  • Ubuntu: Open the terminal and copy-paste the following commands
     sudo apt-get update
     sudo apt-get install g++
    

Compilation

The compilation process can be done using the provided script files which could be found in the easy_setup folder depending on your current OS.

Run

The C/C++ client can be ran using the provided scripts which could be found in the easy_setup folder depending on your current OS. It should be mentioned that you can still use the Easy setup & Run tutorial and use the "run2_client_cpp" name instead of "run2_client".

Usage

The C/C++ API consists of the following files that each will be explained here. These files are located in the Client/cpp directory.

client
|
|- player.py (The Main player file that you should fill if you are using Ubuntu or Mac)     ** Change This **
|- player_win.py (The Main player file that you should fill if you are using Windows)     ** 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 **

Player/ Player_win:

This file consists of three functions:

  1. Start (Called at the beginning of the Game)

You Received world info which will be set in the global variables in the file and could be used later. This function should return the team name at the end of the function. World info is as follows:

  • The number of teams in the world
  • The number of Robots each team is using
  • The number of the color sensor each robot has
  • The number of proximity sensor each robot has
 char *  start(int _team_size,int _robot_per_team,int _color_sensor_size,int _proximity_sensor_size){
	team_size=_team_size;
	robot_per_team=_robot_per_team;
	color_sensor_size=_color_sensor_size;
	proximity_sensor_size=_proximity_sensor_size;
	return "my_team_name";
}
  1. Play (Called every loop of the simulator)

You Received robot observation:

  • Information about each color sensor(the sample player is written for 3 color sensor, each color sensor return 3 values(r,g,b) in terms of an array)
  • Information about whether each proximity sensors has detected an obstacle or not in terms of 1/0. The Current robot model contains 8 proximity sensors which mean the proximity_detected array size is 8.
  • Information about the distance of each obstacle to Robot when each proximity sensor senses the obstacle in terms of the float array which each of its elements shows the correspondent value to each proximity sensor and its size is 8.
  • The Robot's Position in (x,y,z) coordinates.

You should fill the Command values using pointers and return the Action Command :

  • Move: The Linear and Angular speed of the robot should be set in "wheel_linear" and "wheel_angular".
  • Action: The position of the action should be set whenever an action is detected using "action_x","action_y" and "action_z". In the current player sample, the "find_checkpoint" action is defined and the play function should return the Action's name whenever an action is detected and the positions are set. Please take a look at World and Rules for more information about the Actions.
 char* play(int colors_1[],int colors_2[],int colors_3[],int proximity_detected[],float proximity_distances[],float pos[],int *led_color_id,float *wheel_linear, float *wheel_angular,float * action_x,float * action_y,float * action_z){

    """ THIS FUNCTION WILL BE CALLED FOR EACH ROBOT
       led_color_id:  1---> red  2---> green 3---> blue 4---> off
       colors_1[]:  color sensor 1 value, colors are defined by (r,g,b), colors_1[0]-->r value  colors_1[1]-->g value colors_1[2]-->b value
       colors_2[]: color sensor 2 value, colors are defined by (r,g,b), colors_2[0]-->r value  colors_2[1]-->g value colors_3[2]-->b value
       colors_3[]: color sensor 3 value, colors are defined by (r,g,b), colors_3[0]-->r value  colors_2[1]-->g value colors_3[2]-->b value
       wheel_linear: linear velocity 
       wheel_angular: angular velocity
       proximity_distances[]: values of proximity sensor receptively, you can find the order numbers by clicking on each proximity sensor of robot model in model tree,vrep
       proximity_detected[]: the array length is equal to number of proximity sensor receptively and it's value is 0 or 1 for each proximity. 1 shows that the obstacle is detected
       pos[]: pos[0] --> x  pos[1] --> y   pos[2]--> z
       action_x: the x position of the detected action
       action_y: the y position of the detected action
       action_z: the z position of the detected action
       return char*: action name if action is detected or empty string
    """
    # Your code will be here
}
  1. End (Called at the end of the Game)

You Can send any message you want to the server at the end of the game by just return it as a string.

char * end(){
	return  "The Ending Message";
}
Clone this wiki locally