1. 程式人生 > >ROS-Industrial 之 industrial_robot_client 分析理解(3)

ROS-Industrial 之 industrial_robot_client 分析理解(3)

經過前面(1)(2)的理解與討論,此篇文章對ROS向機器人控制器的資料下載相關檔案進行說明。

JOINT_TRAJECTORY_STREAMER

#ifndef JOINT_TRAJECTORY_STREAMER_H
#define JOINT_TRAJECTORY_STREAMER_H

//標頭檔案thread.hpp用於進行程序管理
#include <boost/thread/thread.hpp>
#include "industrial_robot_client/joint_trajectory_interface.h"

以上thread.hpp檔案用於在程式中建立新的執行緒,並對其進行管理與使用。

namespace industrial_robot_client
{
namespace joint_trajectory_streamer
{

using industrial_robot_client::joint_trajectory_interface::JointTrajectoryInterface;
using industrial::joint_traj_pt_message::JointTrajPtMessage;
using industrial::smpl_msg_connection::SmplMsgConnection;

同樣的,client包中的所有程式都有一個統一的名稱空間,而不同的功能則有一個對應的子空間,方便對其中的變數與函式進行分類與管理。

namespace TransferStates
{
enum TransferState
{
  IDLE = 0, STREAMING =1 //,STARTING, //, STOPPING
};
}
typedef TransferStates::TransferState TransferState;

定義控制命令流的狀態字。

class JointTrajectoryStreamer : public JointTrajectoryInterface
{

建立一個將資訊向機器人控制器進行傳輸的類,繼承自JointTrajectoryInterface類。

public
: JointTrajectoryStreamer(int min_buffer_size = 1) : min_buffer_size_(min_buffer_size) {};

建構函式,對類進行初始化,並指定了要完成一次操作的最小點數量。

   virtual bool init(SmplMsgConnection* connection, const std::vector<std::string> &joint_names,
                    const std::map<std::string, double> &velocity_limits = std::map<std::string, double>());

初始化函式,其中:

  • connection :用於向機器人傳送資料的連線控制代碼。
  • joint_names :機器人關節名稱。
  • velocity_limits:對應於每一個關節的速度限制。
  ~JointTrajectoryStreamer();

解構函式,主要用來清除已經建立的執行緒。

  virtual void jointTrajectoryCB(const trajectory_msgs::JointTrajectoryConstPtr &msg);

回撥函式,進行資訊轉換與傳送。

  virtual bool trajectory_to_msgs(const trajectory_msgs::JointTrajectoryConstPtr &traj, std::vector<JointTrajPtMessage>* msgs);

資訊轉換函式。

  void streamingThread();

主要執行執行緒,進行流資料傳送。

  bool send_to_robot(const std::vector<JointTrajPtMessage>& messages);

初始化待發送的資料。

protected:
  void trajectoryStop();

  boost::thread* streaming_thread_;
  boost::mutex mutex_;
  int current_point_;
  std::vector<JointTrajPtMessage> current_traj_;
  TransferState state_;
  ros::Time streaming_start_;
  int min_buffer_size_;
};
} //joint_trajectory_streamer
} //industrial_robot_client
#endif /* JOINT_TRAJECTORY_STREAMER_H */

成員變數宣告,自上而下,為執行緒建立,互斥量,當前點的數量,當前軌跡,傳輸狀態字,時間,長度。

JOINT_TRAJECTORY_DOWNLOADER

#ifndef JOINT_TRAJECTORY_DOWNLOADER_H
#define JOINT_TRAJECTORY_DOWNLOADER_H
#include "industrial_robot_client/joint_trajectory_interface.h"
namespace industrial_robot_client
{
    namespace joint_trajectory_downloader
    {
        using industrial_robot_client::joint_trajectory_interface::JointTrajectoryInterface;
        using industrial::joint_traj_pt_message::JointTrajPtMessage;
        class JointTrajectoryDownloader : public JointTrajectoryInterface
        {
        public:
            bool send_to_robot(const std::vector<JointTrajPtMessage>& messages);
        };
} //joint_trajectory_downloader
} //industrial_robot_client
#endif /* JOINT_TRAJECTORY_DOWNLOADER_H */

將軌跡完整的傳送到機器人控制器中。

JOINT_TRAJTORY_ACTION

以下的檔案內容直接以程式碼的形式放在下面了。

#ifndef JOINT_TRAJTORY_ACTION_H
#define JOINT_TRAJTORY_ACTION_H
#include <ros/ros.h>
#include <actionlib/server/action_server.h>
#include <trajectory_msgs/JointTrajectory.h>
#include <control_msgs/FollowJointTrajectoryAction.h>
#include <control_msgs/FollowJointTrajectoryFeedback.h>
#include <industrial_msgs/RobotStatus.h>
namespace industrial_robot_client
{
namespace joint_trajectory_action
{
class JointTrajectoryAction
{
public:
   JointTrajectoryAction();
   ~JointTrajectoryAction();
    void run() { ros::spin(); }
private:
  typedef actionlib::ActionServer<control_msgs::FollowJointTrajectoryAction> JointTractoryActionServer;
  ros::NodeHandle node_;
  JointTractoryActionServer action_server_;
  ros::Publisher pub_trajectory_command_;
  ros::Subscriber sub_trajectory_state_;
  ros::Subscriber sub_robot_status_;
  ros::Timer watchdog_timer_;
  bool controller_alive_;
  bool has_active_goal_;
  bool has_moved_once_;
  JointTractoryActionServer::GoalHandle active_goal_;
  trajectory_msgs::JointTrajectory current_traj_;
  static const double DEFAULT_GOAL_THRESHOLD_;// = 0.01;
  double goal_threshold_;
  std::vector<std::string> joint_names_;
  control_msgs::FollowJointTrajectoryFeedbackConstPtr last_trajectory_state_;
  industrial_msgs::RobotStatusConstPtr last_robot_status_;
  ros::Time time_to_check_;
  static const double WATCHDOG_PERIOD_;// = 1.0;
  void watchdog(const ros::TimerEvent &e);
  void goalCB(JointTractoryActionServer::GoalHandle gh);
  void cancelCB(JointTractoryActionServer::GoalHandle gh);
  void controllerStateCB(const control_msgs::FollowJointTrajectoryFeedbackConstPtr &msg);
  void robotStatusCB(const industrial_msgs::RobotStatusConstPtr &msg);
  void abortGoal();
  bool withinGoalConstraints(const control_msgs::FollowJointTrajectoryFeedbackConstPtr &msg,
                             const trajectory_msgs::JointTrajectory & traj);
};
} //joint_trajectory_action
} //industrial_robot_client
#endif /* JOINT_TRAJTORY_ACTION_H */

通過前面的檔案描述,這裡面的東西先放在這裡,先不進行解釋,要看懂這個程式碼檔案,還要繼續認識一下ROS Action的內容。
對於Client的理解先到這裡。

相關推薦

ROS-Industrial industrial_robot_client 分析理解(3)

經過前面(1)和(2)的理解與討論,此篇文章對ROS向機器人控制器的資料下載相關檔案進行說明。 JOINT_TRAJECTORY_STREAMER #ifndef JOINT_TRAJECTORY_STREAMER_H #define JOINT_

ROS-Industrial industrial_robot_client Overview

按照在ROS-Industrial Overview路線部分所說的,在完成ROS-I框架最底的一層之後,還要分析理解simple_message和industrial_robot_client兩大部分才算相對完整的理解ROS-I如何與已有的機器人控制器進行融合,

TensorFlow學習筆記原始碼分析3)---- retrain.py

"""簡單呼叫Inception V3架構模型的學習在tensorboard顯示了摘要。 這個例子展示瞭如何採取一個Inception V3架構模型訓練ImageNet影象和訓練新的頂層,可以識別其他類的影象。 每個影象裡,頂層接收作為輸入的一個2048維向量。這

Ogitor探索程式碼分析3)---CBaseEditor::showBoundingBox(bool bShow)

在Qtogitor中編輯場景時如何選中物體Object並讓它顯示出邊線(Ogitor稱它為Bounding Box)呢? 前面已經介紹了OnMouseMove的功能了,如果不知道的要先看一下OnMouseMove的功能; 1、當滑鼠在螢幕上移動時OnMouseMove實時

EventBus 3原始碼分析

eventbus 2的原始碼分析:https://blog.csdn.net/qq_35559358/article/details/74295870 請看本篇的朋友先看2從更基礎更詳細的地方理解,篇末將加入2個版本原始碼中最大不同實現的對比,新人菜鳥,請不要罵太凶。 本篇的分析和eventbu

redis個人理解3---redis的事件驅動原始碼分析

redis的事件驅動 redis效能很好,而且是一個單執行緒的框架。得益於redis主要通過非同步IO, 多路複用的技術,使用反應堆(reactor)模式,把大量的io操作通過訊息驅動的方式單執行緒一條條處理,這樣可以很好的利用CPU資源。因為沒有同步呼叫,所以處理速度非常快。使得多個Client訪問red

大資料技術學習筆記hive框架基礎3-sqoop工具的使用及具體業務分析

一、CDH版本的介紹及環境部署     -》Hadoop的三大發行版本         -》Apache Hadoop         -》

大資料技術學習筆記Hadoop框架基礎3-網站日誌分析及MapReduce過程詳解

一、回顧     -》Hadoop啟動方式         -》單個程序             sbin/h

《springsecurity原始碼分析3.springsecurity原始碼分析如何儲存認證資訊Authentication並在請求之間共享。

通過身份認證之後,是如何儲存認證結果,並將認證結果在多個請求中共享的呢?   我猜肯定是放入session。  UsernamePasswordAuthenticationFilter 繼承AbstractAuthenticationProcessingFilter,

Netty原始碼分析3章(客戶端接入流程)---->第2節: 處理接入事件handle的建立

  Netty原始碼分析第三章: 客戶端接入流程   第二節: 處理接入事件之handle的建立   上一小節我們剖析完成了與channel繫結的ChannelConfig初始化相關的流程, 這一小節繼續剖析客戶端連線事件的處理 回到上一章NioEventLoop的p

spring4.2.9 java專案環境下ioc原始碼分析(五)——refreshobtainFreshBeanFactory方法(@3預設標籤import,alias解析)

接上篇文章,到了具體解析的時候了,具體的分為兩種情況,一種是預設名稱空間的標籤<bean>;另一種是自定義名稱空間的標籤比如<context:xxx>,<tx:xxx>等。先看下預設的名稱空間的標籤解析。protected void par

Linux裝置模型分析bus(基於3.10.1核心)

作者:劉昊昱  核心版本:3.10.1 一、bus定義 Linux裝置驅動模型中的bus,即可以是物理匯流排(如PCI、I2C匯流排)的抽象,也可以是出於裝置驅動模型架構需要而定義的虛擬的“platform”匯流排。一個符合Linux裝置驅動模型的device或devi

Linux裝置驅動程式架構分析platform(基於3.10.1核心)

作者:劉昊昱  核心版本:3.10.1 一、platform bus的註冊 platform bus註冊是通過platform_bus_init函式完成的,該函式定義在drivers/base/platform.c檔案中,其內容如下: 904int __init pl

Linux裝置模型分析device_driver(基於3.10.1核心)

一、device_driver定義 181/**  182 * struct device_driver - The basic device driver structure  183 * @name:   Name of the device

ROS學習釋出訊息——Publisher_程式碼分析

//一個非常詳細的版本: //本檔名字為: publisher.cpp #include "ros/ros.h" #include "std_msgs/String.h" #include <i

ROS學習訂閱訊息——Subscriber_程式碼分析

//詳解版本: //本程式碼檔名為:subscriber.cpp #include "ros/ros.h" #include "std_msgs/String.h" #include <iost

ROS學習tf.3編寫一個tf接收器(C++)

ROS.tf3編寫一個tf接收器(C++)宣告:本教程來自於ROS.WIKI,本人在整理過程中可能出現一些錯誤和問題,有問題可以去檢視官網版本也可以諮詢本人在之前的教程中,我們建立了一個tf廣播公司向tf釋出一隻烏龜的姿勢。 在本教程中,我們將建立一個tf接收器來開始使用tf

Memcached原始碼分析訊息迴應(3

文章列表: 《Memcached原始碼分析 - Memcached原始碼分析之總結篇(8)》 前言 上一章《Memcached原始碼分析 - Memcached原始碼分析之命令解析(2)》,我們花了很大的力氣去講解Memcached如何從客戶端讀取命令,並且

JFinal個人學習筆記原始碼分析3

上篇分析完了initActionMapping()的原始碼。JFinal原始碼裡初始化init方法還有: boolean init(JFinalConfig jfinalConfig, Serv

.NET Core 3.0深入原始碼理解Configuration(二)

檔案型配置基本內容 上一篇文章討論了Configuration的幾個核心物件,本文繼續討論Configuration中關於檔案型配置的相關內容。相比較而言,檔案型配置的使用場景更加廣泛,使用者自定義配置擴充套件也可以基於檔案型配置進行擴充套件。如果需要檢視上一篇文章,可以點選移步。 .NET Core檔案型配