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

云迹机器人底盘调用

云迹机器人底盘调用还是比较友好的,就是纯socket收发指令就能实现,今天实现一个底盘移动到指定点位功能。底盘的默认IP是192.168.10.10通讯端口是31001,测试机与底盘接入统一网络后直接发指令即可。本文给出两种语言调用源码,选择一种使用即可。

python调用源码:

import socket
import jsonyunji_ip = "192.168.10.10"#设定地盘ip地址,需要根据机器人实际ip地址修改#底盘-移动到指定为止
def YunjiGo(target):print(f"---------------------YunjiGo:{target}---------------------")port = 31001command = "/api/move?marker=" + target + "&distance_tolerance=0&theta_tolerance=0"client = socket.socket()client.connect((yunji_ip, port))print(f"command:{command}")client.send(command.encode())while True:try:data = client.recv(1024)if not data:print("Socket closed by peer.")return Nonestr_data = data.decode('utf-8')split_data = [s for s in str_data.split('\n') if s]for s in split_data:try:json_data = json.loads(s)print(json_data.get("description"))# 检查条件:任务完成且目标匹配if (json_data.get("description") == "The move task is finished."and "data" in json_dataand "target" in json_data["data"]and json_data["data"]["target"] == target):print("Task finished successfully!")client.close()  # 关闭 socketreturn True     # 返回成功except json.JSONDecodeError:print("Invalid JSON data, continue waiting...")continueexcept socket.timeout:print("Timeout reached, no matching data received.")return Noneexcept Exception as e:print(f"Error occurred: {e}")client.close()  # 确保异常时关闭 socketreturn None
YunjiGo("huahua")#移动到点位huahua

JAVA调用源码:(需要下载org.json-20161124.jar)

package examples;
import java.io.*;
import java.net.*;
import org.json.JSONObject;
import org.json.JSONException;/*
依赖安装:
sudo apt update
sudo apt install language-pack-zh-hans  # 简体中文
sudo apt install fonts-noto-cjk        # 中文字体
sudo apt install default-jdk*///make:
/*
cd /home/java
javac -encoding UTF-8 -cp .:\
org.json-20161124.jar \
examples/RobotControl.java
*/
//run : 
/*
cd /home/java
java -Dfile.encoding=UTF-8 -cp .:\
org.json-20161124.jar \
examples.RobotControl
*/public class RobotControl {String yunji_ip  = "192.168.10.10";  // 底盘ip地址int yunji_port = 31001;//底盘通讯端口private static RobotControl mInstance =null;public static synchronized RobotControl getInstance() {if (mInstance == null) {mInstance = new RobotControl();}return mInstance;}//底盘移动public void YunjiGo(String target) throws Exception{String command = "/api/move?marker=" + target + "&distance_tolerance=0.01&theta_tolerance=0.01";try {Socket client = new Socket(yunji_ip, yunji_port);//System.out.println("command:" + command);OutputStream out = client.getOutputStream();out.write(command.getBytes());out.flush();InputStream in = client.getInputStream();BufferedReader reader = new BufferedReader(new InputStreamReader(in));String strData;while ((strData = reader.readLine()) != null) {//System.out.println("strData:" + strData);try {JSONObject jsonData = new JSONObject(strData);System.out.println(jsonData.optString("description"));// 检查条件:任务完成且目标匹配if (jsonData.optString("description").equals("The move task is finished.")&& jsonData.has("data")&& jsonData.getJSONObject("data").has("target")&& jsonData.getJSONObject("data").getString("target").equals(target)) {System.out.println("Task finished successfully!");client.close(); // 关闭 socketreturn;    // 返回成功}} catch (JSONException e) {System.out.println("Invalid JSON data, continue waiting...");continue;}}throw new Exception("Socket closed by peer.");} catch (SocketTimeoutException e) {throw new Exception("Timeout reached, no matching data received.");} catch (Exception e) {throw new Exception("Error occurred: " + e.getMessage());}}public static void main(String[] args) {  RobotControl robotControl = RobotControl.getInstance();try{System.out.println("------------YunjiGo------------");robotControl.YunjiGo("huahua");} catch (Exception e) {System.out.println("YunjiGo Error occurred: " + e.getMessage());}System.out.println();}
}

运行输出:


------------YunjiGo------------The move task is started.
Start to leave charging pile..
Charge status off.
Succeed to leave charging pile.
traffic turn right.
traffic turn right.
The move task is finished.
Task finished successfully!

http://www.xdnf.cn/news/8746.html

相关文章:

  • 从AD9361 到 ADSY1100 ,中间的迭代产品历史
  • 软考 系统架构设计师系列知识点之杂项集萃(73)
  • 【MPC控制 - 从ACC到自动驾驶】5. 融会贯通:MPC在ACC中的优势总结与知识体系构建
  • 云手机是什么?哪个云手机便宜好用,掌派云手机流畅不卡顿
  • 前端垫片chimp
  • 贪心算法应用:Ford-Fulkerson最大流问题详解
  • 【C语言干货】free细节
  • 弦序参量(SOP)
  • 【MySQL】第10节|MySQL全局优化与Mysql 8.0新增特性详解
  • 【图像大模型】ControlNet:深度条件控制的生成模型架构解析
  • 如何确定是不是一个bug?
  • 深入理解Istio:全面解析与实践指南
  • Java 学习笔记:注解、泛型与 IO 流
  • 线性代数之张量计算,支撑AI算法的数学原理
  • 神经正切核推导(2)
  • DeepSeek联网Google搜索引擎
  • Windows端的C函数setlocale、printf与wprintf打印中文字符谜局小解
  • 深入浅出IIC协议 - 从总线原理到FPGA实战开发 -- 第六篇:AXI4-Lite桥接设计
  • 金众诚业财一体化解决方案如何提升项目盈利能力?
  • 国际荐酒师(香港)协会亮相新西兰葡萄酒巡展深度参与赵凤仪大师班
  • 《数据结构》系列笔记|附扫描手写笔记 1.0开篇-数据结构在学什么?
  • 【八股战神篇】操作系统高频面试题
  • Markdown 到 LaTeX:Overleaf 学习笔记
  • 华为OD机试真题——欢乐周末 (2025B卷:200分)Java/python/JavaScript/C/C++/GO最佳实现
  • 《深入探秘:从底层搭建Python微服务之FastAPI与Docker部署》
  • 在Linux下用GPIO模拟I2C通信(软件)
  • 前端流行框架Vue3教程:26. 异步组件
  • [医学影像 AI] 使用 PyTorch 和 MedicalZooPytorch 实现 3D 医学影像分割
  • xss-labs第15关
  • 历年华中科技大学保研上机真题