Baxter机器人末端轨迹坐标采集和轨迹还原

  • 采集命令
    • 代码
    • 生成
    • 轨迹还原
    • 代码
      • 参考

采集命令

rosrun baxter_moveit_config endpoint_recorder.py -f filename #此处filename为要保存的文件名,后面还可加上采集频率,但是采集频率过高会造成在轨迹复原的时候,机械臂抖动的特别厉害,建议20HZ就可以

代码

#!/usr/bin/env python
import argparse
import rospy
import baxter_interface
from baxter_interface import CHECK_VERSION
class JointRecorder(object):def __init__(self, filename, rate):"""Records joint data to a file at a specified rate."""self._filename = filenameself._raw_rate = rateself._rate = rospy.Rate(rate)self._start_time = rospy.get_time()self._done = Falseself._limb_left = baxter_interface.Limb("left")self._limb_right = baxter_interface.Limb("right")def _time_stamp(self):return rospy.get_time() - self._start_timedef stop(self):"""Stop recording."""self._done = Truedef done(self):"""Return whether or not recording is done."""if rospy.is_shutdown():self.stop()return self._donedef record(self):if self._filename:joints_left = self._limb_left.joint_names()joints_right = self._limb_right.joint_names()with open(self._filename, 'w') as f:f.write('time,')f.write(','.join([j for j in joints_left]) + ',')f.write(','.join([j for j in joints_right]) + '\n')while not self.done():current_pose = self._limb_left.endpoint_pose()endpoint_pose_position_left = [current_pose['position'].x,current_pose['position'].y,current_pose['position'].z]endpoint_pose_orientation_left = [current_pose['orientation'].x,current_pose['orientation'].y,current_pose['orientation'].z,current_pose['orientation'].w,]current_pose = self._limb_right.endpoint_pose()                      endpoint_pose_position_right = [current_pose['position'].x,current_pose['position'].y,current_pose['position'].z,]endpoint_pose_orientation_right = [current_pose['orientation'].x,current_pose['orientation'].y,current_pose['orientation'].z,current_pose['orientation'].w,]                     f.write("%f," % (self._time_stamp(),))f.write(','.join([str(x) for x in endpoint_pose_position_left]) + ',')f.write(','.join([str(x) for x in endpoint_pose_position_right]) + ',')f.write(','.join([str(x) for x in endpoint_pose_orientation_left]) + '\n')f.write(','.join([str(x) for x in endpoint_pose_orientation_right]) + '\n')self._rate.sleep()
def main():epilog = """
Related examples:joint_position_file_playback.py; joint_trajectory_file_playback.py."""arg_fmt = argparse.RawDescriptionHelpFormatterparser = argparse.ArgumentParser(formatter_class=arg_fmt,description=main.__doc__,epilog=epilog)required = parser.add_argument_group('required arguments')required.add_argument('-f', '--file', dest='filename', required=True,help='the file name to record to')parser.add_argument('-r', '--record-rate', type=int, default=20, metavar='RECORDRATE',help='rate at which to record (default: 100)')args = parser.parse_args(rospy.myargv()[1:])print("Initializing node... ")rospy.init_node("rsdk_joint_recorder")print("Getting robot state... ")rs = baxter_interface.RobotEnable(CHECK_VERSION)print("Enabling robot... ")rs.enable()Recorder = JointRecorder(args.filename, args.record_rate)rospy.on_shutdown(Recorder.stop)print("Recording. Press Ctrl-C to stop.")Recorder.record()print("\nDone.")
if __name__ == '__main__':main()

生成

ubuntu下生成的是txt文件,画图需要转化为csv。

图片:

轨迹还原

调用方式为:

调用命令:rosrun baxter_moveit_config endpoint_trajectory_playback.py -f filename joint_states:=/robot/joint_states #此处filename为存储的末端轨迹数据的文件名

代码

#!/usr/bin/env python
import rospy,sys
import argparse
import moveit_commander
import numpy as np
from geometry_msgs.msg import PoseStamped,Pose
from moveit_commander import MoveGroupCommander
import time
from copy import deepcopy
from os import path
class MoveItDemo:def __init__ (self):moveit_commander.roscpp_initialize(sys.argv)self.left_arm  = moveit_commander.MoveGroupCommander( 'left_arm')self.right_arm = moveit_commander.MoveGroupCommander('right_arm')self.right_eef = self.right_arm.get_end_effector_link()self.left_eef = self.left_arm.get_end_effector_link()self.right_arm.allow_replanning(True)self.left_arm.allow_replanning(True)self.right_arm.set_goal_position_tolerance(0.5)self.right_arm.set_goal_orientation_tolerance(0.5)self.left_arm.set_goal_position_tolerance(0.1)self.left_arm.set_goal_orientation_tolerance(0.1)self.left_arm.set_planning_time(5)self.right_arm.set_planning_time(5)def execute(self,filename):with open(filename, 'r') as f:lines = f.readlines()waypoints1 = []waypoints2 = []waypoints_l_start = []waypoints_r_start = []i = 1for idx, values in enumerate(lines[1:]):print "Line:\n", ii = i + 1if i == len(lines):breakvalues = values.rstrip().split(',')values = [float(x) for x in values]print valuesif idx == 0:print idxstart_pose1 = self.left_arm.get_current_pose(self.left_eef).posewpose1 = deepcopy(start_pose1)wpose1.position.x = values[1]wpose1.position.y= values[2]wpose1.position.z = values[3]wpose1.orientation.x = values[7]wpose1.orientation.y = values[8]wpose1.orientation.z = values[9]wpose1.orientation.w = values[10]start_pose2 = self.right_arm.get_current_pose(self.right_eef).posewpose2 = deepcopy(start_pose2)wpose2.position.x = values[4]wpose2.position.y = values[5]wpose2.position.z = values[6]wpose2.orientation.x = values[11]wpose2.orientation.y = values[12]wpose2.orientation.z = values[13]wpose2.orientation.w = values[14]waypoints_l_start.append(deepcopy(start_pose1))waypoints_l_start.append(deepcopy(wpose1))waypoints_r_start.append(deepcopy(start_pose2))waypoints_r_start.append(deepcopy(wpose2))wpose1.position.x = values[1]wpose1.position.y = values[2]wpose1.position.z = values[3]wpose1.orientation.x = values[7]wpose1.orientation.y = values[8]wpose1.orientation.z = values[9]wpose1.orientation.w = values[10]waypoints1.append(deepcopy(wpose1))wpose2.position.x = values[4]wpose2.position.y = values[5]wpose2.position.z = values[6]wpose2.orientation.x = values[11]wpose2.orientation.y = values[12]wpose2.orientation.z = values[13]wpose2.orientation.w = values[14]waypoints2.append(deepcopy(wpose2))print "To start pose\n"(cartesian_plan_l,fraction) = self.left_arm.compute_cartesian_path(waypoints_l_start,0.01, 0.0, True)self.left_arm.execute(cartesian_plan_l)(cartesian_plan_r,fraction) = self.right_arm.compute_cartesian_path(waypoints_r_start,0.01, 0.0, True)self.right_arm.execute(cartesian_plan_r)rospy.sleep(3)print "start playback\n"(cartesian_plan_l,fraction) = self.left_arm.compute_cartesian_path(waypoints1,0.01, 0.0, True)self.left_arm.execute(cartesian_plan_l)(cartesian_plan_r,fraction) = self.right_arm.compute_cartesian_path(waypoints2,0.01, 0.0, True)self.right_arm.execute(cartesian_plan_r)rospy.sleep(3)print("Done.")moveit_commander.roscpp_shutdown()moveit_commander.os._exit(0)
def main():print("Initializing node... ")rospy.init_node('moveit_demo')rospy.sleep(1)epilog = """
Related examples:joint_recorder.py; joint_position_file_playback.py."""arg_fmt = argparse.RawDescriptionHelpFormatterparser = argparse.ArgumentParser(formatter_class=arg_fmt,description=main.__doc__,epilog=epilog)parser.add_argument('-f', '--file', metavar='PATH', required=True,help='path to input file')args = parser.parse_args(rospy.myargv()[1:])moveit = MoveItDemo()moveit.execute(path.expanduser(args.file))
if __name__ == "__main__":main()

参考

[1]: 链接: link.

【Baxter机器人末端轨迹坐标采集和轨迹还原】相关推荐

  1. ros moveit进行机器人末端轨迹移动

    ros moveit进行机器人末端轨迹移动 参考链接: ROS moveit 机械臂笛卡尔空间运动 ROS moveit 机械臂逆运动 机械臂末端直线运动: #!/usr/bin/env python ...

  2. matlab如何看机器人末端坐标,关于RobotStudio中机器人末端位置的MATLAB仿真验证

    关于RobotStudio中机器人末端位置的MATLAB仿真验证 最近事情贼多,感觉有点乏力. 主要是最近在着手写一篇关于机器人轨迹规划的文章.随之而来的,当然是一堆的仿真,以及实验平台的搭建,还要想 ...

  3. 遨博协作机器人ROS开发 - 机械臂复杂轨迹规划

    目录 一.简介 二.环境版本 三.学习目标 四.知识储备 五.任务实施 六.任务拓展 七.课堂小结 八.课后练习 一.简介 大家好,欢迎关注遨博学院带来的系列技术分享文章(协作机器人ROS开发),今天 ...

  4. Matlab机械臂综合仿真平台,包含运动学、动力学和控制。 MATLAB机器人仿真正逆运动学simulink轨迹规划 机械臂动力学控制等

    Matlab机械臂综合仿真平台,包含运动学.动力学和控制. MATLAB机器人仿真正逆运动学simulink轨迹规划 机械臂动力学控制等 gui控制仿真平台PUMA机器人 robotics toolb ...

  5. 地理围栏 | EXCEL表格中分析轨迹坐标是否在设定的围栏范围内

    1 前言 地理围栏(Geo-fencing)是LBS的一种新应用,就是用一个虚拟的栅栏围出一个虚拟地理边界.当手机进入.离开某个特定地理区域,或在该区域内活动时,手机可以接收自动通知和警告.有了地理围 ...

  6. 【四足机器人】学习笔记 足端轨迹规划和步态规划

    [四足机器人]学习笔记 足端轨迹规划和步态规划 一.足端轨迹规划(摆线) 二.步态规划 1.Walk步态 2.Trot步态 近期,博主在古月居学习关于四足机器人的相关部分知识,从阳炼老师的四足机器人控 ...

  7. LiveGBS国标GB/T28181国标平台功能-电子地图移动位置订阅mobileposition地图定位GPS轨迹坐标位置获取redis获取位置

    LiveGBS国标GB/T28181国标平台功能-电子地图移动位置订阅mobileposition地图定位GPS轨迹坐标位置获取redis获取位置 1.位置订阅 1.1.国标设备编辑 1.2.选择设备 ...

  8. python 轨迹预测_CVPR 2019轨迹预测竞赛冠军方法总结

    背景 CVPR 2019 是机器视觉方向最重要的学术会议,本届大会共吸引了来自全世界各地共计 5160 篇论文,共接收 1294 篇论文,投稿数量和接受数量都创下了历史新高,其中与自动驾驶相关的论文. ...

  9. matlab 根轨迹 虚轴交点,根轨迹与虚轴的交点.ppt

    根轨迹与虚轴的交点.ppt 第八.九周实验安排 第8周 时间待定 第9周 时间待定 设一单位反馈控制系统的开环传递函数为: ,绘制该系统的根轨迹. 4.分离点: 得: 5.与虚轴交点: School ...

最新文章

  1. 用户 'IIS APPPOOL\**' 登录失败的解决方案(项目部署到本地IIS上打开网页出现报错)...
  2. html 播放远程视频教程,视频基于HTML5的服务器远程访问工具
  3. 利用IPFS构建自己的去中心化分布式Wiki系统
  4. Mysql8.0可以使用解压版 这个比较快 好像现在都是解压版了
  5. 小组站立会议之冲次会议2
  6. php中glob怎么用,如何在php中利用glob函数对文件进行遍历
  7. 布比Code Review赏金计划正式启动 让区块链回归代码本身
  8. java全局变量和局部变量_Java 10:局部变量类型推断
  9. 工具使用教程(三)【Anaconda虚拟环境下使用Juypter Notebook】
  10. ppt设置外观样式_ppt设置主题样式的方法步骤详解
  11. 通用的业务编码规则设计实现
  12. 关于 Android 8.0 gts 的 widevine 类问题 GtsMediaTestCases / GtsExoPlayerTestCases
  13. Linux下载Mysql
  14. debian系统离线安装iperf2
  15. ps2键盘测试软件,PS2键盘51测试程序1
  16. LINK : fatal error LNK1561和LINK : fatal error LNK1168:解决方法
  17. java设计模式---创建者模式
  18. 【codeforces 760B】Frodo and pillows
  19. GSMA TAC核发及IMEI编码规则
  20. 如何在word中打带矩形的√

热门文章

  1. 计算机语言学翁富良,形式语言与自动机的关系.doc
  2. 韩KakaoPay移动支付系统问世 仅支持安卓用户
  3. 魔兽怀旧服api文档位置
  4. 去除IOS升级提示小红点
  5. 类脑科学实验(三)——Hebb学习
  6. 北大核心2020_上清华也能选修北大课程?是的!清华北大互相开放部分本科课程...
  7. STM32(基于HAL库)驱动0.96寸OLED屏幕(六脚)
  8. java代码实现excel文件数据导入
  9. 按以下规律将电文变成密码,将字母A变成E,a变成e,即变成其后的第四个字母
  10. 中英文说明书丨 AbFluor 488 细胞凋亡检测试剂盒