機器人編程趣味實踐10-做個任務(行動)

      網友投稿 730 2022-05-29

      這是ROS2中比服務更為復雜的基礎模塊。

      白話一下:一個行動,可以時刻匯報進展,無法完成時可以變更或者取消,完成后會告知

      Mission completed!

      具體應用案例,如導航行為樹

      這個后續細說,現在先從簡單的入手吧。

      >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

      本節目標通過基礎案例掌握ROS2內部行動的基本使用。

      預備知識

      行動是 ROS 2 中的又一種通信類型,用于長時間運行的任務,由三部分組成:目標、反饋和結果。行動建立在主題和服務上。 它們的功能類似于服務,但可以取消,還提供穩定的反饋,而不同于返回單一響應的服務。行動同樣使用客戶端-服務器模型,類似于發布者-訂閱者模型(在主題教程中進行了描述)。 “行動客戶端”節點向“動作服務器”節點發送目標,該節點確認目標并返回反饋過程流和結果。

      功能包要點

      ros2基礎包

      turtlesim包

      source

      實踐

      1 配置

      運行如下兩個節點 /turtlesim 和 /teleop_turtle :

      ros2 run turtlesim turtlesim_node

      ros2 run turtlesim turtle_teleop_key

      2 基礎使用

      可以看到右側啟動/teleop_turtle節點后,終端顯示如下:

      使用方向鍵移動機器人.

      使用 G|B|V|C|D|E|R|T 鍵使機器人轉相應角度. 'F' 鍵取消旋轉.

      讓我們專注于第二行,它對應于一個行動。 (第一條指令對應于“cmd_vel”主題,之前在主題教程中討論過。)請注意,字母鍵 G|B|V|C|D|E|R|T 在美國 QWERTY 鍵盤上的 F 鍵周圍形成一個“框”。 F 周圍的每個鍵的位置對應于turtlesim 中的方向。 例如,E 會將海龜的方向旋轉到左上角。

      注意 /turtlesim 節點運行的終端。 每次按下其中一個鍵時,都會向作為 /turtlesim 節點一部分的動作服務器發送一個目標。 目標是旋轉烏龜以使其朝向特定方向。 烏龜完成旋轉后,應顯示一條中繼目標結果的消息:

      [INFO] [1622462396.650765434] [turtlesim]: 開啟二維機器人仿真節點 /turtlesim

      [INFO] [1622462396.735890281] [turtlesim]: Spawning turtle [turtle1] at x=[9.855556], y=[7.388889], theta=[0.000000]

      [INFO] [1622462694.049672436] [turtlesim]: Rotation goal completed successfully

      如上對應:

      if (fabs(normalizeAngle(static_cast(orient_) - theta)) < 0.02)

      {

      RCLCPP_INFO(nh_->get_logger(), "Rotation goal completed successfully");

      rotate_absolute_goal_handle_->succeed(rotate_absolute_result_);

      rotate_absolute_goal_handle_ = nullptr;

      lin_vel_x_ = 0.0;

      lin_vel_y_ = 0.0;

      ang_vel_ = 0.0;

      }

      F 鍵將在執行過程中取消目標。

      嘗試按 B 鍵,然后在海龜完成旋轉之前按 F 鍵。 在運行 /turtlesim 節點的終端中,將看到以下消息:

      [INFO] [1622462850.641914700] [turtlesim]: Rotation goal canceled

      如上對應:

      if (rotate_absolute_goal_handle_->is_canceling())

      {

      RCLCPP_INFO(nh_->get_logger(), "Rotation goal canceled");

      rotate_absolute_goal_handle_->canceled(rotate_absolute_result_);

      rotate_absolute_goal_handle_ = nullptr;

      lin_vel_x_ = 0.0;

      lin_vel_y_ = 0.0;

      ang_vel_ = 0.0;

      }

      客戶端(在Teleop中的輸入)不僅可以停止目標,而且服務器端(/turtlesim節點)也可以停止目標。 當服務器端選擇停止處理一個目標時,稱為“中止”該目標。 嘗試按 D 鍵,然后在旋轉完成之前按 G 鍵。 在運行 /turtlesim 節點的終端中,將看到以下消息:

      [WARN] [1622462989.905265647] [turtlesim]: Rotation goal received before a previous goal finished. Aborting previous goal

      如上對應:

      void Turtle::rotateAbsoluteAcceptCallback(const std::shared_ptr goal_handle)

      {

      // Abort any existing goal

      if (rotate_absolute_goal_handle_)

      {

      RCLCPP_WARN(nh_->get_logger(), "Rotation goal received before a previous goal finished. Aborting previous goal");

      rotate_absolute_goal_handle_->abort(rotate_absolute_result_);

      }

      rotate_absolute_goal_handle_ = goal_handle;

      rotate_absolute_feedback_.reset(new turtlesim::action::RotateAbsolute::Feedback);

      rotate_absolute_result_.reset(new turtlesim::action::RotateAbsolute::Result);

      rotate_absolute_start_orient_ = orient_;

      }

      該行動服務器選擇中止第一個目標,因為有了新目標。 可以選擇其他目標,例如拒絕新目標或在第一個目標完成后執行第二個目標。 不要假設每個行動服務器在獲得新目標時都會選擇中止當前目標。

      3 節點信息

      /turtlesim

      Action Servers:

      /turtle1/rotate_absolute: turtlesim/action/RotateAbsolute

      zhangrelay@ros2fun:~/RobSoft/turtlesim$ ros2 node info /turtlesim

      /turtlesim

      Subscribers:

      /parameter_events: rcl_interfaces/msg/ParameterEvent

      /turtle1/cmd_vel: geometry_msgs/msg/Twist

      Publishers:

      /parameter_events: rcl_interfaces/msg/ParameterEvent

      /rosout: rcl_interfaces/msg/Log

      /turtle1/color_sensor: turtlesim/msg/Color

      /turtle1/pose: turtlesim/msg/Pose

      Service Servers:

      /clear: std_srvs/srv/Empty

      /kill: turtlesim/srv/Kill

      /reset: std_srvs/srv/Empty

      /spawn: turtlesim/srv/Spawn

      /turtle1/set_pen: turtlesim/srv/SetPen

      /turtle1/teleport_absolute: turtlesim/srv/TeleportAbsolute

      /turtle1/teleport_relative: turtlesim/srv/TeleportRelative

      /turtlesim/describe_parameters: rcl_interfaces/srv/DescribeParameters

      /turtlesim/get_parameter_types: rcl_interfaces/srv/GetParameterTypes

      /turtlesim/get_parameters: rcl_interfaces/srv/GetParameters

      /turtlesim/list_parameters: rcl_interfaces/srv/ListParameters

      /turtlesim/set_parameters: rcl_interfaces/srv/SetParameters

      /turtlesim/set_parameters_atomically: rcl_interfaces/srv/SetParametersAtomically

      Service Clients:

      Action Servers:

      /turtle1/rotate_absolute: turtlesim/action/RotateAbsolute

      Action Clients:

      /teleop_turtle

      Action Clients:

      /turtle1/rotate_absolute: turtlesim/action/RotateAbsolute

      zhangrelay@ros2fun:~/RobSoft/turtlesim$ ros2 node info /teleop_turtle

      /teleop_turtle

      Subscribers:

      /parameter_events: rcl_interfaces/msg/ParameterEvent

      Publishers:

      /parameter_events: rcl_interfaces/msg/ParameterEvent

      /rosout: rcl_interfaces/msg/Log

      /turtle1/cmd_vel: geometry_msgs/msg/Twist

      Service Servers:

      /teleop_turtle/describe_parameters: rcl_interfaces/srv/DescribeParameters

      /teleop_turtle/get_parameter_types: rcl_interfaces/srv/GetParameterTypes

      /teleop_turtle/get_parameters: rcl_interfaces/srv/GetParameters

      /teleop_turtle/list_parameters: rcl_interfaces/srv/ListParameters

      /teleop_turtle/set_parameters: rcl_interfaces/srv/SetParameters

      /teleop_turtle/set_parameters_atomically: rcl_interfaces/srv/SetParametersAtomically

      Service Clients:

      Action Servers:

      Action Clients:

      /turtle1/rotate_absolute: turtlesim/action/RotateAbsolute

      4 行動列表

      ros2 action list

      顯示如下:

      /turtle1/rotate_absolute

      ros2 action list -t

      顯示如下:

      /turtle1/rotate_absolute [turtlesim/action/RotateAbsolute]

      5 行動信息

      ros2 action info /turtle1/rotate_absolute

      顯示結果如下:

      Action: /turtle1/rotate_absolute

      Action clients: 1

      /teleop_turtle

      Action servers: 1

      /turtlesim

      6 行動接口消息

      ros2 interface show turtlesim/action/RotateAbsolute

      顯示如下:

      # The desired heading in radians

      float32 theta

      ---

      # The angular displacement in radians to the starting position

      float32 delta

      ---

      # The remaining rotation in radians

      float32 remaining

      機器人編程趣味實踐10-做個任務(行動)

      7 發送目標

      通用格式:

      ros2 action send_goal

      具體應用:

      ros2 action send_goal /turtle1/rotate_absolute turtlesim/action/RotateAbsolute "{theta: 1.57}"

      顯示結果如下:

      Waiting for an action server to become available...

      Sending goal:

      theta: 1.57

      Goal accepted with ID: 9e134c1c6d3d41bbac1aa20038487d07

      Result:

      delta: 1.5520031452178955

      Goal finished with status: SUCCEEDED

      注意,誤差大約0.02。可以修改機器人PID轉向提高精度留作思考題。

      當然控制周期也可以好好研究一下哦^_^

      如果需要看過程:

      ros2 action send_goal /turtle1/rotate_absolute turtlesim/action/RotateAbsolute "{theta: 0.0}" --feedback

      Waiting for an action server to become available...

      Sending goal:

      theta: 0.0

      Feedback:

      remaining: -0.10079997777938843

      Goal accepted with ID: e06e9a8bc25345e18ace2a0fdaa55b80

      Feedback:

      remaining: -0.09919998049736023

      ....

      Feedback:

      remaining: -0.0016000281320884824

      Result:

      delta: 0.09919995069503784

      Goal finished with status: SUCCEEDED

      總結

      行動類似服務,允許執行長時間運行的任務、提供定時反饋并且可以取消。

      機器人系統可能會使用行動進行導航。 動作目標可以告訴機器人行進到一個位置。 機器人導航到該位置時,可以沿途發送更新(即反饋),一旦到達目的地,它就會發送最終結果消息。

      turtlesim 有一個行動服務器,行動客戶端可以將目標發送到旋轉機器人。 在本教程中,學習行動 /turtle1/rotate_absolute,更好了解什么是行動以及它們如何工作。

      機器人

      版權聲明:本文內容由網絡用戶投稿,版權歸原作者所有,本站不擁有其著作權,亦不承擔相應法律責任。如果您發現本站中有涉嫌抄襲或描述失實的內容,請聯系我們jiasou666@gmail.com 處理,核實后本網站將在24小時內刪除侵權內容。

      上一篇:操作系統之存儲管理——FIFO算法和LRU算法
      下一篇:Linux應用開發:標準IO庫(上)
      相關文章
      亚洲精品无码成人| 中文字幕乱码亚洲精品一区| 国产成人亚洲合集青青草原精品 | 午夜影视日本亚洲欧洲精品一区| 在线亚洲午夜理论AV大片| 亚洲色欲久久久久综合网| 亚洲男人在线无码视频| 亚洲人成人网站在线观看| 亚洲性久久久影院| 亚洲精品动漫人成3d在线| 亚洲男人天堂2020| 亚洲日产无码中文字幕| 人人狠狠综合久久亚洲婷婷| 国产亚洲综合成人91精品 | 在线aⅴ亚洲中文字幕| 中文有码亚洲制服av片| 亚洲日韩精品无码专区| 亚洲av日韩aⅴ无码色老头| 国产成人亚洲综合无| 亚洲一区日韩高清中文字幕亚洲| 久久久久亚洲?V成人无码| 亚洲欧洲自拍拍偷午夜色无码| 久久亚洲高清观看| 亚洲综合无码一区二区| 亚洲欧洲日产国码在线观看| 精品亚洲AV无码一区二区三区| 亚洲第一区二区快射影院| 亚洲成a人片在线观看天堂无码| 国产精品亚洲а∨无码播放不卡| 亚洲乱码国产一区网址| 国产亚洲精品精品国产亚洲综合 | 亚洲第一男人天堂| 欧美亚洲精品一区二区| 亚洲精品线路一在线观看| 国产V亚洲V天堂A无码| 亚洲综合激情九月婷婷| 亚洲精品国产国语| 国产亚洲视频在线观看| 亚洲伊人久久精品影院| 麻豆亚洲AV永久无码精品久久| 91亚洲精品自在在线观看|