首页 > 系统相关 >ROS2在MyCobot320Pi2022和PC之间通讯(都是Ubuntu20.04系统)

ROS2在MyCobot320Pi2022和PC之间通讯(都是Ubuntu20.04系统)

时间:2024-10-28 11:49:24浏览次数:7  
标签:Ubuntu20.04 control MyCobot320Pi2022 self robot coordinates PC ------

参考:

  1. Running ROS across multiple machines http://wiki.ros.org/ROS/Tutorials/MultipleMachines
  2. SLAM+语音机器人DIY系列:(五)树莓派3开发环境搭建——4.PC端与robot端ROS网络通信 https://www.cnblogs.com/hiram-zhang/p/10410168.html
  3. 在多台PC上进行ROS通讯(在多台远程机器人或电脑上运行ROS)-学习笔记 https://blog.51cto.com/u_12369060/5172376
  4. [基于ROS构建移动机器人]第二篇:设置ROS主从网络和远程开发环境 https://zhuanlan.zhihu.com/p/52005221/

示例代码:使用PC驱动Raspberry机械臂,并以10Hz的频率发布机械臂末端法兰盘相对于基座坐标系的坐标:

------ Notes ------
Aim to control and monitor robot arm (MyCobot320pi2022) through PC. Both with Ubuntu 20.04 and ROS 2 Galactic installed.
The command comes from the MECHREV computer (PC), whose hostname is `zsfmec`. IP: 192.168.117.142, passcode:zsf2603
The executor is Raspberry with hostname `er`. IP: 192.168.117.179, passcode: 123

------ Topic list defined in this packgae ------
1. /robot_arm/coordinates
2. 
3. 



------ Usage ------
1. Connect the two devices in the same WiFi: phone hotspot called: Redmi K40, passcode: zsf20220912
2. Raspberry: open the folder ~/Desktop/pymycobot/demo in terminal, and execute:
    `python3 Server.py`, press Enter
    open another terminal inside the folder ~/Desktop/pymycobot/demo, and execute:
    `python3 Server1.py`, press Enter
3. PC: 
    open a terminal and run /home/zsfmec/ros2_ws/src/robot_control/robot_control/coordinate_publisher.py
    open another terminal and run /home/zsfmec/ros2_ws/src/robot_control/robot_control/actuate_robot.py

------ 我的笔记 ------
PC与MyCobot通讯可以参考我的CSDN的文章: https://blog.csdn.net/weixin_42776565/article/details/137049334

/home/zsfmec/ros2_ws/src/robot_control/robot_control/coordinate_publisher.py

#!/usr/bin/env python3
import rclpy
from rclpy.node import Node
from std_msgs.msg import Float32MultiArray  # Replace String with appropriate message type for coordinates
from pymycobot import MyCobotSocket  # Import the MyCobotSocket library for TCP/IP connection
import time

class CoordinatePublisher(Node):
    def __init__(self):
        super().__init__('coordinate_publisher')
        self.publisher_ = self.create_publisher(Float32MultiArray, '/robot_arm/coordinates', 10)
        self.timer = self.create_timer(0.1, self.publish_coordinates)  # 0.1 seconds corresponds to 10Hz
        
        # Initialize MyCobotSocket connection to the robot arm
        self.tcp_ip = '192.168.117.179'  # Replace with the IP address of the robot arm
        self.tcp_port = 9000  # Default MyCobot port
        
        try:
            self.mc = MyCobotSocket(self.tcp_ip, self.tcp_port)
            self.get_logger().info('Connected to robot arm via TCP/IP')
        except Exception as e:
            self.get_logger().error(f'Failed to connect to robot arm: {e}')

    def publish_coordinates(self):
        try:
            # Request angles from the robot arm via TCP/IP
            coords = self.mc.get_coords()  # Get the end-effector coordinates
            if coords:
                msg = Float32MultiArray()  # Using Float32MultiArray to hold coordinate values
                msg.data = coords
                self.publisher_.publish(msg)
                self.get_logger().info(f'Publishing coordinates: {coords}')
        except Exception as e:
            self.get_logger().error(f'Failed to get coordinates: {e}')


def main(args=None):
    rclpy.init(args=args)
    node = CoordinatePublisher()
    rclpy.spin(node)
    node.destroy_node()
    rclpy.shutdown()

if __name__ == '__main__':
    main()

/home/zsfmec/ros2_ws/src/robot_control/robot_control/actuate_robot.py

from pymycobot import MyCobotSocket
import time
#其中"192.168.11.15"为机械臂IP,请自行输入你的机械臂IP
mc = MyCobotSocket("192.168.117.179",9001)  

#连接正常就可以对机械臂进行控制操作
mc.send_angles([0,0,0,0,0,0],20)
time.sleep(3)
mc.send_angles([30,20,0,0,0,0],20)
time.sleep(3)
mc.send_angles([0,0,0,0,0,0],20)
time.sleep(3)
mc.send_angles([-30,-20,0,0,0,0],20)
time.sleep(3)

image

image

标签:Ubuntu20.04,control,MyCobot320Pi2022,self,robot,coordinates,PC,------
From: https://www.cnblogs.com/zhengshufang/p/18502589

相关文章

  • 新安装的Ubuntu20.04 系统没有声音怎么办?
    问题描述:新安装的Ubuntu20.04系统没有声音怎么办?问题解答:第一步,下载pavucontrol音频播放工具。sudoaptinstallpavucontrol第二步、设置工具。首先在配置里面将HDANVidia设置为关闭。(我的ubuntu安装时候汉化了,所以软件也是汉语,有的人可能是英文的)。其次,将内置音频......
  • 硬件开发笔记(三十一):TPS54331电源设计(四):PCB布板12V转5V电路、12V转3.0V和12V转4V电路
    前言  前面设计好了常用的12V转5V电路3A、12V转3.3V电路,不常用的12V转4V电路。  本篇描述PCB的设计布线,12V转5V电路、12V转3.3V电路,12V转4V电路。 前面输出的原理图   设计PCB步骤一:12V转5V电路PCB设计  先看原理图,注意元器件的编号:    ......
  • GBPC3510-ASEMI整流桥GBPC3510参数、封装、尺寸
    编辑:llGBPC3510-ASEMI整流桥GBPC3510参数、封装、尺寸型号:GBPC3510品牌:ASEMI封装:GBPC-4批号:2024+现货:50000+最大重复峰值反向电压:1000V最大正向平均整流电流(Vdss):35A功率(Pd):大功率芯片个数:4引脚数量:4安装方式:插件类型:插件方桥、整流桥正向浪涌电流IFSM:400A正向电......
  • PCL 计算点云重叠区域的均值标准差
    目录一、概述1.1原理1.2实现步骤1.3应用场景二、代码实现2.1关键函数2.1.1计算均值和标准差的函数2.2完整代码三、实现效果PCL点云算法汇总及实战案例汇总的目录地址链接:PCL点云算法与项目实战案例汇总(长期更新)一、概述        在点云配准中,评估配准......
  • PCL 获取对齐点云之间的差异
    目录一、概述1.1原理1.2实现步骤1.3应用场景二、代码实现2.1关键函数2.1.1提取差异点云的函数2.1.2点云可视化函数2.2完整代码三、实现效果3.1原始点云3.2处理后点云PCL点云算法汇总及实战案例汇总的目录地址链接:PCL点云算法与项目实战案例汇总(长期更新)一、......
  • PCL 基于Ransac提取误匹配点对
    目录一、概述1.1原理1.2实现步骤1.3应用场景二、代码实现2.1关键函数2.1.1基于RANSAC的误匹配点对提出函数2.1.2点云可视化函数2.2完整代码三、实现效果PCL点云算法汇总及实战案例汇总的目录地址链接:PCL点云算法与项目实战案例汇总(长期更新)一、概述    ......
  • BD82H61 BD82H61 SLJ4B Intel英特尔南桥芯片南桥主要是负责IO北桥用于CPU和内存、显卡
    Thecode"BD82H61SLJ4B"appearstobeaproductcodeormodelnumberforapieceofcomputerhardware.Itcouldbeamotherboardoraprocessor.Withoutmorecontext,itisdifficulttodeterminetheexactmeaningorspecificationsofthiscode......
  • 104. 相机控件MapControls
    地图导航相机控件MapControls,你可实现一个类似百度地图的3D导航功能。MapControls使用操作你可以打开课件案例源码测试下效果。平移:鼠标左键拖动旋转:鼠标右键拖动缩放:鼠标中键滚动引入相机控件MapControls引入相机控件MapControls类,旧版本是通过扩展库文件MapControls.js......
  • grpc的数据传输格式protobuf你了解吗?
    文章目录前言一、grpc为什么要选择protobuf?二、Varint编码2.1字节序2.2定长编码2.3变长编码2.4有符号数的编码三.EncodingTag例子解析字段嵌套的情况repeated字段注意四:Decoding参考资料总结前言本文档主要讲解protobuf中基础的编码规则。先整体描述protobuf数......
  • CSP-S2024&CCPC济南站游记
    初赛忘了,乱打的。得分-估分=\(13\),得分=\(79\)。Day-5忘了,打模拟赛被打爆。Day-4忘了,打模拟赛被打爆。Day-3忘了,打模拟赛被打爆。Day-2忘了,打模拟赛被打爆。我患上了一种只会做T1的病。晚上画画,CF啥都不会。Day-1和wmh坐上了一趟高铁。到了以后疯狂发徽章......