Stop Ros Program - Code foundation for ROS


please i need help with the right code to stop my program after the robot performs the desired movement. It seems that my program never ends so this affects the grading system. I have spent hours on this but not making any progress. My code is shown below, Thank you.

#! /usr/bin/env python

import rospy
from sensor_msgs.msg import LaserScan
from geometry_msgs.msg import Twist

class RobotMove(object):

def __init__(self):
    #self._topic_name = topic_name
    self._laser_sub = rospy.Subscriber('/kobuki/laser/scan', LaserScan, self.callback)
    self._laser_scan = LaserScan()
    self._cmd_pub = rospy.Publisher('/cmd_vel', Twist, queue_size=1)
    self._twist_move = Twist()
    self.ctrl_c = False

def callback(self, msg):
    self._laser_scan = msg
    return self._laser_scan

def laser_scan_to_twist(self):

    if self._laser_scan.ranges[0]<5:
        self._twist_move.linear.x = 0.2
        self._twist_move.angular.z = 0

    if self._laser_scan.ranges[360]<=1.7:
        self._twist_move.linear.x = 0.0
        self._twist_move.angular.z = -2.5
    if self._laser_scan.ranges[360]>7:
        self._twist_move.linear.x = 0.0
        self._twist_move.angular.z = 0.0


def shutdownhook(self):
    # works better than the rospy.is_shut_down()
    #global ctrl_c
    print "shutdown time!"
    self.ctrl_c = True  

if name == ‘main’:
robotmove_object = RobotMove()
rate = rospy.Rate(2)

def stop(self):
    self._twist_move.linear.x = 0.0
    self._twist_move.angular.z = 0.0

Could you confirm what you ask in Task2?
It appears to me to just make the robot stop at a distance of less than a meter and then rotate 90 degrees.


The grading system doesnt move past so i cant get my result. I was told that the reason is because my program never ends. I need to make my program end after achieving the desired robot movement but i dont know how to. Thank you.

Hi Clistenes,

Please don’t bother with my question, I figured out how to solve the issue so I am now debugging Thank you

1 Like


have good studies

1 Like