You are on page 1of 5

ROS Lab 6

Devakinandan K [21BRS1284]

INSTALLATION:

Install dependent ROS packages:


$ sudo apt-get install ros-noetic-joy ros-
noetic-teleop-twist-joy \
ros-noetic-teleop-twist-keyboard ros-noetic-
laser-proc \
ros-noetic-rgbd-launch ros-noetic-rosserial-
arduino \
ros-noetic-rosserial-python ros-noetic-
rosserial-client \
ros-noetic-rosserial-msgs ros-noetic-amcl
ros-noetic-map-server \
ros-noetic-move-base ros-noetic-urdf ros-
noetic-xacro \
ros-noetic-compressed-image-transport ros-
noetic-rqt* ros-noetic-rviz \
ros-noetic-gmapping ros-noetic-navigation
ros-noetic-interactive-markers
Install TurtleBot3 via Debian Packages.
$ sudo apt install ros-noetic-dynamixel-sdk
$ sudo apt install ros-noetic-turtlebot3-msgs
$ sudo apt install ros-noetic-turtlebot3
Gazebo will open: (burger model)
Simulation part : To move the robot
1. roscore

2. Start gazebo

3. Create a python file inside src : touch script.py


4. Make the changes inside the file:

Code:
#!/usr/bin/env python3
import rospy
from geometry_msgs.msg import Twist
cmd_vel_pub = rospy.Publisher('cmd_vel', Twist,
queue_size=1)
rospy.init_node('red_light_green_light')
rospy.loginfo("started")
red_light_twist = Twist()
green_light_twist = Twist()
green_light_twist.linear.x = 0.5
driving_forward = False
light_change_time = rospy.Time.now()
rate = rospy.Rate(10)
while not rospy.is_shutdown():
if driving_forward:
cmd_vel_pub.publish(green_light_twist)
else:
cmd_vel_pub.publish(red_light_twist)
if light_change_time < rospy.Time.now():
driving_forward = not driving_forward
light_change_time = rospy.Time.now() +
rospy.Duration(3)
rate.sleep()

5. Compile the python file:


Output: Robot moved its position

You might also like