Skip to content

aliy98/roscpp-robot-simulator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

roscpp-robot-simulator

This is a simple rospackage to simulate and control a robot.

Screenshot from 2021-11-15 02-10-46

Installing and runnning

Here is the instruction for using the package:

$ mkdir -p catkin_ws/src
$ cd catkin_ws/src
$ git clone https://github.com/aliy98/roscpp_robot_simulator
$ cd ..
$ source /opt/ros/<distro>/setup.bash
$ catkin_make
$ source devel/setup.bash
$ roscore &
$ rosrun stage_ros stageros $(rospack find second_assignment)/world/my_world.world

in order to run the controller node, open a new terminal in the same directory and run the following commands:

$ source devel/setup.bash
$ rosrun second_assignment controller_node

now robot starts to move in the circuit.

For initializing the command node also, in a new terminal run the following commands:

$ source devel/setup.bash
$ rosrun second_assignment command_node

you can input new values for robot speed between 0 and 2 or reset the robot position.

The rosgraph would look like this: rosgraph

Software Architecture

Slide1

Software architecture in this project is based on two nodes:

  1. Command Node: Gets robot speed or reset position request from user and publishes them on command topic
  2. Controller Node: Subscribes command and base_scan topics and publishes the robot control signal with respect to detected obstacles to cmd_vel topic. It also calls reset_srv to reset robot position if user has requested so.

Pseudocode

***
  controller node:
  
  while(1)
  {
        if reset command is subscribed
        {
              request reset position service
        }

        if there is no obstacle in front of robot
        {
              move robot forward with the user input speed
              if robot is getting close to the obstacle from the left side
              {
                    stop the robot and turn it to the right side
              }

              if robot is getting close to the obstacle from the right side
              {
                    stop the robot and turn it to the left side
              }
        }
        else
        {
              if robot is closer to the obstacle in the left side
              {
                    while there is still obstacle in front of robot
                    {
                          if reset command is subscribed
                          {
                                request reset position service
                          }
                          turn robot to the right
                    }
              }
              else
              {
                    while there is still obstacle in front of robot
                    {
                          if reset command is subscribed
                          {
                                request reset position service
                          }
                          turn robot to the left
                    }
              }
        }
  }

  
***
  command node:
  
  while(1)
  {
        print("enter robot speed or enter "r" to reset robot position:")
        scan("string")
        if("string" == "r") 
              publish reset command
        else
        {
              speed = str2float("string")
              if(0<speed<2) publish speed
              else print("error")
        }
  }

About

A simple rospackage to simulate and control a robot.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published