Programming Virtual "Robot" - VTAstrobotics/Documentation GitHub Wiki
- In this onboarding exercise, you will program a virtual robot.
- To get started, open up VSCode, and clone the repository found at https://github.com/VTAstrobotics/VirtualRobotOnboarding/tree/main.
- To clone a repository in VSCode, click
Clone Git Repository
when the application starts, and then paste the following linkehttps://github.com/VTAstrobotics/VirtualRobotOnboarding.git
.- You can also clone the repository using git CLI if you prefer (
git clone <link>
).
- You can also clone the repository using git CLI if you prefer (

- Once you have cloned the repository and are inside of the repository folder in VSCode, click on the "Source Control" tab on the left of your screen (icon below)

- On the bottom of the screen, you should see text that says
main
. Click on that, and a drop down menu should appear from the top of your screen. ClickCreate new branch from
, and then selectmain
. You will be prompted to enter a name. Enter something relating to your name (e.g.ryan_robot
), and press enter. - On the source control screen on the left, there should be a blue button titled
Publish Branch
. Click this, and navigate back to the repository on a browser (https://github.com/VTAstrobotics/VirtualRobotOnboarding/tree/main). Clickbranches
. You should see your new branch listed! This allows you to develop code without affecting the main branch. You may have to sign in if prompted. - In our team, the main branch should always be the base robot code that we know works. Whenever we are adding a feature, we create a branch and name the branch after the feature we are adding. We can then take the code from the new branch and move it into main if the feature is successful. It is good practice to follow this convention. Don't push straight to main.
Assuming you installed Docker and the Dev Containers extension listed in Software Setup, this should be pretty easy. Press ctrl+shift+p, to bring up the command dropdown. Select Dev Containers: Rebuild and Reopen in Container
. Your container should start running (on the first run this can take a while).
- On the Explorer tab, click on src/subscriber/src/motor_node.cpp. This is the main file you will be editing.

- This repository has two main nodes, one publishing velocity commands to a topic, and one subscribing to that topic and distributing motor commands to left and right motors. Both nodes are written in C++.
- This is meant to replicate how a node might operate in a real robot (reading information from a topic, doing math, and publishing new data to another topic).
- The velocity command publisher has already been created.
- The code in motor_node_cpp.cpp is meant to subscribe to the topic published by the velocity command publisher, do math, and publish new data to two new topics. If you need a review on publishers and subscribers, and their syntax, head to https://docs.ros.org/en/humble/Tutorials/Beginner-Client-Libraries/Writing-A-Simple-Cpp-Publisher-And-Subscriber.html.
- Further instructions are actually written in motor_node_cpp.cpp.
- Here is a diagram of what is supposed to happen after you are finished coding. You are responsible for coding the motor controller node.

- navigate to the ros2_ws folder (
cd ~/ros2_ws
in your VSCode terminal) - Enter
colcon build
into the terminal to build your packages. You should see text showing your build progress.- if your build fails, look at the stack trace. Try to figure out why it failed. If you are stuck, contact me (Ryan)
- If your build is successful, source the workspace (enter
source install/setup.bash
). - you can now use the launch file in the repository. Type
ros2 launch start_robot launch.launch.py
to launch the velocity command node and the node you wrote.
- after launching your file, open a new terminal by clicking the "+" in the right hand corner of the terminal (WHILE THE NODES YOU LAUNCHED ARE STILL RUNNING:

- Now, you should push your changes to your branch. This allows you to share your code with your team members, and in a real setting would allow your code to be merged into main so it can run on the robot.
- First, reopen the folder locally by hitting ctrl+shift+p, and selecting
Dev Containers: Reopen Folder Locally
- Once this finishes, click back on the source control tab on the right. Make sure your branch is selected on the bottom instead of
main
- Type a commit message in the
messages
space, and click the bluecommit
button. - Click on the
Sync Changes
button. This pushes the code you wrote to our online repository.- Check if this works by navigating to https://github.com/VTAstrobotics/VirtualRobotOnboarding/tree/main, clicking branch, and then selecting your branch. If you see the message you wrote above on the right of the screen, you pushed successfully and are done!
- ROS2 documentation https://docs.ros.org/en/humble/Tutorials.html
- Specifically pub and sub tutorial: https://docs.ros.org/en/humble/Tutorials/Beginner-Client-Libraries/Writing-A-Simple-Cpp-Publisher-And-Subscriber.html
- The software lead
- I will be happy to answer any of your questions, or help you out if you are stuck. Just message me on discord.
- I have office hours posted on the Astrobotics Google Calandar, so drop by if you need help. If you can't make the times I have posted just message me and we can set something up!
- If you find any errors or missed steps in this tutorial, please message me (software lead) and I will fix them. If the error is something small like a typo on this page, feel free to edit it yourself.