編碼的世界 / 優質文選 / 財富

windows系統下安裝和使用ROS的解決方案 2019年4月更新(1 win_ros 2 rosserial_windows)


2021年10月21日
-   

目前已經正式支持ROS1和ROS2:https://microsoft.github.io/Win-RoS-Landing-Page/#

https://microsoft.github.io/Win-RoS-Landing-Page/#
適用於Windows的ROS 人們一直對機器人著迷。今天,先進的機器人正在改變我們的生活,無論是在工作還是在家裏。倉庫機器人已經為在線購物者提供了次日送貨服務,許多寵物主人依靠機器人真空吸塵器來保持地板清潔。制造業,運輸業,醫療保健業和房地產業等多種行業都從機器人中受益。隨著機器人的發展,開發工具也越來越先進。許多開發人員利用機器人操作系統(ROS),這是一套幫助您構建複雜機器人的庫和工具。ROS被用於世界各地的許多尖端機器人項目中。
微軟很高興宣布推出適用於Windows的ROS1實驗版。這將使Windows 10 IoT Enterprise的可管理性和安全性進入創新的ROS生態系統。
幾十年來,Windows一直是機器人和工業系統的可靠部分。借助ROS for Windows,開發人員將能夠使用熟悉的Visual Studio工具集以及豐富的AI和雲功能。我們期待通過向家庭,教育,商業和工業機器人展示硬件加速Windows機器學習,計算機視覺,Azure認知服務,Azure物聯網雲服務和其他Microsoft技術等高級功能,為機器人技術帶來智能優勢。制造商希望讓機器人更加了解周圍環境,更容易編程,更安全。世界各地的政府,制造商和學術界正在投資下一代制造業,有時也被稱為“工業4.0”。
微軟正與Open Robotics和ROS Industrial Consortium合作,將機器人操作系統引入Windows。微軟已加入ROS工業聯盟,其使命是將ROS的先進功能擴展到制造,並提高工業機器人的生產力和投資回報。在西班牙馬德裏的ROSCon 2018上,微軟展示了一台Robotis Turtlebot 3機器人,它運行著名為Melodic Morenia的ROS版本,它識別並引導著最接近機器人的人。該機器人使用新的ROS節點在Intel Coffee Lake NUC上運行Windows 10 IoT Enterprise,該節點利用硬件加速的Windows機器學習。微軟還展示了在Azure中運行的ROS仿真環境。它展示了一群在虛擬世界中運行的機器人,這些機器人連接到編排系統並通過Azure IoT Hub進行控制。Microsoft將為ROS1和ROS2提供Windows構建版本,並為Windows提供文檔,開發和部署解決方案。
Windows上的ROS是實驗性的。我們的目標是2018年底的核心移植工作。
在Windows上使用ROS
  • 在Windows上安裝ROS
  • 你是ROS新手嗎?
  • 了解Windows上的ROS與Linux上的ROS之間的差異
  • 移植狀態
  • 幫助和疑難解答
  • Turtlebot3入門(更新:Gazebo + Cartographer示例已添加)
  • Moveit入門!和UR3
  • 在Windows上與ROS持續集成
  • 關於Windows上的Azure DevOps buildfarm for ROS
  • 從Source中為Windows建立ROS

  • 在Azure中使用ROS
  • Azure IoT Hub的ROS

  • Windows安裝ROS參考:https://blog.csdn.net/ZhangRelay/article/details/82928141
    ROS支持,是微軟物聯網的一部分。這裏有兩個非常重要網站:
    1. 文檔:https://ms-iot.github.io/ROSOnWindows/
    2. 源碼:https://github.com/ms-iot/ROSOnWindows
    翻譯
    Windows與ROS簡介人類一直對機器人充滿興趣。今天,無論是在工作還是在家中,先進的機器人技術正在逐漸改變我們的生活。倉儲物流機器人已經能夠具備為在線購物者提供第二天交付的能力,許多寵物主人依靠機器人真空吸塵器來保持地板清潔。制造業、運輸業、醫療保健業和房地產業等多種行業都從機器人技術中受益。隨著機器人的發展,開發工具也越來越先進。許多開發人員利用機器人操作系統(ROS),這是一套幫助開發人員構建複雜機器人軟件的庫和工具。ROS被用於世界各地的許多尖端機器人項目中。
    微軟很高興宣布推出適用於Windows的ROS1實驗版(注,ROS2也全面支持Windows系統)。這將Windows 10 IoT Enterprise的可管理性和安全性帶入創新的ROS生態系統。
    幾十年來,Windows一直是機器人和工業系統可靠的軟件模塊。借助ROS for Windows,開發人員將能夠使用熟悉的Visual Studio工具集以及豐富的AI(人工智能)和雲功能。我們期待通過向家庭、教育、商業和工業機器人展示硬件加速Windows機器學習、計算機視覺、Azure認知服務、Azure物聯網雲服務和其他Microsoft技術等高級功能,為機器人技術帶來智能優勢。制造商希望讓機器人更加了解周圍環境,更容易編程,更安全。世界各地的政府,制造商和學術界正在投資下一代制造業,有時也被稱為“工業4.0”。
    微軟正與Open RoboticsROS Industrial Consortium合作,將機器人操作系統(ROS)引入Windows。微軟已加入ROS工業聯盟,其使命是將ROS的先進功能擴展到制造,並提高工業機器人的生產力和投資回報。在西班牙馬德裏的ROSCon 2018上,微軟展示了一台Robotis Turtlebot 3機器人,它運行著名為Melodic Morenia的ROS版本,識別並引導著最接近機器人的人。該機器人運行新版的Windows 10 IoT Enterprise在Intel Coffee Lake NUC上使用ROS節點,該節點利用硬件加速Windows機器學習。微軟還展示了在Azure中運行的ROS模擬環境。它展示了一群在虛擬世界中運行的機器人,這些機器人連接到編排系統並通過Azure IoT Hub進行控制。Microsoft將為ROS1和ROS2提供Windows構建版本,並為Windows提供文檔,開發和部署解決方案。 Windows上的ROS是實驗性的。我們的目標是2018年底的核心移植工作。在Windows上使用ROS
    • 在Windows上安裝ROS
    • 你是ROS新手嗎?入門看這裏
    • 了解Windows上的ROS與Linux上的ROS之間的差異
    • 移植狀態
    • 幫助和疑難解答
    • Turtlebot3入門
    • Moveit!和UR3入門
    • 關於Windows上的Azure DevOps buildfarm for ROS
    • 在Windows編譯ROS源碼

    在Azure中使用ROS
    • Azure IoT Hub中的ROS

     
    具體請參考官網:
    1  http://wiki.ros.org/win_ros
    2  https://github.com/ros-windows/win_ros
    3  http://wiki.ros.org/rosserial_windows
    4  http://wiki.ros.org/rosserial_windows/Tutorials
    Hello World from Windows
    Description: How to publish information to a ROS master from windows using rosserial_windows.Keywords: rosserial, windows, rosserial_windowsTutorial Level: INTERMEDIATE   
     
     
    目錄
  • Introduction
  • Generating the ros_lib
  • Installing rosserial_windows
  • Generate ros_libI
  • L
  • Add ros_lib to Visual Studio Project
  • Create a new Win32 Console Application
  • Copy ros_lib into the project
  • Add ros_lib to projectI
  • L
  • Add code to main for Hello World
  • Start ROS and rosserial_server
  • Run the app
  • Robot Doughnuts

  •  
     
     
    Introduction
     
    Windows machines can do all kinds of thing that are difficult to do in other environments: interface an MYO, displays for end users, and working with Windows-only software. Working with a ROS master from Windows can be difficult. The rosserial_windows package makes it much easier to send and receive ROS messages from Windows. This package generates all of the coded needed to drop into a Visual Studios Solution. The workflow is generally:
  • From the ROS based system, generate the ros_lib code
  • Drop the ros_lib code into a Visual Studios Solution
  • Write code to use ros_lib to connect to the ROS master and send/receive messages
  • Run rosserial_server socket on ROS master
  • Compile and run Windows app

  • This tutorial will guide you through those steps to be up and running with your own project.
     
    Generating the ros_lib
     
     
    Installing rosserial_windows
     
    Install rosserial_windows and the rosserial server:
    sudo apt-get install ros-hydro-rosserial-windows
    sudo apt-get install ros-hydro-rosserial-server

     
     
    Generate ros_lib
     
    This step will generate the code that will be needed in the Visual Studio project to talk to the ROS master. You will need to supply the name of the folder into which to copy the finished files.
     
    rosrun rosserial_windows make_libraries.py my_library

     
    This will place the ros_lib folder in the folder my_library.
     
    Add ros_lib to Visual Studio Project
     
    NB: This tutorial assumes Visual Studio 2013 Express Desktop.
     
    Create a new Win32 Console Application
     
  • Open Visual Studio
  • File -> New Project
  • Find the Win32 Console Application under Installed -> Templates -> Visual C++ -> Win32
  • Give your project a name. We'll use rosserial_hello_world
  • You will probably want to turn off precompile headers. The project should work with them enabled, but precompiled headers have caused problems in the past.

  •  
    Copy ros_lib into the project
     
    Copy the ros_lib folder into the rosserial_hello_world project folder. The folder structure should look like:
    • rosserial_hello_world/
      • ipch/
      • ros_lib/
        • ros.h
        • WindowsSocket.cpp
        • all of the rosserial generated code, including folders for all of the message packages
      • rosserial_hello_world/
        • ReadMe.txt
        • rosserial_hello_world.cpp
        • rosserial_hello_world.vcxproj
        • rosserial_hello_world.vcxproj.filters
        • stdafx.cpp
        • stdafx.h
        • targetver.h
      • rosserial_hello_world.opensdf
      • rosserial_hello_world.sdf
      • rosserial_hello_world.sln
      • rosserial_hello_world.v12.suo

     
    Add ros_lib to project
     
    Add all of the files in the ros_lib folder that aren't in subfolders to your project. As of writing this, those are:
    • ros.h
    • duration.cpp
    • time.cpp
    • WindowsSocket.h
    • WindowsSocket.cpp

    Then add the ros_lib folder to your includes path by:
  • Right-click on the rosserial_hello_world project in the Solution Explorer and go to Properties
  • Under C/C++, add "../ros_lib" to the Additional Include Directories property

  •  
    Add code to main for Hello World
     
    Since we're commanding a robot, why not send a command instead of just a string? Here we'll send the cmd_vel message to command a robot to go forward and spin around. You'll need to change the IP address to match the address of your ROS master.
     
    切換行號顯示
     1 // rosserial_hello_world.cpp : Example of sending command velocities from Windows using rosserial
    2 //
    3 #include "stdafx.h"
    4 #include <string>
    5 #include <stdio.h>
    6 #include "ros.h"
    7 #include <geometry_msgs/Twist.h>
    8 #include <windows.h>
    9
    10 using std::string;
    11
    12 int _tmain (int argc, _TCHAR * argv[])
    13 {
    14 ros::NodeHandle nh;
    15 char *ros_master = "1.2.3.4";
    16
    17 printf ("Connecting to server at %s
    ", ros_master);
    18 nh.initNode (ros_master);
    19
    20 printf ("Advertising cmd_vel message
    ");
    21 geometry_msgs::Twist twist_msg;
    22 ros::Publisher cmd_vel_pub ("cmd_vel", &twist_msg);
    23 nh.advertise (cmd_vel_pub);
    24
    25 printf ("Go robot go!
    ");
    26 while (1)
    27 {
    28 twist_msg.linear.x = 5.1;
    29 twist_msg.linear.y = 0;
    30 twist_msg.linear.z = 0;
    31 twist_msg.angular.x = 0;
    32 twist_msg.angular.y = 0;
    33 twist_msg.angular.z = -1.8;
    34 cmd_vel_pub.publish (&twist_msg);
    35
    36 nh.spinOnce ();
    37 Sleep (100);
    38 }
    39
    40 printf ("All done!
    ");
    41 return 0;
    42 }

     
    A few notes on this code:
    • A "node handle" is the equivalent to a ROS node. You'll send everything through that handle
    • Use "init_node" to connect to your ROS master. The format is "hostname:port". The default port is 11411 if none is specified
    • The include files are organized by "package/msg.h" so that they match what you would expect from ROS
    • To publish a message, you first need to make a publisher and then advertise that you're publishing a message
    • finally, you can fill in the message data structure and use the publisher to send it
    • Spin once is used for both receiving messages and for any admin on the port, including keeping your connection alive
    • Beware of a precompile headers. They tend to break building the project.

     
    Start ROS and rosserial_server
     
    In order for rosserial_windows to communicate with the ROS master, a server socket is needed to connect. This tutorial uses a TCP socket, but in theory it is also possible to use a serial port. On the ROS master, start the ROS core:
     
    roscore

     
    In a separate terminal, start the rosserial server
    rosrun rosserial_server socket_node

     
    In a third terminal, use rostopic to see what your app sends
     
    rostopic echo /cmd_vel

     
     
    Run the app
     
    Go back to your windows machine and run the app. You should see command velocities start appearing in the rostopic terminal on your ROS master.
     
    Robot Doughnuts
     
    If you set up a robot simulation in Gazebo, you can then see your robot move based on your commands from Windows. For example, if you follow the ROS 101 Drive a Husky tutorial, you can use this to make the Husky do doughnuts. Here's how to set up that simulation.
    In one terminal, launch the husky simulator in an empty world:
    roslaunch husky_gazebo husky_empty_world.launch

     
    In another terminal, start the rosserial_server with the command velocity topic remapped to where the Husky expects it.
    rosrun rosserial_server socket_node cmd_vel:=/husky/cmd_vel

     
    Now run your app again, and watch the Husky spin around!
    Receiving Messages in rosserial_windows
    Description: An example of receiving messages in rosserial_windowsKeywords: rosserial, windows, rosserial_windowsTutorial Level: INTERMEDIATE   
     
     
    目錄
  • Introduction
  • Using a Callback Function
  • Receiving Messages
  • Example
  • Running it all together
  • Class-based Approach

  •  
     

    Introduction


     
    By now you've learned how to say Hello World with rosserial_windows. But what about if you want to receive a message? This tutorial will guide you through receiving messages in rosserial_windows
     
    Using a Callback Function
     
    Receiving a message is a little more complicated than sending, but only slightly. You'll need to tell the node handle what to do when you receive a message. Specifically, we'll use a callback function that gets called when a message is received.
    Let's say that you want to receive the estimated pose of the robot. Whenever that happens, you'll want to print out the pose. Here's a function that might do that.
     
    切換行號顯示
     1 void estimated_pose_callback (const geometry_msgs::PoseWithCovarianceStamped & pose)
    2 {
    3 printf ("Received pose %f, %f, %f
    ", pose.pose.pose.position.x,
    4 pose.pose.pose.position.y, pose.pose.pose.position.z);
    5 }

     
    That is an example of a callback function. It handles a new pose, in this case by printing to the screen. The next question is how do you get this called when receiving a new message? Assuming that you've already connected to the ROS master and have a NodeHandle called nh, here's how you would do that:
     
    切換行號顯示
     1 ros::Subscriber < geometry_msgs::PoseWithCovarianceStamped >
    2 poseSub ("estimated_pose", &estimated_pose_callback);
    3 nh.subscribe (poseSub);

     
     
    Receiving Messages
     
    Now you have a callback and you've subscribed, but if you don't actually give rosserial a chance to process messages you won't receive anything. Fortunately, we've been doing that all along. That's what this bit of code does:
     
    切換行號顯示
     1 while (1)
    2 {
    3 nh.spinOnce ();
    4 Sleep (100);
    5 }

     
    All this does is give rosserial a chance to process messages and then sleep for a bit. The sleep is optional, though I don't recommend just calling spinOnce(). If you have other elements that you need to call that block for short periods, put them in this loop. Otherwise, beware that going too long between calling spinOnce() will produce disconnects.
     
    Example
     
    Here's the full example of how to receive messages.
     
    切換行號顯示
     1 #include "stdafx.h"
    2 #include <string>
    3 #include <stdio.h>
    4 #include "ros.h"
    5 #include <geometry_msgs/PoseWithCovarianceStamped.h>
    6 #include <windows.h>
    7
    8 using std::string;
    9
    10 void estimated_pose_callback (const geometry_msgs::PoseWithCovarianceStamped & pose)
    11 {
    12 printf ("Received pose %f, %f, %f
    ", pose.pose.pose.position.x,
    13 pose.pose.pose.position.y, pose.pose.pose.position.z);
    14 }
    15
    16 int _tmain (int argc, _TCHAR * argv[])
    17 {
    18 ros::NodeHandle nh;
    19 char *ros_master = "1.2.3.4";
    20
    21 printf ("Connecting to server at %s
    ", ros_master);
    22 nh.initNode (ros_master);
    23
    24 ros::Subscriber < geometry_msgs::PoseWithCovarianceStamped >
    25 poseSub ("estimated_pose", &estimated_pose_callback);
    26 nh.subscribe (poseSub);
    27
    28 printf ("Waiting to receive messages
    ");
    29 while (1)
    30 {
    31 nh.spinOnce ();
    32 Sleep (100);
    33 }
    34
    35 printf ("All done!
    ");
    36 return 0;
    37 }

     
     
    Running it all together
     
    Again, assuming the Husky/Gazebo simulation from ROS 101 Drive a Husky, here's how to receive the pose from odometry:
    In one terminal, launch the husky simulator in an empty world:
    roslaunch husky_gazebo husky_empty_world.launch

     
    In another terminal, start the rosserial_server with the estimated_pose topic remapped to the odometry result from robot EKF:
    rosrun rosserial_server socket_node estimated_pose:=/robot_pose_ekf/odom

     
    Now run the app, and you should be receiving pose messages. If not, check that the mapping is correct, using rostopic if necessary.
     
    Class-based Approach
     
    It's possible to subclass the Subscriber class for a more object-oriented approach. In that case, instead of registering with the call back above simply instantiate the new class and pass that in to the subscribe call.
     
     

    熱門文章