Skip to content

Controlling Turtlebot using Ultrasonic sensor

Sakshi Kakde edited this page Dec 9, 2017 · 8 revisions

A script is written such that if the distance of the object from ultrasonic sensor is less than 10 cm,the the Turtlebot will move forward.Following wiki consists of the steps to achieve this. Follow the previous wiki to integrating ROS and arduino and publish HC-SR04 ultrasonic sensor data on a rostopic.

Writing a test script for Turtlebot and ultrasonic sensor

Follow Turtlebot tutorial:http://learn.turtlebot.com/2015/02/01/10/
The example goforward.py has been used as refrence.

Subscribing to rostopic where data from sensor is published

If your followed the previous wiki,then the sensor data is used to calculate distance and is being published on topic 'chatter' with message type 'Float64'.Hence,the node must subscribe to the topic 'chatter'.

Publish velocities to move Turtlebot

The velocity(linear and angular) is published on topic 'cmd_vel_mux/input/navi' with message type as 'Twist'.Twist is a ROS message type in geometry_msgs.geometry_msgs provides messages for common geometric primitives such as points, vectors, and poses.For more details,refer:http://wiki.ros.org/geometry_msgs
As our robot works in 2D space,hence we are concerned with linear.x and angular.z velocities only.
The code can be download from:https://github.com/surabhi96/libbot
The code is such that id the distance measured id less than 10 cm,then the robot move forward.
To run the script from terminal,move to the location where the file exists and run command 'python move.py'

Note:the code is to understand the concepts and test the working.

Move the Turtlebot parallel to the wall using PID

Proportional controller

algorithm

The reference distance is set.The error is calculated based on the reference and measured distance.The value of kp is set as 0.1 and the angular velocity is calculated as kp*error. Download the code from:https://github.com/surabhi96/libbot/tree/Turtlebot

Observations

The error starts accumulating and the robot maloperates.The graph of angular velocity vs time is as seen from:
https://github.com/surabhi96/libbot/blob/Turtlebot/graphs/kp_0.1.png

Clone this wiki locally