Skip to content

se-buw/abt

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

39 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Getting started

--Consists of NuSMV Encoding--

--Consists of a ros2 workspace--

--Consists of the Gazebo .sdf files for simulating 3D environment and vehicles--

Packages of the ros2 workspace

3. BehaviorTree.CPP: C++ library for creating behavior trees

5. my_car_controller [Final deployment package]

1. my_robot_controller

This package consists of the following files

  1. init.py
  2. moveTurtle.py
  3. turtle_publisher.py
  4. turtle_subscriber.py
  5. advanced_turtle1.py
  6. advanced_turtle2.py
  7. advanced_turtle3.py

1. init.py

It initialises the python package and marks the directory as a package.

2. moveTurtle.py

It consists of the class MoveTurtle class which creates a publisher to control the turtle movement and subscriber to receive the co-ordinates of the turtle in the same terminal.

The turtle movement is controlled to draw a circle by changing the linear velocity, angular velocity and angle of the turtlesim node.

Run the code following the instructions at the end and using the name moveTurtle.

Dependencies

rclpy
Node from rclpy.node
Twist from geometry_msgs.msg
Pose from turtlesim.msg

3. turtle_publisher.py

It consists of the class TurtlePublisher which controls the turtlesim node to move in a circle.

The turtle movement is controlled to draw a circle by changing the linear velocity, angular velocity and angle of the turtlesim node.

Run the code following the instructions at the end and using the name turtle_publisher.

Dependencies

rclpy
Node from rclpy.node
Twist from geometry_msgs.msg
time

4. turtle_subscriber.py

It consists of the class "TurtleSubscriber" which receoves the messages from the turtlesim node x and y coordinates.

Run the code following the instructions at the end and using the name turtle_subscriber.

Dependencies

rclpy
Node from rclpy.node
Pose from turtlesim.msg

5. advanced_turtle1.py

It is used to control the movement of the turtlesim node by implementing a Behavior Tree (BT).

It consists of the class

  • "MoveForward" which inherits from the py_trees.behavior.Behavior and moves the turtlesim node forward.
  • "ZigZag" which turns the turtle left and right to move in a zigzag motion

The BT structure is as below:

Sequence (Root)
|
|-- MoveForward (Action node)
|
|-- Zigzag (Action node)

The main function is used to define the structure of BT.

Run the code following the instructions at the end and using the name advanced_turtle1.

Dependencies

py_trees
rclpy
Node from rclpy.node
Twist from geometry_msgs.msg\

6. advanced_turtle2.py

It is used to control the movement of the turtlesim node by implementing a Behavior Tree (BT).

It consists of the class

  • "MoveForward" which inherits from the py_trees.behavior.Behavior and moves the turtlesim node forward.
  • "ZigZag" which turns the turtle left and right to move in a zigzag motion
  • "RotateClockwise" which rotates the turtle clockwise using the angular component of the node.
  • "RotateCounterClockwise" which rotates the turtle counter-clockwise using the angular component of the node.

The BT structure is as below:

Sequence (Root: Sequence node)
|
|-- MoveForward (Action node)
|
|-- Zigzag (Action node)
|
|-- RotateClockwise (Action node)
|
|-- RotateCounterClockwise (Action node)\

The main function is used to define the structure of BT.

Run the code following the instructions at the end and using the name advanced_turtle2.

Dependencies

py_trees
rclpy
Node from rclpy.node
Twist from geometry_msgs.msg

7. advanced_turtle3.py

It is used to control the movement of the turtlesim node by implementing a Behavior Tree (BT).

It consists of the class

  • "MoveForward" which inherits from the py_trees.behavior.Behavior and moves the turtlesim node forward.
  • "ZigZag" which turns the turtle left and right to move in a zigzag motion
  • "RotateClockwise" which rotates the turtle clockwise using the angular component of the node.
  • "RotateCounterClockwise" which rotates the turtle counter-clockwise using the angular component of the node.

The BT structure is as below:

RootSelector (Root : Selector node)
|
|-- ForwardNode (Sequence node)
| |
| |-- MoveForward (Action node)
| |
| |-- Zigzag (Action node)
|
|-- RotationNode (Sequence node)
|
|-- RotateClockwise (Action node)
|
|-- RotateCounterClockwise (Action node)\

The main function is used to define the structure of BT.

Run the code following the instructions at the end and using the name advanced_turtle3.

Dependencies

py_trees
rclpy
Node from rclpy.node
Twist from geometry_msgs.msg

2. my_behavior_tree

This package consists of the following executable files

my_behavior_tree.cpp

my_behavior_tree implements a basic Behavior tree (BT) which inherits from behaviortree_cpp C++ package. This file executes a BT by traversing the xml file /behavior_trees/my_behavior_tree.xml. As the BT is executed the output is printed in the console.

The contents of my_behavior_tree.xml are given below,

  • MainTree
    • Sequence (RootSequence)
      • MoveForward
      • TurnLeft
      • MySelector (BatteryCheckSelector)
        • CheckBattery
        • Sequence (MoveTurnSequence)
          • MoveRight
          • StopMovement

We see the following ouput in the console:

Moving forward...
Turning left...
Checking battery...

Update the path in the my_behavior_tree.cpp file for the xml file as in your local directory before running the code. Run the file following the instructions at the end and using the name my_behavior_tree.

Dependencies

behaviortree_cpp
iostream

4. my_turtle_controller

This package consists of the following executable files

my_turtle_behavior.cpp

my_turtle_behavior implements a Behavior tree (BT) which inherits from behaviortree_cpp C++ package. This file executes a BT by traversing the xml file /behavior_trees/my_turtle_behavior.xml. As the BT is executed the turtlesim node is controlled to trace the path in a hexagon fashion.

The behavior tree which is stored in the xml as follows:

  • MainTree
    • Sequence
      • Sequence
        • MoveForward
        • RotateClockwise
      • Sequence
        • MoveForward
        • RotateClockwise
      • Sequence
        • MoveForward
        • RotateClockwise
      • Sequence
        • MoveForward
        • RotateClockwise
      • Sequence
        • MoveForward
        • RotateClockwise
      • Sequence
        • MoveForward
        • RotateClockwise
      • Sequence
        • MoveForward
        • RotateClockwise

Update the path in the my_turtle_behaviore.cpp file for the xml file as in your local directory before running the code. Run the file following the instructions at the end and using the name my_turtle_controller.

Dependencies

behaviortree_cpp
rclcpp
geometry_msgs
turtlesim\

5. my_car_controller

This package consists of the following executable files

  • my_car_controller.cpp

my_car_controller implements a Behavior tree (BT) which inherits from behaviortree_cpp C++ package. This file executes a BT by traversing the xml file /behavior_trees/my_car_behavior.xml. As the BehaviorTree is traversed it interacts with the simulated bot in the Gazebo environment. It publishes in the /cmd_vel topic to control the movement of the car. It also subscribes to the lidar and contact information for autonmous navigation.

Update the path in the my_car_controller.cpp file for the xml file as in your local directory before running the code.

Run the file following the instructions at the end and using the name my_car_controller.

Dependencies

behaviortree_cpp
rclcpp
geometry_msgs\

Gazebo files

  1. Environment_1.sdf -- Simulation environment with contact sensors and autonomous vehicle with lidar sensor.
  2. Environment_2.sdf -- Simulation environment with an actor and autonomous vehicle with lidar sensor.

Reference : https://github.com/gazebosim/docs/blob/master/fortress/tutorials/moving_robot/moving_robot.sdf

It is a 3D world with a differential drive robot.

Running the executable in the ROS2 workspace

  1. Navigate to the ros2_ws in the terminal (ros2 workspace : cd ros2_ws)

  2. execute the command "colcon build" or for particular packages use command : "colcon build --packages-select name-of-pkg"

  3. execute the command : "source install/setup.bash"

  4. If the executable is for a turtlesim node run command : ros2 run turtlesim turtlesim_node

  5. Run the desired file by executing the command : ros2 run "package name" "access name". Access name is the same as the file name without the extension (e.g. .py for python)

Running Gazebo files

  1. For Gazebo Fottress use the command "ign gazebo file_name.sdf"
  2. Establish a bridge between ROS2 ansd Gazebo topic run the command "ros2 run ros_gz_bridge parameter_bridge /cmd_vel@geometry_msgs/msg/Twist]ignition.msgs.Twist"
  3. Establish a bridge for Lidar "ros2 run ros_gz_bridge parameter_bridge /lidar@sensor_msgs/msg/LaserScan[gz.msgs.LaserScan"
  4. Establish a bridge for contact sensor "ros2 run ros_gz_bridge parameter_bridge /wall/touched@std_msgs/msg/Bool[gz.msgs.Boolean"