,

Turtlebot and irritated Robot Simulation in ROS | ROS Noetic Tutorial 7

Turtle Bot and Irritated Robot 

If the robot encounters an obstacle at a threshold distance of 0.5, then the robot engages in a twisted or circular motion. The robot moves forward at a nominal speed if there is no obstacleYou can make use of Burger as the Turtlebot model


Exercise 2: From the above example, make the irritated robot into a diplomat robot where the robot moves away from the obstacle and moves forward with a nominal speed. 


SOURCE CODE:

#!/usr/bin/python3


import rospy

import numpy as np

from numpy import inf

from geometry_msgs.msg import Twist

from sensor_msgs.msg import LaserScan

import sys

import random


class object_irritation_robot: 

    def __init__(self):

        rospy.Subscriber("/scan", LaserScan, self.laserData_cb)

        self.pub = rospy.Publisher('/cmd_vel', Twist, queue_size=10)

        self.robot_velocity=Twist()


    def laserData_cb(self,data):

        laser_data=np.array(data.ranges)

        laser_data[laser_data == inf] = 0

        laser_data=max(laser_data)

        rospy.loginfo(laser_data)


        if(laser_data > 0.5):

            self.escape()

        else : 

            self.move_forward()

        self.pub.publish(self.robot_velocity)

    

    def move_forward(self):

        rospy.loginfo("Lets Move ON ")

        self.robot_velocity.linear.x=0.5

        self.robot_velocity.angular.z=0.0


    def escape(self):

        rospy.loginfo("Lets get out")

        self.robot_velocity.linear.x  = -1

        self.robot_velocity.angular.z = 1


if __name__ == '__main__':

    rospy.init_node('object_irritation_robot', anonymous=True)

    object_irritation_robot()

    rospy.spin()


Irritated Robot
Irritated Robot


Turtle bot
Turtle bot


0 comments:

Post a Comment