esp32和ros2之奔跑的turtlesim ?_? !_! ^_^ O_O >_<

这篇博客记录了使用ROS2 Foxy与Arduino ESP32进行消息和速度指令发布的调试过程。作者分享了如何将std_msgs::String替换为geometry_msgs::Twist,并提供了修改后的代码示例。此外,还展示了如何改变小坦克的舞台背景和尺寸,以提供更丰富的视觉体验。博客中提到,已创建了6套ROS2教程,并计划逐步更新更多内容。

其实这些内容都是一年前开发完成的……不信,那看如下博客:


^_^ -分割线- ^_^


ros2博客点击量比ros1低多了,于是就专心开发并没有更新全部内容。


啥子?ROS2的教程太少,这里已经有六套啦,如果还不够?学习了十几套源码开发课程,慢慢更新。


将std_msgs::String更换为geometry_msgs::Twist。

当然代码需要修改的地方也不少,直接上源码:

#include <ros2arduino.h>

#include <WiFi.h>
#include <WiFiUdp.h>
#define SSID       "ESP32LoveROS2"
#define SSID_PW    "66666666"
#define AGENT_IP   "172.20.10.2"
#define AGENT_PORT 2021 //AGENT port number

#define PUBLISH_FREQUENCY 10 //hz

void publishString(geometry_msgs::Twist* msg, void* arg)
{
  (void)(arg);
  static int cnt = 0;
//  msg->linear.x = ((double)rand()/(RAND_MAX));  //随机线速度
//  msg->angular.z = ((double)rand()/(RAND_MAX)); //随机角速度
  msg->linear.x = 0.2;                            //固定线速度
  msg->angular.z = 1.0 - 0.001*cnt;               //变化角速度
  cnt++;
}

class StringPub : public ros2::Node
{
public:
  StringPub()
  : Node("esp32_cmdvel")
  {
    ros2::Publisher<geometry_msgs::Twist>* publisher_ = this->createPublisher<geometry_msgs::Twist>("turtle1/cmd_vel");
    this->createWallFreq(PUBLISH_FREQUENCY, (ros2::CallbackFunc)publishString, nullptr, publisher_);
  }
};

WiFiUDP udp;

void setup() 
{
  WiFi.begin(SSID, SSID_PW);
  while(WiFi.status() != WL_CONNECTED);

  ros2::init(&udp, AGENT_IP, AGENT_PORT);
}

void loop() 
{
  static StringPub StringNode;
  
  ros2::spin(&StringNode);
}

小乌龟看腻了,换了小坦克,背景色不喜欢,换莫兰迪色,舞台太小换大!

小坦克:

莫兰迪色(部分):

 

选b5c4b1。 

#define DEFAULT_BG_R 0xb5
#define DEFAULT_BG_G 0xc4
#define DEFAULT_BG_B 0xb1

舞台原来才500---换---666。 


原来是这样的:

 

现在是这样的:


走两步?那不行,一定要走满整个舞台!!!

一开始:

 然后:

当然也可以换个颜色,再走个魔鬼步伐。下一节细说。 

 


 

 

<?xml version="1.0"?> <package format="2"> <name>ground_projection</name> <version>0.0.0</version> <description>The map_intergration package</description> <!-- One maintainer tag required, multiple allowed, one person per tag --> <!-- Example: --> <!-- <maintainer email="jane.doe@example.com">Jane Doe</maintainer> --> <maintainer email="pf@todo.todo">pf</maintainer> <!-- One license tag required, multiple allowed, one license per tag --> <!-- Commonly used license strings: --> <!-- BSD, MIT, Boost Software License, GPLv2, GPLv3, LGPLv2.1, LGPLv3 --> <license>TODO</license> <!-- Url tags are optional, but multiple are allowed, one per tag --> <!-- Optional attribute type can be: website, bugtracker, or repository --> <!-- Example: --> <!-- <url type="website">http://wiki.ros.org/map_intergration</url> --> <!-- Author tags are optional, multiple are allowed, one per tag --> <!-- Authors do not have to be maintainers, but could be --> <!-- Example: --> <!-- <author email="jane.doe@example.com">Jane Doe</author> --> <!-- The *depend tags are used to specify dependencies --> <!-- Dependencies can be catkin packages or system dependencies --> <!-- Examples: --> <!-- Use depend as a shortcut for packages that are both build and exec dependencies --> <!-- <depend>roscpp</depend> --> <!-- Note that this is equivalent to the following: --> <!-- <build_depend>roscpp</build_depend> --> <!-- <exec_depend>roscpp</exec_depend> --> <!-- Use build_depend for packages you need at compile time: --> <!-- <build_depend>message_generation</build_depend> --> <!-- Use build_export_depend for packages you need in order to build against this package: --> <!-- <build_export_depend>message_generation</build_export_depend> --> <!-- Use buildtool_depend for build tool packages: --> <!-- <buildtool_depend>catkin</buildtool_depend> --> <!-- Use exec_depend for packages you need at runtime: --> <!-- <exec_depend>message_runtime</exec_depend> --> <!-- Use test_depend for packages you need only for testing: --> <!-- <test_depend>gtest</test_depend> --> <!-- Use doc_depend for packages you need only for building documentation: --> <!-- <doc_depend>doxygen</doc_depend> --> <buildtool_depend>catkin</buildtool_depend> <build_depend>geometry_msgs</build_depend> <build_depend>nav_msgs</build_depend> <build_depend>pcl_conversions</build_depend> <build_depend>pcl_ros</build_depend> <build_depend>roscpp</build_depend> <build_depend>rospy</build_depend> <build_depend>sensor_msgs</build_depend> <build_depend>std_msgs</build_depend> <build_depend>tf2_ros</build_depend> <build_depend>tf2</build_depend> <build_depend>cv_bridge</build_depend> <build_depend>image_transport</build_depend> <build_export_depend>geometry_msgs</build_export_depend> <build_export_depend>nav_msgs</build_export_depend> <build_export_depend>pcl_conversions</build_export_depend> <build_export_depend>pcl_ros</build_export_depend> <build_export_depend>roscpp</build_export_depend> <build_export_depend>rospy</build_export_depend> <build_export_depend>sensor_msgs</build_export_depend> <build_export_depend>std_msgs</build_export_depend> <build_export_depend>tf2</build_export_depend> <build_export_depend>tf2_ros</build_export_depend> <build_export_depend>cv_bridge</build_export_depend> <build_export_depend>image_transport</build_export_depend> <exec_depend>geometry_msgs</exec_depend> <exec_depend>nav_msgs</exec_depend> <exec_depend>pcl_conversions</exec_depend> <exec_depend>pcl_ros</exec_depend> <exec_depend>roscpp</exec_depend> <exec_depend>rospy</exec_depend> <exec_depend>sensor_msgs</exec_depend> <exec_depend>std_msgs</exec_depend> <exec_depend>tf2</exec_depend> <exec_depend>tf2_ros</exec_depend> <exec_depend>cv_bridge</exec_depend> <exec_depend>image_transport</exec_depend> <!-- The export tag contains other, unspecified, tags --> <export> <!-- Other tools can request additional information be placed here --> </export> </package> 注释上述代码
最新发布
09-09
以下是 `ground_projection` 包的 `package.xml` 文件详细注释: ```xml <?xml version="1.0"?> <!-- ROS1格式的包定义文件(format 2) --> <package format="2"> <!-- 基础元数据(待完善状态) --> <name>ground_projection</name> <!-- 地面投影处理包 --> <version>0.0.0</version> <!-- 初始开发版本 --> <description>The map_intergration package</description> <!-- 描述与包名不符需修正 --> <!-- 维护信息(临时占位符) --> <maintainer email="pf@todo.todo">pf</maintainer> <!-- 需替换为有效邮箱 --> <license>TODO</license> <!-- 未指定具体许可证 --> <!-- 构建系统配置 --> <buildtool_depend>catkin</buildtool_depend> <!-- ROS1标准构建系统 --> <!-- 多模态传感器处理依赖 --> <build_depend>geometry_msgs</build_depend> <!-- 几何变换消息 --> <build_depend>nav_msgs</build_depend> <!-- 导航消息 --> <build_depend>pcl_conversions</build_depend> <!-- PCL点云转换 --> <build_depend>pcl_ros</build_depend> <!-- ROS-PCL接口 --> <build_depend>roscpp</build_depend> <!-- C++接口 --> <build_depend>rospy</build_depend> <!-- Python接口 --> <build_depend>sensor_msgs</build_depend> <!-- 传感器数据消息 --> <build_depend>std_msgs</build_depend> <!-- 标准消息 --> <build_depend>tf2_ros</build_depend> <!-- TF2坐标变换库 --> <build_depend>tf2</build_depend> <!-- TF2核心 --> <build_depend>cv_bridge</build_depend> <!-- OpenCV-ROS桥接 --> <build_depend>image_transport</build_depend> <!-- 图像传输工具 --> <!-- 导出依赖(与build_depend对应) --> <build_export_depend>geometry_msgs</build_export_depend> ... <build_export_depend>image_transport</build_export_depend> <!-- 运行时依赖 --> <exec_depend>geometry_msgs</exec_depend> ... <exec_depend>image_transport</exec_depend> <!-- 空导出配置(可添加插件声明) --> <export></export> </package> ``` 关键特征说明: 1. **多传感器集成**: - 同时依赖点云(PCL)视觉(CV_Bridge)处理库 - 包含TF2坐标变换支持 2. **开发初期状态**: - 版本号0.0.0 - 许可证未指定(TODO) - 描述与包名不一致 - 维护者信息不完整 3. **完整依赖链**: - 所有依赖项都完整声明了三阶段: * build_depend * build_export_depend * exec_depend 4. **典型地面处理包**: - 需要几何计算(geometry_msgs) - 依赖点云处理(pcl_ros) - 包含视觉辅助(cv_bridge)
评论 15
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

zhangrelay

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值