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

“Hopf Oscillator-Based Gait Transition for A Quadruped Robot“代码复现

paper链接:https://ieeexplore.ieee.org/abstract/document/7090642/

import math
import numpy as np
import matplotlib.pyplot as plt# 设置中文显示
plt.rcParams['font.sans-serif'] = ['SimHei']  # 设置中文字体为黑体
plt.rcParams['axes.unicode_minus'] = False  # 解决负号'-'显示为方块的问题class CPG(object):def __init__(self, gait=0):self.gait_num = 3self.gait_names = ["Walk","Trot", "Pace", "Bound"]self.labels = ['FL', 'FR', 'HL', 'HR']# CPG构建基本参数self._alpha = 100self.leg_num = 4self.gait = gaitself.mu_ = -1self._a = 50self.u1 = 0self.u2 = 0# 负载系数对相关参数影响self.BEAT_ = [0.75, 0.5, 0.5, 0.5]self.period_ = [0.6, 0.5, 0.5, 0.4]self._beta = self.BEAT_[0]self._t = self.period_[0]# 时间self.t_step = 0.001self.point_x = np.zeros(self.leg_num)self.point_y = np.zeros(self.leg_num)self.PHASE = [[0 * 2 * np.pi, 0.5 * 2 * np.pi, 0.25 * 2 * np.pi, 0.75 * 2 * np.pi],[0 * 2 * np.pi, 0.5 * 2 * np.pi, 0.5 * 2 * np.pi, 0 * 2 * np.pi],[0 * 2 * np.pi, 0.5 * 2 * np.pi, 0 * 2 * np.pi, 0.5 * 2 * np.pi],[0 * 2 * np.pi, 0 * 2 * np.pi, 0.5 * 2 * np.pi, 0.5 * 2 * np.pi],]# 相对相位矩阵self.R_cell = np.zeros(shape=(self.leg_num, self.leg_num, 2, 2))self.Phi = None# 初始值,非0即可self.leg_x = Noneself.leg_y = Noneself.reset()# 计数,什么时候完成相位同步self.count_ = 0# 计数,什么时候结束步态转换self.t_count_ = 0self.init_phase()def init_phase(self):for _ in range(700):self.step()def reset(self):self._beta = self.BEAT_[self.gait]self._t = self.period_[self.gait]self.Phi = self.PHASE[self.gait]self.leg_x = np.ones(self.leg_num) * 0.0001self.leg_y = np.ones(self.leg_num) * 0.0001self.update_rotation_matrix()def next_gait(self):self.gait = (self.gait + 1) % self.gait_numself.reset()def update_rotation_matrix(self):        for i in np.arange(0, self.leg_num):for j in np.arange(0, self.leg_num):self.R_cell[j, i] = np.array([[np.cos(self.Phi[i] - self.Phi[j]), - np.sin(self.Phi[i] - self.Phi[j])],[np.sin(self.Phi[i] - self.Phi[j]), np.cos(self.Phi[i] - self.Phi[j])]])def transit_gait(self, tau=0):self.t_count_ = self.t_count_ + 1# 步态在一个周期内完成转换if tau == 0:# walk to trot# beta/φ2从0.75变换到0.5# walk步态周期为0.6,假设在1s内完成转换,共200步,每步变换1/800=0.00125transit_step = 0.00125self.Phi[0] = 0# self.Phi[1] = 0.5phi2_ = 0.75 - transit_step * self.t_count_self.Phi[2] = phi2_ * 2 * np.piself.Phi[3] = (phi2_ - 0.5) * 2 * np.pi# 更新占空比参数和周期参数self._beta = phi2_            else:# trot to gallop# φ1从0.5到0,0.5/200=1/400=0.0025transit_step = 0.0025phi1_ = 0.5 - transit_step * self.t_count_self.Phi[1] = phi1_ * 2 * np.piself.Phi[3] = (0.5 - phi1_) * 2 * np.piif self.t_count_ >= 200:self.t_count_ = 0if tau == 0:self._t = 0.5else:self._t = 0.4self.update_rotation_matrix()def step(self):if self.count_ > 400:self.mu_ = 1self.count_  = self.count_ + 1if self.count_ > 1200 and self.count_ <= 1400:self.transit_gait(tau=0)if self.count_ > 1800 and self.count_ <= 2000:self.transit_gait(tau=1)for _ in range(5):for i in np.arange(0, self.leg_num):r_pow = (self.leg_x[i] - self.u1) ** 2 + (self.leg_y[i] - self.u2) ** 2W = math.pi / (self._beta*self._t*(math.exp(-self._a*self.leg_y[i]) + 1)) + math.pi / ((1-self._beta)*self._t*(math.exp(self._a*self.leg_y[i]) + 1))V = np.matmul(np.array([[self._alpha * (self.mu_ - r_pow), - W], [W, self._alpha * (self.mu_ - r_pow)]]),np.array([[self.leg_x[i] - self.u1], [self.leg_y[i] - self.u2]])) + \np.matmul(self.R_cell[0, i], np.array([[self.leg_x[0] - self.u1], [self.leg_y[0] - self.u1]])) + \np.matmul(self.R_cell[1, i], np.array([[self.leg_x[1] - self.u2], [self.leg_y[1] - self.u2]])) + \np.matmul(self.R_cell[2, i], np.array([[self.leg_x[2] - self.u1], [self.leg_y[2] - self.u2]])) + \np.matmul(self.R_cell[3, i], np.array([[self.leg_x[3] - self.u1], [self.leg_y[3] - self.u2]]))self.leg_x[i] = self.leg_x[i] + V[0, 0] * self.t_stepself.leg_y[i] = self.leg_y[i] + V[1, 0] * self.t_stepfor i in range(0, self.leg_num):self.point_x[i] = self.leg_x[i]self.point_y[i] = self.leg_y[i]if self.leg_y[i] > 0:self.point_y[i] = 0else:self.point_y[i] = -self.leg_y[i]return np.concatenate([[h, k] for h, k in zip(self.point_x, self.point_y)])if __name__ == '__main__':cpg = CPG(0)step_num = 1800plt.rcParams.update({'font.size': 20})fig1 = plt.figure(figsize=(9, 6))plt.subplots_adjust(left=None, bottom=None, right=None, top=None, wspace=None, hspace=0.5)phases = np.stack(np.array([cpg.step() for _ in range(step_num)]), axis=1)ax = plt.subplot(4, 1, 1)leg_labels = ['FL', 'FR', 'HL', 'HR']for i in range(4):ax.plot(np.arange(0, step_num) * 0.005, phases[2 * i, :], linewidth=2, label=leg_labels[i])ax.set_xlim(0,step_num * 0.005)ax.legend(prop={'size': 14}, loc= 'lower right')plt.show()

代码实现了从静止到行走(walk)到小跑(trot)再到飞奔(gallop)步态的转换。具体实现细节和解释有时间再写👌。

 相关文章:raisimGymTorch的使用-CSDN博客

相关文章:

  • 致我的2023年——个人学年总结
  • 使用 Elasticsearch 和 OpenAI 构建生成式 AI 应用程序
  • HTTPS 的加密流程
  • 【跳槽须知】关于企业所签订的竞业协议你知道多少?
  • 2024年华为OD机试真题-螺旋数字矩阵-Java-OD统一考试(C卷)
  • Linux中ps/kill/execl的使用
  • FPS游戏框架漫谈第二十天
  • Redis面试题41
  • 2024美赛数学建模C题完整论文教学(含十几个处理后数据表格及python代码)
  • Golang数据库编程详解 | 深入浅出Go语言原生数据库编程
  • 关闭Ubuntu 默认开启的自动安全更新
  • easyexcel解析跨多行的数据
  • 【STL】list模拟实现
  • pnpm + vite 从外网迁移到内网环境开发
  • Netty连接通道中的Channel参数模型
  • 345-反转字符串中的元音字母
  • css的样式优先级
  • CSS进阶篇--用CSS开启硬件加速来提高网站性能
  • in typeof instanceof ===这些运算符有什么作用
  • Javascripit类型转换比较那点事儿,双等号(==)
  • JavaScript设计模式与开发实践系列之策略模式
  • JS基础之数据类型、对象、原型、原型链、继承
  • js算法-归并排序(merge_sort)
  • k8s如何管理Pod
  • MD5加密原理解析及OC版原理实现
  • Node + FFmpeg 实现Canvas动画导出视频
  • PV统计优化设计
  • python大佬养成计划----difflib模块
  • RxJS 实现摩斯密码(Morse) 【内附脑图】
  • vue中实现单选
  • 测试如何在敏捷团队中工作?
  • 关键词挖掘技术哪家强(一)基于node.js技术开发一个关键字查询工具
  • 快速体验 Sentinel 集群限流功能,只需简单几步
  • 猫头鹰的深夜翻译:Java 2D Graphics, 简单的仿射变换
  • 如何合理的规划jvm性能调优
  • 三分钟教你同步 Visual Studio Code 设置
  • 深入体验bash on windows,在windows上搭建原生的linux开发环境,酷!
  • 自动记录MySQL慢查询快照脚本
  • 组复制官方翻译九、Group Replication Technical Details
  • ​520就是要宠粉,你的心头书我买单
  • ​云纳万物 · 数皆有言|2021 七牛云战略发布会启幕,邀您赴约
  • # Swust 12th acm 邀请赛# [ K ] 三角形判定 [题解]
  • #### go map 底层结构 ####
  • #QT(智能家居界面-界面切换)
  • #鸿蒙生态创新中心#揭幕仪式在深圳湾科技生态园举行
  • #微信小程序:微信小程序常见的配置传值
  • (6)设计一个TimeMap
  • (C语言)逆序输出字符串
  • (MATLAB)第五章-矩阵运算
  • (附源码)springboot高校宿舍交电费系统 毕业设计031552
  • (九)One-Wire总线-DS18B20
  • (转)AS3正则:元子符,元序列,标志,数量表达符
  • (转)关于pipe()的详细解析
  • (转)人的集合论——移山之道
  • ****Linux下Mysql的安装和配置