← Back to list

This week I learnt — Week 5

This week I learned about:

Trisit Wuttichaikitcharoen · 2025-05-19 16:50 · 0 claps · 4.4 min read
#roses #turtlebot
Open on Medium ↗

This week I learnt — Week 5

This week I learned about:

S.L.A.M and navigation

This week is the first week of term 1!, summer is finally over and I’m still NOT ready!, anywaysss lets get started!!!

NEW STUFF!!!

imu sensor

imu sensor

first of all the good stuff, the picture above is an imu sensor, used to mesure the angular value of its own, very useful for tracking the angle of the turtlebot!

Encoder

Encoder

The encoder is used for tracking the rotation of the wheel, very useful for tracking the distance that the turtlebot has moved!

Lidar sensor

Lidar sensor

LIDAR sensor, shoots laser VERY VERY FAST while spinning the measure the distance of obstacles around it, very useful for the turtlebot to navigate around obstacles on its own!

Thats all the new equipments!

SLAM

stands for Simultaneous Localization and Mapping, we use SLAM to scan the surrounding area of the tbot and saves it in a file as a map to use it for navigation.

“how do we use it?”

fear not cus I’ll teach you!

check if your lidar sensor is working by using the command:

rostopic echo /scan to check the values lidar is giving

if theres no value then : INSTALL THE DRIVERS!!!

now lets pretend that you got it working, lets try making our map with the SLAM command!:

after setting down your tbot at the starting position, make sure to use the command rostopic pub -1 /reset std_msgs/Empty to reset your tbot’s position

roslaunch turtlebot3_slam turtlebot3_slam.launch : to start scanning the surrounding obstacles/walls around the lidar sensor, things should start showing up on the new window that popped up!

just like this!

just like this!

now to start scanning the whole area, we need to control the robot, using our old friend teleoping! open another terminator window and use the command roslaunch turtlebot3_teleop turtlebot3_teleop_key.launch and use the arrow keys to start controlling the tbot and watch as the map reveals itself!, just make sure to not move/spin too fast otherwise the map will start to distort and you need to retry again…

after you’re sure that you are done with the whole entire map, save it by opening another terminator and run the command rosrun map_server map_saver -f ~/map with this command the new map that you have created should be saved to the directory you gave it

now before we start navigating the robot, we should check the config files first, in the file costmap_common_params_burger.yaml you can change two important value:

inflation_radius : just like the name, virtually inflates the wall for the tbot so that the wall will have a thicker width to it, making tbot tries to avoid going near it. so the bigger the number, the futher the tbot will distance itself from the walls

cost_scaling_factor : think of it as how brave the tbot it, the more cost it has, the more brave tbot is, so if the cost is high, the tbot will manuever around the course with speed and tight spots, but if the costs are low, the tbot will try to manuever itself around the tight spots if possible.

NAVIGATION!

after configuring the setting, you can start navigating, using the command roslaunch turtlebot3_navigation turtlebot3_navigation.launch map_file:=$HOME/map.yaml, this will open another new window which will display the map that you previously saved, or whichever the directory you gave it, using the green arrow (2d pose estimate), you can set the starting position if the position was offsetted, this depends on where the tbot was when you use the reset command, and using the purple arrow (2d nav goal), you can place it anywhere on the map and the tbot will manuever around the obstacles with ease!

congrats you learned how to SLAM and NAVIGATE!

now to create a waypoint.py file so that you can run a launch file and let the tbot navigate through all the points you give it!, after running the navigate command, you can open another terminator window and run the command rostopic echo /amcl_pose to read the value of the x,y axis and the x,y,z,w angular value, using these value that update everytime you navigate the tbot, you can document the coordinates of the points you want the tbot to go, and create a python file which commands the tbot to automatically nav to these coordinates you give it. heres an example code

#!/usr/bin/python3

import rospy
import tf.transformations
import actionlib
from move_base_msgs.msg import MoveBaseAction, MoveBaseGoal
from geometry_msgs.msg import Pose, Point, Quaternion
from nav_msgs.msg import Odometry
from actionlib_msgs.msg import GoalStatus

class MoveBaseNavigator:
    def __init__(self):
        rospy.init_node('move_to_goal', anonymous=True)


        self.move_base_client = actionlib.SimpleActionClient('/move_base', MoveBaseAction)
        self.move_base_client.wait_for_server()


        rospy.Subscriber('/odom', Odometry, self.odom_callback)


        self.current_position = None
        self.current_orientation = None

    def odom_callback(self, msg):
        self.current_position = msg.pose.pose.position
        self.current_orientation = self.quaternion_to_euler(msg.pose.pose.orientation)

    def quaternion_to_euler(self, orientation):
        quaternion = (orientation.x, orientation.y, orientation.z, orientation.w)
        return tf.transformations.euler_from_quaternion(quaternion)

    def create_goal(self, x, y, qx, qy, qz, qw):
        goal = MoveBaseGoal()
        goal.target_pose.header.frame_id = 'map'
        goal.target_pose.header.stamp = rospy.Time.now()
        goal.target_pose.pose = Pose(Point(x , y , 0), Quaternion(qx, qy, qz, qw))
        return goal

    def move_to_goal(self, position):
        goal = self.create_goal(*position)
        self.move_base_client.send_goal(goal)

        self.move_base_client.wait_for_result()
        state = self.move_base_client.get_state()

        rospy.loginfo(f"Moving to ({goal.target_pose.pose.position.x}, {goal.target_pose.pose.position.y})")

        if state == GoalStatus.SUCCEEDED:
            rospy.loginfo("Reached Goal Successfully!")
            return True
        else:
            rospy.logwarn("Failed to reach goal")
            self.move_base_client.cancel_goal()
            return False

def main():
    navigator = MoveBaseNavigator()

    waypoints = {
    "p1": (0.2, 0.5, 0.0, 0.0, 0.00, 1.00),
    "p2": (-0.4, 0.5, 0.0, 0.0, 0.69, 0.71),
    "p3": (0.4, -0.5, 0.0, 0.0, -0.04, 0.99)}

    # for name, pos in waypoints.items():
    #     print(f"Moving to: {name}")
    #     navigator.move_to_goal(pos)
    navigator.move_to_goal(waypoints["p1"])
    navigator.move_to_goal(waypoints["p3"])

    rospy.loginfo("Mission completed. Shutting down.")
    rospy.signal_shutdown("Navigation complete")

if __name__ == '__main__':
    try:
        main()
    except rospy.ROSInterruptException:
        pass

try to find p1,p2,p3 those are the coordinates you can give them and the tbot should run to them!, oh yeah right,

to run this file i reccomend to make a launch file to make things easier if you make even more python files, and run the launch file using the command roslaunch [topic] [launch file] and the tbot should run on its own yayyyY!Y!Y!Y!!!!!!

goodnight.


메타데이터
post_id
b7b9f29201d5
slug
this-week-i-learnt-week-5-b7b9f29201d5
url
https://medium.com/@trisitink/this-week-i-learnt-week-5-b7b9f29201d5
canonical_url
https://medium.com/@trisitink/this-week-i-learnt-week-5-b7b9f29201d5
author_url
https://medium.com/@trisitink
status
ok
fetched_at
2026-06-21 21:05:38