Tutorial 4: Read an order
This tutorial shows how to subscribe to the /orders
topic and parse an Order
message.
Starting the environment for Tutorial 4
To start the environment, use this command:
ros2 launch ariac_gazebo ariac.launch.py competitor_pkg:=ariac_tutorials trial_name:=tutorial dev_mode:=True
Running tutorial 4
To start tutorial 4, open a new terminal and use this command:
ros2 launch ariac_tutorials tutorial.launch.py tutorial:=4
Expected output of tutorial 4
Code explanation for Tutorial 4
This is the node used for tutorial 4. The functions from competition_interface.py which are used are highlighted.
#!/usr/bin/env python3
import rclpy
import threading
from rclpy.executors import MultiThreadedExecutor
from ariac_tutorials.competition_interface import CompetitionInterface
from ariac_msgs.msg import CompetitionState
def main(args=None):
rclpy.init(args=args)
interface = CompetitionInterface(enable_moveit=False)
executor = MultiThreadedExecutor()
executor.add_node(interface)
spin_thread = threading.Thread(target=executor.spin)
spin_thread.start()
# The following line enables order displays in the terminal.
# Set to False to disable.
interface.parse_incoming_order = True
interface.start_competition()
while rclpy.ok():
try:
if interface.get_competition_state == CompetitionState.ORDER_ANNOUNCEMENTS_DONE:
break
except KeyboardInterrupt:
break
interface.end_competition()
spin_thread.join()
if __name__ == '__main__':
main()
The purpose of this tutorial is to log orders received by CompetitionInterface
. When an order is published by the /ariac/orders
, the interface._orders_cb
runs. The order msg which was published is then appended to interface._orders
. Then, since in the node interface.parse_incoming_order
was set to True
, the orders received are logged.
This is done using interface._parce_order
, where the order is parsed and returned as a string
.