Skip to content

Latest commit

 

History

History
64 lines (45 loc) · 2.41 KB

README.md

File metadata and controls

64 lines (45 loc) · 2.41 KB

Humanoid Robot Wrestling Controller Example

webots.cloud - Competition

Alice C++ controller

Minimalist C++ controller example for the Humanoid Robot Wrestling Competition. Demonstrates how to play a simple motion file. We use the Motion class from Webots. It could also be programmed in Python, C or Java.

Here is the participant.cpp file:

#include <webots/Robot.hpp>
#include <webots/utils/Motion.hpp>

using namespace webots;

int main() {
  // Robot initialization
  Robot *robot = new Robot();

  // Motion files are text files containing pre-recorded positions of the robot's joints
  Motion *motion = new Motion("../motions/HandWave.motion");
  // We play the hand-waving motion on loop
  motion->setLoop(true);
  motion->play();

  const int time_step = robot->getBasicTimeStep();
  // Mandatory function to make the simulation run
  while (robot->step(time_step) != -1);

  // Robot cleanup
  delete robot;
  return 0;
}

To compile the C++ code, the Dockerfile must be updated; the environment variables needed for python can be removed and a call to make is needed to compile the source code:

FROM cyberbotics/webots.cloud:R2023a-ubuntu20.04

# Environment variables needed for Webots
# https://cyberbotics.com/doc/guide/running-extern-robot-controllers#remote-extern-controllers
ENV LD_LIBRARY_PATH=${WEBOTS_HOME}/lib/controller:${LD_LIBRARY_PATH}
ARG WEBOTS_CONTROLLER_URL
ENV WEBOTS_CONTROLLER_URL=${WEBOTS_CONTROLLER_URL}

# Copies all the files of the controllers folder into the docker container
RUN mkdir -p /usr/local/webots-project/controllers
COPY . /usr/local/webots-project/controllers

WORKDIR /usr/local/webots-project/controllers/participant

# Compile controller
RUN make
    
ENTRYPOINT ["./participant"]

Bob is a more advanced robot controller able to win against Alice.