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

2022-11-30 15:40:25 浏览数 (1)

目前已经正式支持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://cloud.tencent.com/developer/article/1387076

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_windows

Tutorial Level: INTERMEDIATE 

目录

  1. Introduction
  2. Generating the ros_lib
    1. Installing rosserial_windows
    2. Generate ros_lib
  3. Add ros_lib to Visual Studio Project
    1. Create a new Win32 Console Application
    2. Copy ros_lib into the project
    3. Add ros_lib to project
  4. Add code to main for Hello World
  5. Start ROS and rosserial_server
  6. Run the app
  7. 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:

  1. From the ROS based system, generate the ros_lib code
  2. Drop the ros_lib code into a Visual Studios Solution
  3. Write code to use ros_lib to connect to the ROS master and send/receive messages
  4. Run rosserial_server socket on ROS master
  5. 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:

代码语言:javascript复制
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.

代码语言:javascript复制
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

  1. Open Visual Studio
  2. File -> New Project
  3. Find the Win32 Console Application under Installed -> Templates -> Visual C -> Win32
  4. Give your project a name. We'll use rosserial_hello_world
  5. 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
代码语言:txt复制
    - ... all of the rosserial generated code, including folders for all of the message packages
- rosserial_hello_world/      
    -  [ReadMe](http://wiki.ros.org/ReadMe).txt
代码语言: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:

  1. Right-click on the rosserial_hello_world project in the Solution Explorer and go to Properties
  2. 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.

切换行号显示

代码语言:javascript复制
   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 %sn", ros_master);
  18   nh.initNode (ros_master);
  19 
  20   printf ("Advertising cmd_vel messagen");
  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!n");
  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!n");
  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:

代码语言:javascript复制
roscore

In a separate terminal, start the rosserial server

代码语言:javascript复制
rosrun rosserial_server socket_node

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

代码语言:javascript复制
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:

代码语言:javascript复制
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.

代码语言:javascript复制
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_windows

Keywords: rosserial, windows, rosserial_windows

Tutorial Level: INTERMEDIATE 

目录

  1. Introduction
  2. Using a Callback Function
  3. Receiving Messages
  4. Example
  5. Running it all together
  6. 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.

切换行号显示

代码语言:javascript复制
   1 void estimated_pose_callback (const geometry_msgs::PoseWithCovarianceStamped & pose)
   2 {
   3   printf ("Received pose %f, %f, %fn", 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:

切换行号显示

代码语言:javascript复制
   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:

切换行号显示

代码语言:javascript复制
   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.

切换行号显示

代码语言:javascript复制
   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, %fn", 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 %sn", 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 messagesn");
  29   while (1)
  30   {
  31     nh.spinOnce ();
  32     Sleep (100);
  33   }
  34 
  35   printf ("All done!n");
  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:

代码语言:javascript复制
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:

代码语言:javascript复制
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.

0 人点赞