In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article is about how Python drives the AI robot. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.
1. If you have not already started the WSL-ROS environment, run the WSL-ROS shortcut from the Windows start menu. This opens a terminal application and an instance of the Ubuntu terminal. We call this terminal instance Terminal 1.
Start the simulation of TurtleBot3 waffles in an empty world by entering the following command in the terminal:
[TERMINAL 1] $roslaunch turtlebot3_gazebo turtlebot3_empty_world.launch
A balcony simulation window should open, in which you will see a TurtleBot3 waffle
two。 In the new terminal instance, enter the following command:
[TERMINAL 2] $roslaunch turtlebot3_teleop turtlebot3_teleop_key.launch
Summary:
So far, you have started two separate ROS applications using the roslaunch command. Roslaunch is a way to start a ROS project. As you should observe from the example above, we use this command in the following ways:
Roslaunch {package name} {launch file}
This command takes two parameters as input: {package name} is the name of the ROS package that contains the functions we want to perform, and {launch file} is a file in the package that tells ROS exactly what functions in the package we want to start.
3.roscd is a ROS command that allows us to navigate to the directory of any ROS package installed on the system without knowing the path of the package in advance.
Open a new terminal instance (terminal 3) and use the roscd command to navigate to the turtlebot3_teleop package directory on the Linux file system:
4.In TERMINAL 3 enter $cd ~ to go back to your home directory
[TERMINAL 3] $roscd turtlebot3_ Teleop [terminal 3] $pwd [TERMINAL 3] $ls [TERMINAL 3] $ls-F [TERMINAL 3] $cat turtlebot3_teleop_key.launch
The startup file for a package is usually located in the startup folder in the package directory. You should notice that there is a startup folder in the output of the ls command above.
Cd is a Linux command that allows us to change the directory where the terminal is currently located. Use this to navigate to the turtlebot3_teleop package launch folder, and then use ls again to view its contents. In this folder, you will see the turtlebot3_teleop_ key.
Cat is a Linux command that we can use to display the contents of the file in the terminal.
Pkg: the name of the ROS package that contains the features we want to start.
Type: the full name of the script (that is, the ROS node) that we want to execute in this package (including the file extension, if any).
Name: we want to give the ROS node a descriptive name for registering on the ROS network.
Output: where any output of the node will be printed (the output will be printed to the screen of the terminal window, or the output will be printed to the log file).
ROS nodes are executable programs that perform specific robot tasks and operations, such as the remote (or "remote operation") control we saw in the above example.
5. Use the following command to see which nodes are currently active:
[TERMINAL 3] $rosnode list
We can visualize the connections between active nodes by using the rqt_ graphics node in the rqt_ graphics package. We can start this node directly using rosrun (you may get some error messages, but don't worry):
[TERMINAL 3] $rosrun rqt_graph rqt_graph
6. Explore ROS topics and information
We can learn more about the / cmd_-vel topic by using the rostopic ROS command.
In the new terminal instance (Terminal 4), type:
[TERMINAL 4] $rostopic info / cmd_vel
Output of content:
Type: geometry_msgs/Twist Publishers: * / turtlebot3_teleop_keyboard (http://localhost:#####/) Subscribers: * / gazebo (http://localhost:#####/)[TERMINAL 4) $rosmsg info geometry_msgs/Twist
To do this, type Ctrl+C in any processes that are still running (terminals 1, 2, and 3) to close all active terminal processes. Therefore, the relevant Gazebo and rqt_ graphics windows should also be closed.
In a minute or two, you will use Python to create some simple publisher and subscriber nodes and send messages between them. As we learned earlier, the ROS application should be included in the package, so we need to create a package to start creating our own ROS node.
ROS provides a tool to create a new ROS package and ensure that all the basic elements exist: catkin_create_pkg.
When we create and use our own ROS packages, it is important to work in a specific file system location so that ROS can access and build everything appropriately. These spaces are called "Catkin workspaces", and one of them has been created in the WSL-ROS environment: called Catkin_ws.
#! / usr/bin/env python3# A simple ROS publisher node in Pythonimport rospyfrom std_msgs.msg import Stringclass Publisher (): def _ _ init__ (self): self.node_name = "simple_publisher" topic_name = "chatter" self.pub = rospy.Publisher (topic_name, String, queue_size=10) rospy.init_node (self.node_name Anonymous=True) self.rate = rospy.Rate (10) # hz self.ctrl_c = False rospy.on_shutdown (self.shutdownhook) rospy.loginfo (f "The'{self.node_name} 'node is active...") Def shutdownhook (self): print (f "Stopping the'{self.node_name} 'node at: {rospy.get_time ()}") self.ctrl_c = True def main_loop (self): while not self.ctrl_c: publisher_message = f "rospy time is: {rospy.get_time ()}" self.pub.publish (publisher_message) Self.rate.sleep () if _ _ name__ ='_ _ main__': publisher_instance = Publisher () try: publisher_instance.main_loop () except rospy.ROSInterruptException: pass
Thank you for reading! This is the end of the article on "how Python drives the AI robot". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it for more people to see!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.