Ros bridge terminates during the execution

Hello. I am trying to run my ROS project on a real robot. It works perfectly fine in the simulation. When I start the real robot, it runs for a few seconds, and then the ros bridge terminates due to user request (I did not request it). The problem happens when FSM is in state S3.

[ WARN] [1688656949.763434363]: Shutdown request received.
[ WARN] [1688656949.974102462]: Reason given for shutdown: [user request]

I do not understand whether the problem is in my code or on the server. What can I do about it?

My code is:

import rclpy
# import the ROS2 python libraries
from rclpy.node import Node
# import the Twist module from geometry_msgs interface
from geometry_msgs.msg import Twist
# import the LaserScan module from sensor_msgs interface
from sensor_msgs.msg import LaserScan
from rclpy.qos import ReliabilityPolicy, QoSProfile
import time

class Wall_following(Node):

    def __init__(self):
        # Here you have the class constructor
        # call the class constructor
        super().__init__('wall_following')
        # create the publisher object
        self.publisher_ = self.create_publisher(Twist, 'cmd_vel', 10)
        # create the subscriber object
        self.subscriber = self.create_subscription(LaserScan, '/scan', self.laser_callback, QoSProfile(depth=10, reliability=ReliabilityPolicy.RELIABLE))
        # define the timer period for 0.5 seconds
        self.timer_period = 0.5
        # define the variable to save the received info
        self.laser_data = []
        # create a Twist message
        self.cmd = Twist()
        self.timer = self.create_timer(self.timer_period, self.motion)
        self.state = "S0"

        self.linear_velocity_value = 0.3
        self.rotational_velocity_value = 0.3

        self.linear_velocity = 0
        self.rotational_velocity = 0

    def laser_callback(self,msg):
        # Save the frontal laser scan info at 0°
        self.laser_data = msg.ranges
        
        
    def motion(self):
        while(self.laser_data == []):
            time.sleep(0.1)
            self.get_logger().info("Waiting for laser data")

        laser_forward = self.laser_data[350]
        laser_right = self.laser_data[270]

        # print the data
        self.get_logger().info("Forward distance: " + str(laser_forward) + " Right distance: " + str(laser_right))
        
        if(laser_forward < 0.5):
            self.state = "S3"
        elif(laser_right > 0.3):
            self.state = "S2"
        elif(laser_right < 0.2):
            self.state = "S1"
        else:
            self.state = "S0"


        if self.state == "S0":
            self.state_S0()
        elif self.state == "S1":
            self.state_S1()
        elif self.state == "S2":
            self.state_S2()
        elif self.state == "S3":
            self.state_S3()
        else:
            self.get_logger().info("FSM is broken")

        self.cmd.linear.x = self.linear_velocity
        self.cmd.angular.z = self.rotational_velocity
            
        # Publishing the cmd_vel values to a Topic
        self.publisher_.publish(self.cmd)

    #S0- go straight
    def state_S0(self):
        self.linear_velocity = self.linear_velocity_value
        self.rotational_velocity = 0.0
        self.get_logger().info("S0")

    #S1- slight left turn
    def state_S1(self):
        self.linear_velocity = self.linear_velocity_value
        self.rotational_velocity = self.rotational_velocity_value
        self.get_logger().info("S1")

    #S2- slight right turn
    def state_S2(self):
        self.linear_velocity = self.linear_velocity_value
        self.rotational_velocity = -self.rotational_velocity_value
        self.get_logger().info("S2")

    #S3- sharp left turn
    def state_S3(self):
        self.linear_velocity = 0.0
        self.rotational_velocity = self.rotational_velocity_value
        self.get_logger().info("S3")


            
def main(args=None):
    # initialize the ROS communication
    rclpy.init(args=args)
    # declare the node constructor
    wall_following = Wall_following()       
    # pause the program execution, waits for a request to kill the node (ctrl+c)
    rclpy.spin(wall_following)
    # Explicity destroy the node
    wall_following.destroy_node()
    # shutdown the ROS communication
    rclpy.shutdown()

if __name__ == '__main__':
    main()

Hi @Ipogorelov ,

What type of bridge are you using? dynamic_bridge or parameter_bridge?
Can you post the bridge activation command?

Regards,
Girish

I was following the manual for ros2 basics in 5 days (python) rosject.

I actually found a solution myself.

At the very end of the manual, it says that the bridge terminates when the linear speed of the robot is more than 0.19. I was using 0.3.

I wish the instructions were in consecutive order, and not as messy as they are now.

1 Like

@Ipogorelov Thank you for the feedback. I have included it in the list of things to improve about the project.

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.