• Baize_ServoDriver_esp32(ROS+Arduino驱动舵机机械臂,通过串口或WiFi话题通信)(数字孪生:虚拟和现实同步)


    介绍

    硬件平台

    控制板:Baize_ServoDriver_esp32 

    舵机机械臂:

    通过Baize_ServoDriver_esp32这块舵机驱动板,我们来驱动我们的机器人。

    首先,我们通过串口来订阅我们的自定义话题消息。

    具体的话题消息以及定义方式,可以参照下面的仓库

    https://github.com/Allen953/Leizhuo_UnderWaterHexapodRobot

    然后我们就可以使用这个话题消息了,基于这个话题消息,我们用arduino来订阅这个消息,并显示在显示屏上,我发现当只显示一个joint_states数据时,屏幕的关节角度刷新速率正常,非常快,但是当角度多了之后,速度就变的很慢了,我猜是屏幕刷新速度跟不上,不过这个刷法好像也站不住脚,毕竟我用一个数字进行显示实验的时候,刷新速度是非常快的。所以还是比较疑惑。

    代码 

    1.订阅关节变量消息,并显示在显示屏上

    1. /*
    2. * rosserial Publisher Example
    3. * Prints "hello world!"
    4. */
    5. #include <ros.h>
    6. #include <std_msgs/String.h>
    7. #include "Leizhuo_UnderWaterHexapodRobot/joint.h"
    8. #include <SPI.h>
    9. #include <TFT_eSPI.h> // Hardware-specific library
    10. TFT_eSPI TFT = TFT_eSPI(); // Invoke custom library
    11. void chatterCallback(const std_msgs::String& msg) {
    12. // TFT.fillScreen(TFT_BLACK);
    13. TFT.setCursor(0, 30, 4);
    14. // Set the font colour to be white with a black background
    15. TFT.setTextColor(TFT_WHITE, TFT_BLACK);
    16. // We can now plot text on screen using the "print" class
    17. TFT.println(msg.data);
    18. }
    19. int m = 0;
    20. void chatterCallbackjoint(const Leizhuo_UnderWaterHexapodRobot::joint& hexapod_joint) {
    21. TFT.fillScreen(TFT_BLACK);
    22. // for(int i=0;i<2;i++)
    23. // {
    24. // for(int j=0;j<3;j++)
    25. // {
    26. // TFT.setCursor(j*70, i*20, 4);
    27. // // Set the font colour to be white with a black background
    28. // TFT.setTextColor(TFT_WHITE, TFT_BLACK);
    29. // // We can now plot text on screen using the "print" class
    30. // TFT.println(hexapod_joint.position[i*3+j]);
    31. // }
    32. // }
    33. // TFT.setCursor(0, 0, 4);
    34. // // Set the font colour to be white with a black background
    35. // TFT.setTextColor(TFT_WHITE, TFT_BLACK);
    36. // // We can now plot text on screen using the "print" class
    37. // TFT.println(hexapod_joint.position[0]);
    38. TFT.setCursor(80, 0, 4);
    39. // Set the font colour to be white with a black background
    40. TFT.setTextColor(TFT_WHITE, TFT_BLACK);
    41. // We can now plot text on screen using the "print" class
    42. TFT.println(hexapod_joint.position[1]);
    43. }
    44. ros::NodeHandle nh;
    45. std_msgs::String str_msg;
    46. ros::Publisher chatter("gun", &str_msg);
    47. ros::Subscriber<Leizhuo_UnderWaterHexapodRobot::joint> subjoint("/hexapod_joint", chatterCallbackjoint);
    48. ros::Subscriber<std_msgs::String> sub("/chatter", chatterCallback);
    49. char hello[13] = "gunnimade!";
    50. void setup()
    51. {
    52. nh.initNode();
    53. nh.advertise(chatter);
    54. nh.subscribe(sub);
    55. nh.subscribe(subjoint);
    56. TFT.init();
    57. TFT.setRotation(3);
    58. TFT.fillScreen(TFT_BLACK);
    59. TFT.initDMA();
    60. TFT.setCursor(0, 0, 4);
    61. // Set the font colour to be white with a black background
    62. TFT.setTextColor(TFT_WHITE, TFT_BLACK);
    63. // We can now plot text on screen using the "print" class
    64. TFT.println("Initialised default\n");
    65. }
    66. void loop()
    67. {
    68. // str_msg.data = hello;
    69. // chatter.publish( &str_msg );
    70. nh.spinOnce();
    71. // time_s = millis();
    72. delay(10);
    73. }

  • 相关阅读:
    jmeter 主从配置
    微信小程序2022年发展方向曝光
    “下一个江小白”靠什么成就?
    Visual Studio 2022下载安装的详细步骤-----C语言编辑器
    【JVM】运行时数据区之 堆——自问自答
    静态ip详解
    虹科工业树莓派应用案例之在石油开采中的应用
    数据结构之——栈的操作讲解与功能实现
    c# winform程序,DispatcherTimer被调用延迟,响应间隔长
    Python简介-Python3及环境配置
  • 原文地址:https://blog.csdn.net/qqliuzhitong/article/details/126861216