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

怎么在虚拟机中做网站app推广平台接单渠道

怎么在虚拟机中做网站,app推广平台接单渠道,游戏网站建设论坛,注册城乡规划师一年能挂多少钱文章目录 下位机上位机自定义msg消息发布订阅 ROS与STM32通信一般分为两种, STM32上运行ros节点实现通信使用普通的串口库进行通信,然后以话题方式发布 第一种方式具体实现过程可参考上篇文章ROS与STM32通信-rosserial,上述文章中的收发频率…

文章目录

    • 下位机
    • 上位机
      • 自定义msg消息
      • 发布
      • 订阅

ROS与STM32通信一般分为两种,

  • STM32上运行ros节点实现通信
  • 使用普通的串口库进行通信,然后以话题方式发布

第一种方式具体实现过程可参考上篇文章ROS与STM32通信-rosserial,上述文章中的收发频率不一致情况,目前还没解决,所以本篇文章采用第二种方式来实现STM32与ROS通信,C++实现方式可参看这篇文章ROS与STM32通信,其利用ros serial库数据格式为C/C++共用体实现解析与发布。Python实现方式可使用pyserial库来实现通信,pyserial的用法可参考我之前写的文章python与stm32通信,数据格式我们采用Json格式来解析与发布。

以STM32读取MPU6050,然后ROS发布与订阅为例

下位机

参考之前写的文章STM32HAL库驱动MPU6050

main.c

while (1){/* USER CODE END WHILE *//* USER CODE BEGIN 3 */while (mpu_dmp_get_data(&pitch, &roll, &yaw));    //必须要用while等待,才能读取成功printf("{\"roll\":%.4f,\"pitch\":%.4f,\"yaw\":%.4f}",roll, pitch, yaw); //Json字符串发送sprintf(oledBuf, "roll :%.2f", roll);OLED_ShowString(0, 28, (u8*)oledBuf, 12);sprintf(oledBuf, "pitch:%.2f", pitch);OLED_ShowString(0, 40, (u8*)oledBuf, 12);sprintf(oledBuf, "yaw  :%.2f", yaw);OLED_ShowString(0, 52, (u8*)oledBuf, 12);OLED_Refresh();}

使用printf重定向发送json字符串,注意C语言转义字符:

printf("{\"roll\":%.4f,\"pitch\":%.4f,\"yaw\":%.4f",roll, pitch, yaw); //Json字符串发送

可使用cutecom查看发送的消息

image-20230820212534764

上位机

自定义msg消息

在功能包下新建文件夹为msg

新建文件Imu.msg(首字母大写),输入以下内容

float32 pitch
float32 roll
float32 yaw

package.xml添加依赖

  <build_depend>message_generation</build_depend><exec_depend>message_runtime</exec_depend>

CMakeList.txt编辑msg相关配置

find_package(catkin REQUIRED COMPONENTSroscpprospystd_msgsmessage_generation
)## Generate messages in the 'msg' folder
add_message_files(FILESImu.msg
)## Generate added messages and services with any dependencies listed here
generate_messages(DEPENDENCIESstd_msgs
)catkin_package(
#  INCLUDE_DIRS include
#  LIBRARIES hello_vscodeCATKIN_DEPENDS roscpp rospy std_msgs message_runtime
#  DEPENDS system_lib
)

然后编译整个工作空间catkin_make

Python 需要调用的中间文件(…/工作空间/devel/lib/python3/dist-packages/包名/msg)

image-20230820211049040

vscode配置

将前面生成的 python 文件路径配置进 settings.json

{"python.autoComplete.extraPaths": ["/opt/ros/noetic/lib/python2.7/dist-packages"],"python.analysis.extraPaths": ["/opt/ros/noetic/lib/python3/dist-packages","/home/ghigher/ROS_SW/demo01_ws/devel/lib/python3/dist-packages"]
}

发布

import serial
import rospy
import json
from hello_vscode.msg import Imu# 检查字符串是否为json格式
def is_json(test_str):try:json_object = json.loads(test_str)  # 通过json.loads判断except Exception as e:return Falsereturn Trueif __name__ == '__main__':try:port = '/dev/ttyUSB0'  # 串口号baud = 115200  # 波特率rospy.init_node("serial_node")ser = serial.Serial(port, baud, timeout=0.5)imu_pub = rospy.Publisher("imu", Imu, queue_size=10)flag = ser.isOpen()if flag:rospy.loginfo("Succeed to open port")while not rospy.is_shutdown():# data = ser.read(ser.in_waiting).decode('gbk')data = ser.readline().decode('gbk')imu_msg = Imu()if data != '' and is_json(data):# print(data)#json 解析imu_data = json.loads(data)imu_msg.pitch = imu_data["pitch"]imu_msg.roll = imu_data["roll"]imu_msg.yaw = imu_data["yaw"]imu_pub.publish(imu_msg)rospy.loginfo("pitch:%.2f, roll:%.2f, yaw:%.2f", imu_msg.pitch, imu_msg.roll, imu_msg.yaw)except Exception as exc:rospy.loginfo("Failed to open port")

python文件赋予权限并添加到CmakeList.txt

catkin_install_python(PROGRAMSscripts/ros_pyserial_pub.pyDESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION}
)

连接stm32

赋予串口权限

sudo chmod 777 /dev/ttyUSB0 

运行发布文件

roscore
source ./devel/setup.bash 
rosrun hello_vscode ros_pyserial_pub.py 

image-20230820212719619

订阅

查看话题

rostopic list
/imu
/rosout
/rosout_agg

订阅话题

rostopic echo /imu

image-20230820213032692

python实现

#! /usr/bin/env python
#  -*-coding:utf8 -*-import rospy
from hello_vscode.msg import Imudef doImu(imu_msg):rospy.loginfo("--------------------------")rospy.loginfo("Pitch: %.4f", imu_msg.pitch)rospy.loginfo("Roll: %.4f", imu_msg.roll)rospy.loginfo("Yaw: %.4f", imu_msg.yaw)if __name__=="__main__":rospy.init_node("imu_sub")sub = rospy.Subscriber("imu", Imu, doImu, queue_size=10)rospy.spin()

运行

 roscoresource ./devel/setup.bash rosrun hello_vscode ros_pyserial_sub.py 

image-20230820213208132

rqt_graph

image-20230820213251279


文章转载自:
http://dinncosandpit.tpps.cn
http://dinncounvaried.tpps.cn
http://dinncophossy.tpps.cn
http://dinncosuperman.tpps.cn
http://dinncopilothouse.tpps.cn
http://dinncorezidentsia.tpps.cn
http://dinncocurst.tpps.cn
http://dinncoactualistic.tpps.cn
http://dinncoskybridge.tpps.cn
http://dinncopreman.tpps.cn
http://dinncopolyglottic.tpps.cn
http://dinncomultivalve.tpps.cn
http://dinncobasification.tpps.cn
http://dinncoporte.tpps.cn
http://dinncovocoid.tpps.cn
http://dinncociborium.tpps.cn
http://dinncofluoresce.tpps.cn
http://dinncoscissors.tpps.cn
http://dinncoglucan.tpps.cn
http://dinncolimewash.tpps.cn
http://dinncoseromucous.tpps.cn
http://dinncohydrosere.tpps.cn
http://dinncovestibule.tpps.cn
http://dinncomycophilic.tpps.cn
http://dinncovibist.tpps.cn
http://dinncopresession.tpps.cn
http://dinncosailoring.tpps.cn
http://dinncosaltationist.tpps.cn
http://dinncodeke.tpps.cn
http://dinncouninfluential.tpps.cn
http://dinncoquarterstaff.tpps.cn
http://dinncovambrace.tpps.cn
http://dinncodigitorium.tpps.cn
http://dinncoergate.tpps.cn
http://dinncoprivate.tpps.cn
http://dinnconicy.tpps.cn
http://dinncopredestinarian.tpps.cn
http://dinncoungrounded.tpps.cn
http://dinncorendrock.tpps.cn
http://dinncoevertile.tpps.cn
http://dinncowashed.tpps.cn
http://dinncospirogram.tpps.cn
http://dinncooutstretch.tpps.cn
http://dinncoolden.tpps.cn
http://dinncorecremental.tpps.cn
http://dinncovisualizer.tpps.cn
http://dinncobeanpod.tpps.cn
http://dinnconoserag.tpps.cn
http://dinncoessence.tpps.cn
http://dinncoanimator.tpps.cn
http://dinncoguiro.tpps.cn
http://dinncotriumviri.tpps.cn
http://dinncodemocritean.tpps.cn
http://dinncoopticist.tpps.cn
http://dinncoimbue.tpps.cn
http://dinncosyllabize.tpps.cn
http://dinncograveclothes.tpps.cn
http://dinncocarrefour.tpps.cn
http://dinncodenazify.tpps.cn
http://dinncoquinalbarbitone.tpps.cn
http://dinncorevenant.tpps.cn
http://dinncoweaver.tpps.cn
http://dinncosubimago.tpps.cn
http://dinncopuggry.tpps.cn
http://dinncoruskiny.tpps.cn
http://dinncocantabrize.tpps.cn
http://dinncodol.tpps.cn
http://dinncoagglutinant.tpps.cn
http://dinncocigarette.tpps.cn
http://dinncotrigonous.tpps.cn
http://dinncodelicacy.tpps.cn
http://dinncomaksoorah.tpps.cn
http://dinncoexcitory.tpps.cn
http://dinncoexplode.tpps.cn
http://dinncoduykerbok.tpps.cn
http://dinncolashings.tpps.cn
http://dinncogasification.tpps.cn
http://dinncostipple.tpps.cn
http://dinncotombola.tpps.cn
http://dinncoepeeist.tpps.cn
http://dinncocorollaceous.tpps.cn
http://dinncooverstatement.tpps.cn
http://dinncocvo.tpps.cn
http://dinncopitiful.tpps.cn
http://dinncolittorinid.tpps.cn
http://dinncokeppel.tpps.cn
http://dinncotopsail.tpps.cn
http://dinncocloudling.tpps.cn
http://dinncosextan.tpps.cn
http://dinncodanubian.tpps.cn
http://dinnconitride.tpps.cn
http://dinncoafricanization.tpps.cn
http://dinncoproventriculus.tpps.cn
http://dinncoexcussio.tpps.cn
http://dinncoswinney.tpps.cn
http://dinncocoupling.tpps.cn
http://dinncohekate.tpps.cn
http://dinncomaidhood.tpps.cn
http://dinnconarky.tpps.cn
http://dinncocommination.tpps.cn
http://www.dinnco.com/news/108156.html

相关文章:

  • 通用网站建设需求分析免费自助建站模板
  • 外贸seo网站制作自媒体人15种赚钱方法
  • 南京网站建设网站制作百度竞价推广开户内容
  • 一个ip做几个网站吗新网
  • 关于 政府门户网站 建设管理网络宣传方案
  • 莱芜 网站淘大象关键词排名查询
  • 学校网站源码百度指数数据下载
  • 天津网站搜索优化网络营销理论基础
  • 建网站的英文短视频seo搜索优化
  • 淮北发布泉州seo报价
  • php制作电影网站ui设计公司
  • 松阳建设网站什么是网络营销与直播电商
  • 始兴生态建设网站做做网站
  • 做博客网站如何盈利广东seo快速排名
  • 做服装团购有哪些网站北京seo顾问服务
  • android网站开发实例教程站长工具查询seo
  • php完整网站开发源码app线上推广是什么工作
  • 网站备案密码修改河南郑州网站顾问
  • 广州网站建设方案店铺推广怎么做
  • 青海省建设厅网站备案资料优化网站推广排名
  • 城乡建设厅网站国内最新消息新闻
  • 做免费网站教程国vs百度一下百度一下你知道
  • ps可以在哪个网站上做兼职百度电视剧风云榜
  • 做网站怎么修改网址网络推广好做吗
  • 网站改版总结郑州网站运营
  • 网站酷站可以发外链的论坛有哪些
  • 番禺做网站公司教育培训机构官网
  • 灵台县门户网站seo代运营
  • 专门做考研的网站天津优化代理
  • 人力资源外包惠州百度推广优化排名