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

14 篇文章 17 订阅
11 篇文章 4 订阅

介绍

硬件平台

控制板:Baize_ServoDriver_esp32 

舵机机械臂:

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

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

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

https://github.com/Allen953/Leizhuo_UnderWaterHexapodRobot

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

代码 

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

/*
 * rosserial Publisher Example
 * Prints "hello world!"
 */
 

#include <ros.h>
#include <std_msgs/String.h>
#include "Leizhuo_UnderWaterHexapodRobot/joint.h"


#include <SPI.h>
#include <TFT_eSPI.h>       // Hardware-specific library
TFT_eSPI TFT = TFT_eSPI();  // Invoke custom library


void chatterCallback(const std_msgs::String& msg) {
//  TFT.fillScreen(TFT_BLACK);
  TFT.setCursor(0, 30, 4);
  // Set the font colour to be white with a black background
  TFT.setTextColor(TFT_WHITE, TFT_BLACK);

  // We can now plot text on screen using the "print" class
  TFT.println(msg.data); 
}

int m = 0;

void chatterCallbackjoint(const Leizhuo_UnderWaterHexapodRobot::joint& hexapod_joint) {
  
  TFT.fillScreen(TFT_BLACK);
//  for(int i=0;i<2;i++)
//  {
//    for(int j=0;j<3;j++)
//    {
//      TFT.setCursor(j*70, i*20, 4);
//      // Set the font colour to be white with a black background
//      TFT.setTextColor(TFT_WHITE, TFT_BLACK);
//      // We can now plot text on screen using the "print" class
//      TFT.println(hexapod_joint.position[i*3+j]);
//    }
//  }
//      TFT.setCursor(0, 0, 4);
//      // Set the font colour to be white with a black background
//      TFT.setTextColor(TFT_WHITE, TFT_BLACK);
//      // We can now plot text on screen using the "print" class
//      TFT.println(hexapod_joint.position[0]);

      TFT.setCursor(80, 0, 4);
      // Set the font colour to be white with a black background
      TFT.setTextColor(TFT_WHITE, TFT_BLACK);
      // We can now plot text on screen using the "print" class
      TFT.println(hexapod_joint.position[1]);
}

ros::NodeHandle  nh;

std_msgs::String str_msg;
ros::Publisher chatter("gun", &str_msg);
ros::Subscriber<Leizhuo_UnderWaterHexapodRobot::joint> subjoint("/hexapod_joint", chatterCallbackjoint);
ros::Subscriber<std_msgs::String> sub("/chatter", chatterCallback);
char hello[13] = "gunnimade!";

void setup()
{
  nh.initNode();
  nh.advertise(chatter);
  nh.subscribe(sub);
  nh.subscribe(subjoint);
  
  TFT.init();
  TFT.setRotation(3);
  TFT.fillScreen(TFT_BLACK);
  TFT.initDMA();
    
  TFT.setCursor(0, 0, 4);
  // Set the font colour to be white with a black background
  TFT.setTextColor(TFT_WHITE, TFT_BLACK);

  // We can now plot text on screen using the "print" class
  TFT.println("Initialised default\n"); 
}

void loop()
{
//    str_msg.data = hello;
//    chatter.publish( &str_msg );

    nh.spinOnce();
//    time_s = millis();  

  delay(10);
}

  • 1
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

Allen953

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

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

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

打赏作者

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

抵扣说明:

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

余额充值