” 辅导DD2410HT201编程、ROS留学生编程 写作、Python编程Assignment 1: DD2410 HT20-1 Introduction to RoboticsView All PagesAssignment 1Introduction to Robotics (DD2410)Assignment 1: Introduction to ROSIn this course we will be using the Robot Operating System (ROS). ROS is a middleware platformthat provides libraries and tools that help software developers create robot applications. It simplifiesthe integration of different components on the same system and over the network.Why do we use ROS?Very large user communityStandard in many Robotics labs around the world, even in some companiesMany commercially available robots use ROS nowadaysQuan Schedule Courses Programme Groups ServicesKTH Webmail News feed News from your courses, groups and programmes Direct notificationsAssignment 1: DD2410 HT20-1 Introduction to Robotics httpss://canvas.kth.se/courses/20716/pages/assignment-1[2020/9/3 8:49:14]Open source + large community = lots of packages, libraries, and tools availableRobot planning and controlNavigationVisualization toolsHardware drivers and interfacesEtc … 辅导DD2410HT201作业、ROS留学生作业 写作Modularization and abstractionStandardization/structureEasier to collaborate with othersMake roboticists life easierBasic ROS conceptsROS has a great wiki that you can find here . There you can find basically everything about ROS,and it should be the first place you look when you have trouble with ROS. There is also a QA, likeStack Overflow but for ROS, here where you can ask questions and find answers to other peoplesquestions.Since ROS already has a great wiki with tutorials and such, we will only briefly mention the mostbasic concepts here. You can then find more information in the ROS wiki as you please. We think thisis a good way of teaching you ROS, since the most important skill for you in order to master ROS isto be able to Find the information you need quickly in the ROS wiki.Nodes : ROS nodes are executables, processes that perform computation. A node shouldperform a single well-defined task, such as motor control, localization, sensor processing, etc. In atypical system you have many nodes. Each running node is able to exchange information throughtopics and services. A ROS node is written with the use of a ROS client library , such as roscppor rospy . In this course you will write all code in Python so you will be using rospy.Remember to make your Python script executable .Master : The ROS Master is what allows nodes to be able to find each other and exchangemessages, or Invoke services. For a functional ROS system you have to have a ROS masterrunning. To explicitly start the ROS Master you use the command roscore . A ROS Master isimplicitly started when running the command roslaunch , if there is no ROS Master alreadyrunning. We recommend that you always explicitly start the ROS Master, using roscore , such thatyou do not have to restart the whole system when restarting the launch file that started the ROSMaster implicitly.Parameter Server : The Parameter Server allows you to store data as key-value pairs, whichnodes can access. This is especially useful when writing nodes in C++, since it allows you tochange a parameters value without recompiling the node. It also allows other people using yourcode to easier change a parameter value, without going into your code. The Parameter Server ispart of the ROS Master.Messages : Nodes communicate with each other by passing messages. A message is simply adata structure that can be passed between nodes.Topics : Nodes can send out messages by publishing the messages to a topic. Another nodecan then subscribe to the same topic in order to receive the messages. For example, a cameraAssignment 1: DD2410 HT20-1 Introduction to Robotics httpss://canvas.kth.se/courses/20716/pages/assignment-1[2020/9/3 8:49:14]node would publish camera images to some topic, a vision system can then subscribe to thattopic in order to get the images. Topics implement many-to-many relationship, meaning there canbe multiple publishers and subscribers on the same topic. For each topic there can only be onetype of message that is being published. A single node can subscribe and publish to multipledifferent topics.Services : The publish and subscribe model of topics is very flexible, sometimes, however, youwant to be able to Request something and get a response. Services implement a client-serverrelationship. One node here acts as a server and offers the service. Other nodes (or the samenode) acts as clients and can use the service. A service is defined by a pair of messages, therequest message and the response message. A service call is almost like a function call. Youmight have a path planning node that is offering a path planning service. Another node can thencall that path planning service with a starting point and an end point as the request message andwill in return get a response message containing the path from the starting point to the end point.Bags : Bags are a format for recording and playing back ROS message data. They allow you totest your algorithms on data without running the system. This can be especially useful when youare working in places where there is difficult or time consuming to collect new data every time youwant to test a change to your algorithms.Packages : Pieces of software in ROS are bundled together and distributed through packages.They contain source code for nodes, message/service/parameters files, and build and installinstructions.You can (and probably should) Read more about the basic ROS concepts in the ROS wiki.Higher level ROS conceptsHere we will describe some of the higher level ROS concepts. You can (and probably should) readmore about the higher level ROS concepts in the ROS wiki.TFLets first take a step back and look at how to deal with coordinate systems in ROS. A coordinatesystem is defined by a frame of reference. You might for example say that your computer is 50 cmfrom the left edge of your table, and 40 cm from the bottom edge. This coordinate system uses thetables lower left corner as its frame of reference (its origin), but clearly, you could choose anyarbitrary reference frame. Perhaps it would make more sense to locate your laptop with respect to thenorth-east corner of the room you are in. If you then know where the table is in the room, it should betrivial to calculate the position of your laptop in the room — this is exactly what TF does for you. Amore concretely robotics-related application is available in section 1 of https://wiki.ros.org/navigation/Tutorials/RobotSetup/TF . More exact terminology can be found on theROS wikis TF terminology page .In mobile robotics there are three important frames that (almost) always are present when workingwith ROS: the map frame, considered the absolute coordinate system in that it does not changeover time; the odom frame, for odometry frame, whose origin typically is where the robot waspowered on; and the base_link frame, which is the robot frame — in other words, the robot is alwaysAssignment 1: DD2410 HT20-1 Introduction to Robotics httpss://canvas.kth.se/courses/20716/pages/assignment-1[2020/9/3 8:49:14]at the origin of the base_link frame. REP 105 (Links to an external site.) defines these, and alsogives some naming conventions And semantics, as well as some additional common frames.The picture below illustrates the relationship between the three frames mentioned above and someadditional ones. A position x=(x, y, z) or a pose (x, y, z and three rotations about the body axes) canbe expressed in any of the frames. However, one of them is usually more natural than the other. Forexample, your laptop is easier to locate with respect to the table than the room in the example above.In the image below, the location of the landmarks L1 and L2 are easier to express in the map frame,whereas the position of the camera_link is defined with respect to base_link (i.e. relative to the robot.)We can see from the graph that in order to know where the camera is in the map frame we also needto know where the robot is in the odom frame and the relation between the odom frame and the mapframe. This requires a localization system, which estimates the pose of the robot in the map frameand therefore calculates the transform between map and odometry. We will see later how TF allowsus to seamlessly move from frame to frame and thus make it possible to, for example, express thelocation of the landmarks in the base_link frame.Assignment 1: DD2410 HT20-1 Introduction to Robotics httpss://canvas.kth.se/courses/20716/pages/assignment-1[2020/9/3 8:49:14]We recommend you to use the newer TF2 instead of the old TF . However, things such asconverting a quaternion to/from euler has not yet been implemented for the Python API of TF2,therefore you have to use TF in these situations. You can see an example of that here .ActionlibServices are great, however sometimes you want to cancel a request to a service. For example if theservice is taking too much time or if you noticed something in the environment that affects what youwant to do.Assignment 1: DD2410 HT20-1 Introduction to Robotics httpss://canvas.kth.se/courses/20716/pages/assignment-1[2020/9/3 8:49:14]It would also be great if you could get periodical feedback about the request. For example if you havea path planner you might be able to start moving along the path even before the whole path has beencalculated.This is where actionlib comes in. It is like services with the added ability for the client to cancel therequest and for the server to send periodic feedback to the client.Use simple action server and client.VisualizationROS provides tools to visualize your data. They subscribe to your topics and display information.RVizYou can use RViz for general purpose visualization.One of the most important tools in the ROS arsenal is RViz, the robot visualization tool. You can startRViz by running rviz in a terminal. At the top is the toolbar. Typically, you will use the Interact tool;it pans, zooms and pivots the camera in the main 3D view. On the left is the displays panel; for now,you will only have a grid indicating the ground plane. The displays are, as the name suggests, thingsthat are displayed in the main view. On the right is the camera settings panel, for now it can be leftalone. It allows you to do Things like following the robot in third person, 2D map projection, orbiting,and more.RQTYou can use RQT for more specialized analysis. You can show the node graph, TF tree, plot data,publish to topics and call services, show debug messages, and much more. Check it out!ROS cheat sheetYou can find a useful ROS cheat Sheet here . As you can see it is for ROS Indigo, howevereverything seems to be the same for Melodic.When you need help with ROSThere are a lot of nice tutorials and information on the ROS webpage. Always look there first forinformation on ROS/ROS Packages.ROS wikiROS Q/AROS tutorialsThe practical part of the assignmentNow we will start with the practical part of the assignment.What we use in this courseAssignment 1: DD2410 HT20-1 Introduction to Robotics httpss://canvas.kth.se/courses/20716/pages/assignment-1[2020/9/3 8:49:14]Ubuntu 18.04ROS MelodicPythonIf you are interested you can read more here .Everything is installed for you in computer labs:E building: Rd, Orange, Gul, Grn, Brun, Gr, Karmosin, Vit, MagentaD bulding: Spel, SportInsall, source, and create ROS workspaceOwn computer# Install ROS Melodic desktop fullsudo sh -c echo deb https://packages.ros.org/ros/ubuntu $(lsb_release -sc) main /etc/apt/sources.list.d/ros-latest.listsudo apt-key adv –keyserver hkp://keyserver.ubuntu.com:80 –recv-key C1CF6E31E6BADE8868B172B4F42ED6FBAB17C654sudo apt updatesudo apt install ros-melodic-desktop-fullsudo rosdep initrosdep updatesudo apt install python-rosinstall python-rosinstall-generator python-wstool build-essential python-pip python-catkin-tools# Install ROS packages and such for assignment 1sudo apt install ros-melodic-ros-tutorials ros-melodic-turtlebot3 ros-melodic-turtlebot3-simulations rosmelodic-navigationlibspatialindex-dev libqt4-devsudo apt install ros-melodic-rqt ros-melodic-rqt-common-plugins ros-melodic-turtlesimsudo apt install ros-melodic-turtle-tf2 ros-melodic-tf2-tools ros-melodic-tfpip install rtree sklearnSchool computerrosdep updatepip install rtree Sklearncd ~mkdir notmv .nv .nvidia-settings-rc notThe last line fixes an OpenGL problem that students with an old account would otherwise encounter.It is fine if it gives an error and says that the file or folder does not exist.Assignment 1: DD2410 HT20-1 Introduction to Robotics httpss://canvas.kth.se/courses/20716/pages/assignment-1[2020/9/3 8:49:14]For allSource ROS :echo source /opt/ros/melodic/setup.bash ~/.bashrcsource ~/.bashrcCreate a ROS workspace :mkdir -p ~/catkin_ws/srccd ~/catkin_ws/catkin_makeecho source ~/catkin_ws/devel/setup.bash ~/.bashrcsource ~/.bashrcRecommended editorI recommend that you use VS Code with the extensions:ROSPythonOther that you find useful…You can of course just whichever editor you want. Here you can find more information about differentintegrated development environments (IDEs) and how they work with ROS: httpss://wiki.ros.org/IDEs.TutorialsBasic ROS tutorialsIn order for you to get a practical understanding of ROS you should now do the beginner level coreROS tutorials that you can find here .We did 1 above so you can skip that one if you want. Since we are using Python you should thereforedo:3. Creating a ROS Package4. Building a ROS Package12. Writing a Simple Publisher and Subscriber (Python)15. Writing a Simple Service and Client (Python)OPTIONAL tutorialsTo get a deeper understanding, or if you get stuck later on, it might be a good idea to also do:2. Navigating the ROS Filesystem5. Understanding ROS Nodes6. Understanding ROS Topics7. Understanding ROS Services and ParametersAssignment 1: DD2410 HT20-1 Introduction to Robotics httpss://canvas.kth.se/courses/20716/pages/assignment-1[2020/9/3 8:49:14]8. Using rqt_console and roslaunch9. Using rosed to edit files in ROS10. Creating a ROS msg and srv13. Examining the Simple Publisher and Subscriber16. Examining the Simple Service and Client17. Recording and playing back data18. Getting Started with roswtf19. Navigating the ROS wikiIf you want you may also do the intermediate level tutorials and/or the C++ tutorials.TF2 tutorialsThe TF library in ROS is very useful when you are building real systems. Therefore we feel it isimportant that you get to try it out. You should therefore do the TF2 tutorials for Python.You should do at least:1. Introduction to tf21. Writing a tf2 static broadcaster (Python)2. Writing a tf2 broadcaster (Python)3. Writing a tf2 listener (Python)Optional TutorialsTo get a deeper understanding, or if you get stuck later on, it might be a good idea to also do:4. Adding a frame (Python)5. Learning about tf2 and time (Python)6. Time travel with tf2 (Python)1. Quaternion BasicsYou can of course do the other tutorials as well.Actionlib tutorialsActionlib is useful when you have something that you want to function as a service but with theabilities to send intermediate results and cancel the request.An example for when actionlib is useful. Imagine that you have a path following node that provides apath following service. Once another node has made a request on the path following service the pathplanning node will execute the whole path. But what happens if you see something along the wayand want to do something else based on that? Well, if you use a service you cannot do much otherthan wait until the path follower has reached the end of the path. If the path following node insteadhad provided a path following action then the other node would have been able to cancel the requestonce you saw something interesting, and the robot would therefore stop following the path.You should do at least these actionlib tutorials:4. Writing a Simple Action Server using the Execute Callback (Python)Assignment 1: DD2410 HT20-1 Introduction to Robotics httpss://canvas.kth.se/courses/20716/pages/assignment-1[2020/9/3 8:49:14]5. Writing a Simple Action Client (Python)Detailed description of actionlib: httpss://wiki.ros.org/actionlib/DetailedDescriptionMini-projectInsallationcd ~/catkin_ws/wstool init srccd ~/catkin_ws/srcwstool set -y irob_assignment_1 –git httpss://github.com/danielduberg/irob_assignment_1.git -v masterwstool set -y hector_slam –git httpss://github.com/tu-darmstadt-ros-pkg/hector_slam.git -v melodic-develwstool updatecd ~/catkin_ws# This makes sure We compile in release mode (which means that the compiler optimizes the code)catkin_make -DCMAKE_BUILD_TYPE=RelWithDebInfosource ~/.bashrcDescriptionYou will now do a mini-project where you should help a TurtleBot3 robot explore an unknownenvironment. The robot is called Burger and you can see a picture of Burger below.Assignment 1: DD2410 HT20-1 Introduction to Robotics httpss://canvas.kth.se/courses/20716/pages/assignment-1[2020/9/3 8:49:14]Image taken from: https://emanual.robotis.com/docs/en/platform/turtlebot3/specifications/#data-ofturtlebot3-burgerThe ability to perform autonomous exploration is essential for an autonomous system operating inunstructured or unknown environments where it is hard or even impossible to describe theenvironment beforehand.Sysem descriptionAssignment 1: DD2410 HT20-1 Introduction to Robotics httpss://canvas.kth.se/courses/20716/pages/assignment-1[2020/9/3 8:49:14]Luckily for you, you do not have to solve the whole exploration task. Instead you will use anexploration node, based on receding horizon next-best-view (RH-NBV) , that we have preparedfor you. You will also make use of a collision avoidance node, based on the obstacle-restrictionmethod (ORM) and pure pursuit (for smooth control), that ensures safe path following. In orderfor Burger to localize herself/himself you will also run a SLAM node, based on Hector SLAM , whichdoes mapping and localization. We will also make use of a costmap_2d node in order to make theexploration and collision avoidance simpler. Since you are not given a real Burger robot we will dothis in simulation. The simulator we use is called Gazebo and it is a popular simulator whenworking with ROS. Lastly, we will use a robot_state_publisher node to get the necessarytransformations.What you will have to do is create a controller node that is using the exploration node and thecollision avoidance node in order to move Burger around in the environment. This is one of the bestthings about ROS. That you do not have to do everything yourself. Instead you can use what othershave done and simply glue the pieces together to make your desired system work.Lets sartOpen three terminals.In the first terminal you should start the ROS Master:roscoreIn the second terminal You should launch the file simulator.launch inside irob_assignment_1/launch likethis:roslaunch irob_assignment_1 simulator.launchAnd in the third terminal launch the file start.launch inside irob_assignment_1/launch like this:roslaunch irob_assignment_1 start.launchYou will see a window called RViz open:Assignment 1: DD2410 HT20-1 Introduction to Robotics httpss://canvas.kth.se/courses/20716/pages/assignment-1[2020/9/3 8:49:14]In the main view of the RViz window you can see a small Turtlebot3 Burger robot in the middle of thewhite area. The white area of the map is called free space, it is space where the robot knows there isnothing. The large gray area is unknown space, it is space that the robot knowns nothing about. Itcan be either free space or occupied space. Occupied space is the cerise colored space. The cyancolored space is called C-space, it is space that are a distance from the occupied space such that therobot would collied with the occupied space if it would move into it. Take a look at the image below ifyou are interested. You can read more about it here . Your job will be to help Burger explore asmuch of the unknown space as possible.Assignment 1: DD2410 HT20-1 Introduction to Robotics httpss://canvas.kth.se/courses/20716/pages/assignment-1[2020/9/3 8:49:14]Image taken from: httpss://wiki.ros.org/costmap_2dIf you open up RQT :rqtThen in the topbar select Plugins-Introspection-Node Graph and uncheck Leaf topics , you will seesomething like this:Assignment 1: DD2410 HT20-1 Introduction to Robotics httpss://canvas.kth.se/courses/20716/pages/assignment-1[2020/9/3 8:49:14]Here you can see all of the nodes that were started when you ran the roslaunch commands before,and that we talked about previously. There are two nodes of interest for you here. The /explore nodeand the /collision_avoidance node.The /explore node is providing an action server called get_next_goal with the typeirob_assignment_1/GetNextGoalAction . If we take a look at the action definition:# Goal definition—# Result definitionfloat64 gainnav_msgs/Path path—# Feedback definitionfloat64 gainnav_msgs/Path pathWe see that in the request it does not require anything. So when you call this action server, you donot have to supply any arguments. The result you will get from the action server is a gain value anda path . The gain value tells you how valuable the path is. It is often how much new space you willdiscover when moving along the corresponding path.In the feedback you can see that you, once again, get gain and a path . The longer the explorationalgorithm is running the better path — one with higher gain — it will find. However, it is not alwaysworth the time it takes to find the best path. So since you get a path with an associated gain, youmight want to stop the exploration once you get a path with a gain higher than a certain value. Youare not require to do this to pass this assignment, it is optional.Okay, so lets say you have now Called the explore action server and gotten a path. Now you want therobot to move along the path. You also do not want the robot to crash while following the path.Therefore we should now take a look at the collision avoidance node.The collision avoidance node is providing a service called get_setpoint of typeirob_assignment_1/GetSetpoint . If you type:Assignment 1: DD2410 HT20-1 Introduction to Robotics httpss://canvas.kth.se/courses/20716/pages/assignment-1[2020/9/3 8:49:14]rossrv show irob_assignment_1/GetSetpointYou will see the request and response messages:# Define the requestnav_msgs/Path path—# Define the responsegeometry_msgs/PointStamped setpointnav_msgs/Path new_pathYou can see that the service wants a path, which is perfect because that is exactly what you got fromthe exploration action server. In return you will get a setpoint of type geometry_msgs/PointStamped and anew path. You get a new path since the collision avoidance node is removing points along the pathwhich is thinks you have already moved passed. The setpoint is where you should move the robotnext to follow the path in a safe and efficient way.If we take a look at the setpoint message:rosmsg show geometry_msgs/PointStampedWe see:std_msgs/Header headeruint32 seqtime stampstring frame_idgeometry_msgs/Point pointfloat64 xfloat64 yfloat64 zThe header tells you in which frame the point is in. If you print the framerospy.loginfo(The frame is: %s, setpoint.header.frame_id)You will see that the point is specified in the X (where X is the frame you get) frame.Okay, so now you have the point and you know which frame it is in. How do we make the robotmove?If we take a look at the topics list:rostopic listYou should be able to find a topic called /cmd_vel . It sounds interesting, maybe it means commandvelociy? We want more Info about the topic so we write:rostopic info /cmd_velAssignment 1: DD2410 HT20-1 Introduction to Robotics httpss://canvas.kth.se/courses/20716/pages/assignment-1[2020/9/3 8:49:14]And it will output something like:Type: geometry_msgs/TwistPublishers: NoneSubscribers:* /gazebo ( https://X:YYYYY/)Here we see that there is one subscriber to the topic and no publisher. We also see that the messagetype that is communicated over the topic is called geometry_msgs/Twist . We take a look at the messagedefinition:rosmsg show geometry_msgs/TwistAnd we get:geometry_msgs/Vector3 linearfloat64 xfloat64 yfloat64 zgeometry_msgs/Vector3 angularfloat64 xfloat64 yfloat64 zSo the geometry_msgs/Twist message consist of a linear and angular velocity. Burger is a differentialdrive robot. Meaning Burger can only move forward/backward and rotate. To move forward linear.xshould be positive. To move backwards it would be negative. To rotate you change the value ofangular.z, then the robot will be yawing, rotating around the z-axis. Changing linear.y, linear.z,angular.x, and angular.y has no effect on the robot.We can also see that the geometry_msgs/Twist message does not contain a header , therefore thesubscriber to the /cmd_vel topic has no idea in what frame of reference the incoming velocitycommand has. Instead the subscriber assumes that the velocity command is in the robots frame.Take a look at the TF tree by running the command rqt , to start RQT, then in the top bar selectPluings-Visualization-TF Tree :Assignment 1: DD2410 HT20-1 Introduction to Robotics httpss://canvas.kth.se/courses/20716/pages/assignment-1[2020/9/3 8:49:14]The robots frame is often called base_link and it is in this mini-project as well. So this is the frame thesubscriber on the /cmd_vel topic is expecting the velocity command to be specified in. So if thesetpoint you got from the get_setpoint service is not in the base_link frame then you have totransform it using TF2 to base_link .After you have transformed the setpoint to base_link you should now convert the setpoint from ageometry_msgs/PointStamped Message to a geometry_msgs/Twist message and publish it on the /cmd_veltopic. If you did the TF2 tutorial on writing a tf2 listener you should have a good idea about how toconvert the geometry_msgs/PointStamped to a geometry_msgs/Twist . Remember that you should transformthe setpoint, so you cannot do exactly as it says in the TF2 tutorial. It is a good idea to use thefunction:transformed_setpoint = tf2_geometry_msgs.do_transform_point(setpoint, transform)When transforming the setpoint using the transform you got from:transform = tf_buffer.lookup_transform(…)It can be a good idea to limit the linear and angular velocities, otherwise the robot will act strange.These seem to be good values:max_linear_velocity = 0.5Assignment 1: DD2410 HT20-1 Introduction to Robotics httpss://canvas.kth.se/courses/20716/pages/assignment-1[2020/9/3 8:49:14]max_angular_velocity = 1.0But you are free to try other values.Then after that you should again call the get_setpoint with the new_path you got from the service thelast time you called it, and then you do the same thing to transform and publish the new setpoint. Youdo this until the new_path does not contain any poses:while new_path.poses:When that happens you should call the explore action server again to get a new path, and doeverything over again until the action server returns an empty path and/or the gain is 0, meaningthere is nothing new to explore.It can be a good idea to limit the frequency of publishing to /cmd_vel to somewhere between 10 to 20.You can do that using the rospy.Rate(X) and then rate.sleep() as you did in the tutorials.You can do the assignment using two different approaches:Simple approachIf you go into the folder irob_assignment_1/scripts you will see a file called controller.py . Here wehave made a skeleton for the controller node that you should write. So create your controller node inthat file. When you are done you can test your controller by running:rosrun irob_assignment_1 Controller.pyIf your code does not work yet, or you want to restart you simply have to close down your node andstart.launch by going to the terminal where you started start.launch and press CTRL+C . Thereafteryou launch the start.launch again:roslaunch irob_assignment_1 start.launchTogether with your node in a seperate terminal:rosrun irob_assignment_1 controller.pyNote that you do not have to restart roscore or simulator.launch .Pseudocode for the assignment:\”
添加老师微信回复‘’官网 辅导‘’获取专业老师帮助,或点击联系老师1对1在线指导。