Python机器人代写｜CS3630 Project 1: Trash Sorting Robot
Some of you may have heard that this course has a lab portion that deals with “actual” robots, but
given the high enrollment of this semester and the current pandemic, we will not have the bandwidth for
that. Instead, we will be building robot applications in a simulated environment with Robot Operating
System (ROS) using Python. ROS is a set of software libraries and tools for building robot applications.
There are multiple versions of ROS available. In this course, we will be using the latest ROS distribution
ROS2 Galactic throughout the semester. The ROS official website (linked above) has very detailed
documentation and a lot of tutorials covering different concepts. Feel free to refer to them at any time.
In this project, we will be building a (simulated) trash sorting robot as illustrated in the textbook for this
course. In this scenario, the robot tries to sort trash of some pre-determined categories into corresponding
bins. Please refer to Section 2 of the book for a more detailed description of the scenario. You will also
have to complete a report that assesses your understanding of the concepts discussed in the book section.
IMPORTANT NOTE: Unfortunately, there is not a windows version of GTSAM at this
time. As such, if you are using a windows machine to work on your project, please use
Windows Subsystem for Linux (guide here), or follow the virtual machine tutorial in the
appendix of the instructions.
In this section, we will be installing ROS2 Galactic through RoboStack. RoboStack is a bundling of the
ROS by Open Robotics for Linux, Mac and Windows using the Conda package manager. If you haven’t
already done so, go to this link and install Miniconda for your system. (Note: If you are on Windows,
please install Miniconda in a path that has NO space in its name.) Once it’s installed run the following
commands in a terminal (terminal refers to the terminal application on macOS and Linux, on Windows it
should be the Anaconda Powershell application):
# Install mamba
conda install mamba -c conda-forge
# Create a new environment
mamba create -n ros_env python=3.8
# Activate the environment
conda activate ros_env
# Add the conda-forge channel to environment configuration
conda config –env –add channels conda-forge
# Add channel for ROS2 Galactic
conda config –env –add channels robostack-experimental
# Use strict channel priority
conda config –env –set channel_priority strict
# Install ROS2 Galactic
mamba install ros-galactic-desktop
# Additionally, install gtbook (this also installs gtsam)
pip install -U gtbook
# Re-activate the environment
conda activate ros_env
IMPORTANT NOTE: Make sure that the installed version of gtbook is 0.0.13 or greater
and the installed version of gtsam is 4.2a3 or greater.
To check if your ROS2 installation works, open two terminals, activate the ros_env environment by
running conda activate ros_env, run the following code in one terminal:
ros2 run demo_nodes_cpp talker
and run the following code in another:
ros2 run demo_nodes_cpp listener
If your installation is correct, you should be able to see a talker publishing a message and a listener receiving
a message as in the following picture. Note that this is an example of the publisher-subscriber model that
will be discussed in the next section.
We are expecting many different issues with this installation on macOS and Windows due to different
system configurations that everyone has. If you run into any error and are able to solve it, we encourage you
to share your debugging experience on Piazza. We will also try our best to answer these setup questions.
If you have no luck getting ROS2 to run on your system, don’t worry, please refer to Appendix A for the
Linux virtual machine setup guide.
There are many ways for robots to communicate with the environment or with each other. In this project,
we will be diving into the publisher-subscriber model. To help you better understand this concept, we will
introduce a few terminologies:
• Node – A node is a process that performs computation. Nodes are combined together into a graph
and communicate with one another.
• Message – Nodes communicate with each other by publishing messages to topics. A message is a
simple data structure, comprising typed fields.
• Topic – Topics are named buses over which nodes exchange messages. Note that each topic is strongly
typed by the ROS message used to publish it and nodes can only receive messages with a matching
type. Topics have anonymous publish/subscribe semantics, which decouples the production of infor
mation from its consumption. In general, nodes that are interested in data subscribe to the relevant
topic (subscriber); nodes that generate data publish to the relevant topic (publisher). There can be
multiple publishers and subscribers to a topic.
• Publisher – A node that creates and sends messages to a topic(s).cx
• Subscriber – A node with a subscription to a topic(s) to receive messages from it.
Let’s look back at the publisher-subscriber model. As the name suggests, there is usually (at least) 1
publisher and (at least) 1 subscriber in the model. There are multiple publisher-subscriber relationships in
this project. For example, there is a publisher for the conductivity sensor in world.py and a subscriber for
this in brain.py. There is also a publisher for the final sorting decision in brain.py, while its subscriber
lives in world.py. To see a list of all active topics, you can start your publisher and run the command
ros2 topic list. Note that in the image below, the demo_talker node is publishing to the chatter