Clone wiki

subt / tutorials / CustomControl

This tutorial describes how to get started with your own solution to the SubT Challenge. Before starting, make sure you have followed the one of the installation procedures.

The SubT virtual test bed uses Ignition Gazebo for simulation and ROS for robot control. This means ROS will be your entry point, and Gazebo should be treated as a separate application that you do not directly interface with.

The set of ROS services and topics at your disposal are listed here.

If you are unfamiliar with ROS, then we recommend following these ROS tutorials before proceeding.

  1. We will use the subt_seed repository, which contains a bare-bones example to control a vehicle.

  2. Fork the subt_seed repository using this link.

  3. Create a catkin workspace

    mkdir -p ~/subt_seed_ws/src
  4. Clone your fork of the subt_seed repository. If you changed the name of the repository when you forked subt_seed, then replace subt_seed with your chosen name in the following command.

    cd ~/subt_seed_ws/src
    hg clone<YOUR_USERNAME_HERE>/subt_seed
  5. Build the workspace

    cd ~/subt_seed_ws
    source /opt/ros/melodic/setup.bash
    catkin_make install
  6. Launch a subt simulation environment in a terminal.

    a. If you are using the docker installation method for subt

    ign launch -v 3 competition.ign

    b. If you are using the catkin workspace installation method for subt

    cd ~/subt_ws
    source install/setup.bash
    ign launch -v 3 competition.ign
  7. In another terminal, run the subt_seed example

    source /opt/ros/melodic/setup.bash
    cd ~/subt_seed_ws
    source install/setup.bash
    roslaunch subt_seed x1.launch
  8. At this point you should see a robot appear and start driving forward. Now let's take a look at the code.

  9. Everything happens in the file.

  10. In the main function, we initialize ROS, create our controller, and start a update loop.

    // Initialize ros
    ros::init(argc, argv, argv[1]);
    ROS_INFO("Starting seed competitor\n");
    // Create the controller
    Controller controller(argv[1]);
    // This sample code iteratively calls Controller::Update. This is just an
    // example. You can write your controller using alternative methods.
    // To get started with ROS visit:
    ros::Rate loop_rate(10);
    while (ros::ok())
  11. Now look in the Controller. This class creates a CommsClient in the constructor. The CommsClient provides a mechanism to communicate with other robots on your team. You must use the CommsClient for robot-robot communication.

    // Create subt communication client
    this->client.reset(new subt::CommsClient(_name));
    this->client->Bind(&Controller::CommClientCallback, this);
  12. We also create a ROS publisher that will send Twist message to move the robot.

    // Create a cmd_vel publisher to control a vehicle.
    this->velPub = this->n.advertise<geometry_msgs::Twist>(_name + "/cmd_vel", 1);
  13. Finally, in the Controller's update function we continually send a forward velocity control message.

    void Controller::Update()
      // Add code that should be processed every iteration.
      // The following code will continuous drive the robot forward.
      geometry_msgs::Twist msg;
      msg.linear.x = 1.0;
  14. Now it's time for you to write your own solution. You can access sensor data from your robot, send messages to other robots, move your robot, and locate artifacts.