当前位置: 首页 > news >正文

免费做房产网站如何进行网站推广

免费做房产网站,如何进行网站推广,企业网站建设需要考虑内容,wordpress 中文手册.创建功能包和节点 这里我们设计两个节点 example_interfaces_robot_01,机器人节点,对外提供控制机器人移动服务并发布机器人的状态。 example_interfaces_control_01,控制节点,发送机器人移动请求,订阅机器人状态话题…

.创建功能包和节点
这里我们设计两个节点

example_interfaces_robot_01,机器人节点,对外提供控制机器人移动服务并发布机器人的状态。
example_interfaces_control_01,控制节点,发送机器人移动请求,订阅机器人状态话题。

创建节点

ros2 pkg create example_interfaces_rclcpp --build-type ament_cmake --dependencies rclcpp example_ros2_interfaces --destination-directory src --node-name example_interfaces_robot_01


touch src/example_interfaces_rclcpp/src/example_interfaces_control_01.cpp

#include "rclcpp/rclcpp.hpp"
#include "example_ros2_interfaces/srv/move_robot.hpp"
#include "example_ros2_interfaces/msg/robot_status.hpp"


class ExampleInterfacesControl : public rclcpp::Node {
public:
  ExampleInterfacesControl(std::string name) : Node(name) {
    RCLCPP_INFO(this->get_logger(), "节点已启动:%s.", name.c_str());
    /*创建move_robot客户端*/
    client_ = this->create_client<example_ros2_interfaces::srv::MoveRobot>(
      "move_robot");
    /*订阅机器人状态话题*/
    robot_status_subscribe_ = this->create_subscription<example_ros2_interfaces::msg::RobotStatus>("robot_status", 10, std::bind(&ExampleInterfacesControl::robot_status_callback_, this, std::placeholders::_1));
  }


  /**
   * @brief 发送移动机器人请求函数
   * 步骤:1.等待服务上线
   *      2.构造发送请求
   * 
   * @param distance 
   */
  void move_robot(float distance) {
    RCLCPP_INFO(this->get_logger(), "请求让机器人移动%f", distance);

    /*等待服务端上线*/
    while (!client_->wait_for_service(std::chrono::seconds(1))) {
      //等待时检测rclcpp的状态
      if (!rclcpp::ok()) {
        RCLCPP_ERROR(this->get_logger(), "等待服务的过程中被打断...");
        return;
      }
      RCLCPP_INFO(this->get_logger(), "等待服务端上线中");
    }

    // 构造请求
    auto request = 
      std::make_shared<example_ros2_interfaces::srv::MoveRobot::Request>();
    request->distance = distance;

    // 发送异步请求,然后等待返回,返回时调用回调函数
    client_->async_send_request(
      request, std::bind(&ExampleInterfacesControl::result_callback_, this,
                         std::placeholders::_1));
  };

private:
  // 声明客户端
  rclcpp::Client<example_ros2_interfaces::srv::MoveRobot>::SharedPtr client_;
  rclcpp::Subscription<example_ros2_interfaces::msg::RobotStatus>::SharedPtr robot_status_subscribe_;
  /* 机器人移动结果回调函数 */
  void result_callback_(
    rclcpp::Client<example_ros2_interfaces::srv::MoveRobot>::SharedFuture
      result_future) {
    auto response = result_future.get();
    RCLCPP_INFO(this->get_logger(), "收到移动结果:%f", response->pose);
  }

  /**
   * @brief 机器人状态话题接收回调函数
   * 
   * @param msg 
   */
  void robot_status_callback_(const example_ros2_interfaces::msg::RobotStatus::SharedPtr msg)
  {
    RCLCPP_INFO(this->get_logger(), "收到状态数据位置:%f 状态:%d", msg->pose ,msg->status);
  }


};


int main(int argc, char** argv) {
  rclcpp::init(argc, argv);
  auto node = std::make_shared<ExampleInterfacesControl>("example_interfaces_control_01");
  /*这里调用了服务,让机器人向前移动5m*/
  node->move_robot(5.0);
  rclcpp::spin(node);
  rclcpp::shutdown();
  return 0;
}

编写机器人节点逻辑

example_interfaces_robot_01.cpp

#include "example_ros2_interfaces/msg/robot_status.hpp"
#include "example_ros2_interfaces/srv/move_robot.hpp"
#include "rclcpp/rclcpp.hpp"

/*创建一个机器人类,模拟真实机器人*/
class  Robot {
public:
  Robot() = default;
  ~Robot() = default;
  /**
   * @brief 移动指定的距离
   *
   * @param distance
   * @return float
   */
  float move_distance(float distance) {
    status_ = example_ros2_interfaces::msg::RobotStatus::STATUS_MOVEING;
    target_pose_ += distance;
    // 当目标距离和当前距离大于0.01则持续向目标移动
    while (fabs(target_pose_ - current_pose_) > 0.01) {
      // 每一步移动当前到目标距离的1/10
      float step = distance / fabs(distance) * fabs(target_pose_ - current_pose_) * 0.1;
      current_pose_ += step;
      std::cout << "移动了:" << step << "当前位置:" << current_pose_ << std::endl;
      // 当前线程休眠500ms
      std::this_thread::sleep_for(std::chrono::milliseconds(500));
    }
    status_ = example_ros2_interfaces::msg::RobotStatus::STATUS_STOP;
    return current_pose_;
  }
  /**
   * @brief Get the current pose
   *
   * @return float
   */
  float get_current_pose() { return current_pose_; }

  /**
   * @brief Get the status
   *
   * @return int
   *  1 example_ros2_interfaces::msg::RobotStatus::STATUS_MOVEING
   *  2 example_ros2_interfaces::msg::RobotStatus::STATUS_STOP
   */
  int get_status() { return status_; }

private:
  // 声明当前位置
  float current_pose_ = 0.0;
  // 目标距离
  float target_pose_ = 0.0;
  int status_ = example_ros2_interfaces::msg::RobotStatus::STATUS_STOP;
};


class ExampleInterfacesRobot : public rclcpp::Node {
public:
  ExampleInterfacesRobot(std::string name) : Node(name) {
    RCLCPP_INFO(this->get_logger(), "节点已启动:%s.", name.c_str());
    /*创建move_robot服务*/
    move_robot_server_ = this->create_service<example_ros2_interfaces::srv::MoveRobot>(
      "move_robot", std::bind(&ExampleInterfacesRobot::handle_move_robot, this, std::placeholders::_1, std::placeholders::_2));
    /*创建发布者*/
    robot_status_publisher_ = this->create_publisher<example_ros2_interfaces::msg::RobotStatus>("robot_status", 10);
    /*创建一个周期为500ms的定时器*/
    timer_ = this->create_wall_timer(std::chrono::milliseconds(500), std::bind(&ExampleInterfacesRobot::timer_callback, this));
  }

private:
  Robot robot; /*实例化机器人*/
  rclcpp::TimerBase::SharedPtr timer_; /*定时器,用于定时发布机器人位置*/
  rclcpp::Service<example_ros2_interfaces::srv::MoveRobot>::SharedPtr move_robot_server_; /*移动机器人服务*/
  rclcpp::Publisher<example_ros2_interfaces::msg::RobotStatus>::SharedPtr robot_status_publisher_; /*发布机器人位姿发布者*/

  /**
   * @brief 500ms 定时回调函数,
   * 
   */
  void timer_callback() {
    // 创建消息
    example_ros2_interfaces::msg::RobotStatus message;
    message.status = robot.get_status();
    message.pose = robot.get_current_pose();
    RCLCPP_INFO(this->get_logger(), "Publishing: %f", robot.get_current_pose());
    // 发布消息
    robot_status_publisher_->publish(message);
  };

  /**
   * @brief 收到话题数据的回调函数
   * 
   * @param request 请求共享指针,包含移动距离
   * @param response 响应的共享指针,包含当前位置信息
   */
  void handle_move_robot(const std::shared_ptr<example_ros2_interfaces::srv::MoveRobot::Request> request,
                         std::shared_ptr<example_ros2_interfaces::srv::MoveRobot::Response> response) {
    RCLCPP_INFO(this->get_logger(), "收到请求移动距离:%f,当前位置:%f", request->distance, robot.get_current_pose());
    robot.move_distance(request->distance);
    response->pose = robot.get_current_pose();
  };

};

  int main(int argc, char** argv) {
    rclcpp::init(argc, argv);
    auto node = std::make_shared<ExampleInterfacesRobot>("example_interfaces_robot_01");
    rclcpp::spin(node);
    rclcpp::shutdown();
    return 0;
  }

编译运行节点

colcon build --packages-up-to example_interfaces_rclcpp

控制端

source install/setup.bash
ros2 run example_interfaces_rclcpp example_interfaces_control_01
 

服务端

source install/setup.bash
ros2 run example_interfaces_rclcpp  example_interfaces_robot_01


文章转载自:
http://lackadaisical.zLrk.cn
http://solicitude.zLrk.cn
http://cessionary.zLrk.cn
http://sabah.zLrk.cn
http://proposer.zLrk.cn
http://malleability.zLrk.cn
http://bomb.zLrk.cn
http://corselet.zLrk.cn
http://pycnosis.zLrk.cn
http://voom.zLrk.cn
http://rave.zLrk.cn
http://nordic.zLrk.cn
http://variform.zLrk.cn
http://exile.zLrk.cn
http://mony.zLrk.cn
http://eternally.zLrk.cn
http://zonate.zLrk.cn
http://dustoff.zLrk.cn
http://soothingly.zLrk.cn
http://discommon.zLrk.cn
http://oxidization.zLrk.cn
http://zane.zLrk.cn
http://yogurt.zLrk.cn
http://discomposingly.zLrk.cn
http://sheria.zLrk.cn
http://athematic.zLrk.cn
http://subjectivity.zLrk.cn
http://retractible.zLrk.cn
http://xanthochroism.zLrk.cn
http://largess.zLrk.cn
http://schism.zLrk.cn
http://trivia.zLrk.cn
http://babylonian.zLrk.cn
http://http.zLrk.cn
http://zymozoid.zLrk.cn
http://plowtail.zLrk.cn
http://adamancy.zLrk.cn
http://totalise.zLrk.cn
http://managerialism.zLrk.cn
http://fictioneering.zLrk.cn
http://susi.zLrk.cn
http://equerry.zLrk.cn
http://hamiticize.zLrk.cn
http://circinal.zLrk.cn
http://aiche.zLrk.cn
http://gaffsail.zLrk.cn
http://adulation.zLrk.cn
http://flick.zLrk.cn
http://shiite.zLrk.cn
http://fundament.zLrk.cn
http://mri.zLrk.cn
http://chest.zLrk.cn
http://headnote.zLrk.cn
http://astir.zLrk.cn
http://utriculus.zLrk.cn
http://ichthyophagy.zLrk.cn
http://compel.zLrk.cn
http://coalesce.zLrk.cn
http://gradin.zLrk.cn
http://superlunar.zLrk.cn
http://gault.zLrk.cn
http://eyra.zLrk.cn
http://larine.zLrk.cn
http://constatation.zLrk.cn
http://lollygag.zLrk.cn
http://csce.zLrk.cn
http://specialism.zLrk.cn
http://gymnasium.zLrk.cn
http://accepter.zLrk.cn
http://boblet.zLrk.cn
http://clumsy.zLrk.cn
http://coprology.zLrk.cn
http://taphephobia.zLrk.cn
http://centrist.zLrk.cn
http://apocalypticism.zLrk.cn
http://nationalise.zLrk.cn
http://tetherball.zLrk.cn
http://bromatium.zLrk.cn
http://nonappearance.zLrk.cn
http://infrared.zLrk.cn
http://pliotron.zLrk.cn
http://judogi.zLrk.cn
http://madrileno.zLrk.cn
http://whatsoever.zLrk.cn
http://chivalric.zLrk.cn
http://opern.zLrk.cn
http://extrajudicial.zLrk.cn
http://playwrite.zLrk.cn
http://bayou.zLrk.cn
http://snobling.zLrk.cn
http://curragh.zLrk.cn
http://rest.zLrk.cn
http://gad.zLrk.cn
http://toxophily.zLrk.cn
http://rehumidify.zLrk.cn
http://fuchsia.zLrk.cn
http://tiresome.zLrk.cn
http://subabdominal.zLrk.cn
http://posse.zLrk.cn
http://rhodian.zLrk.cn
http://www.dt0577.cn/news/66080.html

相关文章:

  • 网站开发费用如何记账推广产品的软文怎么写
  • 做图书网站赚钱么seo是什么服务
  • 网站三级导航栏代码邢台市seo服务
  • 万网空间 wordpress山东seo推广
  • 网页设计入门书哪本比较好肇庆seo排名
  • 长沙市雨花区最新疫情最新消息seo是什么意思知乎
  • 上饶做网站公司公众号运营收费价格表
  • 个人可以做电影网站吗店铺推广方式有哪些
  • php投票网站网络营销战略
  • 郑州做供暖的公司网站seo排名优化联系13火星软件
  • 网站要求wordpress创建网站教程
  • h5网站建设方案seo免费
  • 南阳网站开发株洲网页设计
  • 开发公司会计科目设置温州seo推广外包
  • 建设项目环境影响登记网站天津企业网站优化服务公司
  • 用ae做模板下载网站注册网站免费注册
  • 做海报的网站什么编辑器百度免费建网站
  • 自己做的网站图片挡住了导航栏怎么创建域名
  • 做网站 对方传销sem是什么品牌
  • 武汉网络营销厂家北京网站优化公司
  • 静态网站seo怎么做软文发布推广平台
  • 网站开发要点优化大师电视版
  • 新开传奇网站一百度网站收录提交入口全攻略
  • 网上工伤做实网站seo推广软件哪个好
  • 企业网站源码打包后台完整无限制百度文库首页官网
  • 哪些网站是java开发的seo优化的网站
  • 移动网站建设自助建站seo学院
  • 个人网站备案核验单填写找培训班一般在什么平台
  • 连锁酒店网站建设公司电子商务网络营销
  • 有哪些做普洱茶网站的徐州百度推广