Skip to content

Relay Server REST Communication

smurve edited this page Oct 10, 2014 · 9 revisions

Overview

The relay server as well as your bot will be deployed in the cloud. There, the bot and the relay station will talk together using a REST API. Since the relay server has to send data to the bot as well, both have to send and listen to their specific REST Endpoints.

REST API Basics

The REST APIs expect the sent data in JSON Format application/JSON.

Relay-Server REST API

Base sever URL: http://carrera-relay.beta.swisscloud.io/relay

POST /relay/speed (application/json)

The Bot can set the current speed of the race car by sending a POST request at /ws/rest/relay/speed with SpeedControl data. With each SpeedControl you send to the server, you have to provide your teamId and access code. This is primarily used to avoid distraction from malfunctioning bots while another team is having their race. Consider the example data below:

SpeedControl Data Example:

{
    "teamId": "carrera1",
    "accessCode": "Cool1234",
    "power": 30,
    "timeStamp": 1412687484912
}

Your Bot REST API

As described before, your bot has to provide a REST endpoint as well. The bot will receive important data from the race-track and the car such as sensor events.

GET /ping

The ping resource is used to check if your bot is alive. Your bot is expected to answer with the string "success" as text/plain.

POST /start (application/json)

This POST request is sent by the relays server when your race has started. Depending on your bot logic, you may want to send an initial velocity to the race track now. No content is transmitted by this request.

POST /sensor (application/json)

This POST request is sent by the relays server when new sensor data is available from the race-track / car. This includes the car sensor data (acceleration, gyro-data etc) and also the light barrier event, which is sent when the car has passed a round. You will receive a SensorEvent as JSON:

SensorEvent Data Example:

{
    "type": "CAR_SENSOR_DATA",
    "timeStamp": 124123443,
    "acc": [
        1.1,
        2.2,
        3.3
    ],
    "gyr": [
        4.4,
        5.5,
        6.6
    ],
    "mag": [
        7.7,
        8.8,
        9.9
    ]
}

type can either be CAR_SENSOR_DATA or ROUND_PASSED