Recently learned the Ros robot system, we all know that Ros is based on the Linux platform, of course, if the application of Ros to Windows, Android, IOS, WP system can also be downloaded as long as the corresponding ROS development package is OK, but the configuration of these environments is a very painful thing, Because there are many versions of Ros, not every version has a corresponding platform for the development package, the Android environment configuration is relatively simple, such as iOS, the closed system is more difficult. So I practiced a relatively simple way to make it easy to access the ROS internal network without having to configure the Ros development environment on a variety of platforms. But before entering the topic still have to explain some background, below is pure rookie understanding, please Daniel more criticism guide ~ ~ ~
I. What is the ROS robotic system?
Ros is open source, a post-operating system used for robotics, or a secondary operating system. It provides features similar to the operating system, including hardware abstraction, underlying driver management, execution of shared functions, inter-Program messaging, program release package management, as well as tools and libraries for acquiring, building, writing, and running multi-machine integration programs.
The amount ... Very senior difficult to understand the appearance ~ as I use non-professional grassroots language description: A variety of EXE communication bridge. Maybe just starting to learn Ros, including me, children's shoes will be a little too deified ros system, feel that Ros is omnipotent, anything can do. In fact, I think Ros is just a tool, for a project using Ros, the focus is not on the use of Ros, but how to use the algorithm to process the information obtained from the Ros. In other words, math. Most of the high-level stuff is finally doing math. Stop it! I said a lot of nonsense again ...
Second, the core framework of ROS robot system.
The core framework has three principals: Node Manager, publisher, and Subscriber. The Node Manager is primarily responsible for registering information for various nodes and as a guide for communicating between them. Both the Publisher and the Subscriber are a single node and must be registered with the Node manager. Publishers do not have a coupling relationship with the subscribers themselves, and they do not know the existence of the parties until the connection is established. When a subscriber wants to subscribe to a topic, the node Manager will look for a node to publish the topic, if found, the node Manager will associate the publisher and Subscribers, after which they send and receive information is not through the Node manager, but directly to the communication.
The amount ... Or is it a little hard to understand? I am a layman, with a more vulgar way to explain the above picture is what the meaning of it ~ ~ ~
Anyway, I have never been to these sites, but I probably guess their basic flow, that is, a man and a woman to the marriage must be on those sites to register an account, and then left their basic information, the century good edge to help them pull the line, and finally, the men and women all kinds of chat, all kinds of dating will not be mediated, That's probably what it means. It is easy to understand the meaning of the comparison with one by one.
III. communication mechanism of ROS nodes
In fact, the various nodes of the ROS internal network communication can be said to be based on TCP/IP communication, as long as the node Manager registration, you can communicate with the various nodes. This means of communication enables ROS nodes on different hosts to communicate effectively.
So the problem is, if the node is not under the Linux platform, how to access the internal ROS network, access to internal information? As mentioned earlier, for different platforms, Ros provides the corresponding development package.
Android platform: Http://wiki.ros.org/android Cons: Not supported for all Android versions.
Windows platform: Http://wiki.ros.org/win_ros disadvantage: Only support desktop platform, does not support the WP platform. The latest development kit is only available for older Ros systems: Fuerte\groovy\hydro, Indigo version not supported.
iOS platform: Https://github.com/introlab/ros_for_ios disadvantage: Not all Apple versions are supported, the data is relatively small.
In view of the above limitations, I propose a very simple way to access the ROS internal network to access the information inside. This approach is not necessary to configure the ROS environment on other platforms, as long as the TCP/IP communication can be done, this requirement is too low. The following first talk about the principle of implementation, in fact, the principle of implementation is very simple, is to do a TCP sever agent node in Ros, external programs can be accessed through this proxy node to the ROS internal network, Ah, too simple, the earth can think of the Method!!! Come here, Daniel can close the window, the following is the process of slag slag implementation, no need to read.
Iv. Process of realization
Before the presentation, let's start by talking about my entire development environment:
System: Ubuntu 14.04 LTS
Ros Version: Indigo
If you are the same as my environment, just follow me one step at a to be sure, because I transplanted a lot of computers.
1, install QT.
Since it is necessary to do a proxy server node of course to consider what to do, Qt is a very good choice, Indigo has its own qt4.8.x dynamic library (Forget), note that this is a dynamic library, not a development library, is not compiled QT program, so we need to install a QT development library, I chose qt4.8.6, personally think, QT5 is not necessary, feeling and indigo is not very compatible. QT in Linux as if to build their own installation, so in order to save everyone's time, directly with my compiled on the line:
Https://yunpan.cn/cBnxHN8RCu9CG Access Password ffb0
(1) Enter the following command to extract the compressed package I provided to the specified path:
SU # get root privileges Unzip trolltech.zip-d/usr/local
(2) Add environment variables, edit ~/.BASHRC, add the following environment variables:
Qtdir=/usr/local/trolltech/qt-4.8.6path= $QTDIR/bin: $PATHMANPATH = $QTDIR/doc/man: $MANPATHLD _library_path= $QTDIR/ Lib: $LD _library_pathexport qtdir PATH MANPATH Ld_library_path
2, you can start to write QT program.
To write the Ros version of the QT program needs the ROS Development Kit to cooperate, download: Https://yunpan.cn/cBn8TNx6DvpEv access password 0459
Above is my own modified, if you want to see the official version can be downloaded here: Http://wiki.ros.org/qt_ros
Download down the decompression, we just touch/qt_ws/src/qt_tutorials inside of the things on the line, there are two demo, one is Android, another is TCPServer, as long as the imitation of the two demo to programming on the line, With normal QT programming is no different, just add a bit of Ros things. As this article is not mainly about QT and Ros programming, so do not detail this part of the content, there is a chance to stay in the next article to say. Here's the main code:
Talker.hpp
#ifndef Talker_node_hpp_#define talker_node_hpp_/*************************************************************** includes*****************************************************************************/#ifndef Q _moc_run#include <ros/ros.h> #include ". /COMMON/QNODE.HPP "#endif # include <string>/*************************************************************** Class*****************************************************************************/class Tcpserver;class talker:public Qnode {q_objectpublic:talker (int argc, char** argv); ~talker (); void run (); void Ros_comms_ Init ();p Rivate:ros::P ublisher chatter_publisher; Ros::serviceclient add_client; Tcpserver*server;public q_slots: void Publish_msg (QString msg);}; #endif/* TALKER_NODE_HPP_ */
Talker.cpp
#include <ros/ros.h> #include <string> #include "talker.hpp" #include <std_msgs/String.h> #include <geometry_msgs/Twist.h> #include <sstream> #include "tcpserver.hpp" #include <std_srvs/empty.h>/** implementation******************** /talker::talker (int argc, char** argv): Qnode (ARGC,ARGV, " Android_node ") {On_init (" http://localhost:11311 "," 127.0.0.1 "); Ros_info ("Android Node is starting!");} Talker::~talker () {if (server!=null) {delete server; Server=null; }}void Talker::ros_comms_init () {Ros::nodehandle n; Chatter_publisher = n.advertise<geometry_msgs::twist> ("Turtle1/cmd_vel", 1000); Add_client = n.serviceclient<std_srvs::empty> ("clear"); Server=new TCPServer (6666,0); Connect (server,signal (Receviemessage (QString)), This,slot (Publish_msg (QString)));} void Talker::run () {ros::rateLoop_rate (1); while (Ros::ok ()) {ros::spinonce (); Loop_rate.sleep ();} Std::cout << "Ros shutdown, proceeding to close the GUI." << Std::endl; if (server!=null) {server->deletelater (); Server=null; } q_emit Rosshutdown (); Used to signal the GUI for a shutdown (useful to Roslaunch)}void Talker::p ublish_msg (QString msg) {ros_info ("%s", MS G.tostdstring (). C_STR ()); if (msg[0]!= ' I ') {qstringlist datas=msg.split (""); int Count=datas.count (); if (count==2) {geometry_msgs::twist pose; Pose.linear.x=datas[0].toint (); Pose.angular.z=datas[1].toint (); Chatter_publisher.publish (pose); }else if (count==1) {std_srvs::empty srv; Add_client.call (SRV); } }}
3. Experimental part
This time I developed a small Android program to access the ROS system network, to control the very classic turtle. The ROS program is inside the Android project, which compresses the package directory.
Mobile phone development Source: Https://yunpan.cn/cBnMEKVyJpdiH access Password 7f7e
APK:HTTPS://YUNPAN.CN/CBNMSQGK7MCCK Access Password 57a4
How to use: first to compile a QT program, the specific method does not say, and then start the Ros, start the Android node, and then open the Android program, connected to the server can control the turtle.
After language: This article just from the Android platform to try, of course, other platforms are not a problem, because each platform has socket programming, although this method does not have to toss the corresponding platform of the Ros development package, but because the Ros must be built under a QT Proxy server is a bit of trouble.
Reference: http://blog.csdn.net/hcx25909/article/details/8795043
Network method of simple access to Ros robot system on whole platform