Skip to content

Instantly share code, notes, and snippets.

@dbaldwin
Last active September 14, 2023 19:27
Show Gist options
  • Save dbaldwin/78c39f866703470c4052c3199f7a83a6 to your computer and use it in GitHub Desktop.
Save dbaldwin/78c39f866703470c4052c3199f7a83a6 to your computer and use it in GitHub Desktop.
# Update CMakeLists in ~/catkin_ws/src/unitree_ros/unitree_controller
catkin_install_python(PROGRAMS scripts/joint_mover.py
DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION}
)
#!/usr/bin/env python
import rospy
from sensor_msgs.msg import JointState
from std_msgs.msg import Header
import math
def mover():
pub = rospy.Publisher('joint_states', JointState, queue_size=10)
rospy.init_node('joint_state_publisher')
rate = rospy.Rate(10) # 10hz
current = 0
max = 0.86
increment = 0.01
sign = 1
while not rospy.is_shutdown():
js = JointState()
js.header = Header()
js.header.stamp = rospy.Time.now()
js.name = ['FR_hip_joint', 'FR_thigh_joint', 'FR_calf_joint', 'FL_hip_joint', 'FL_thigh_joint', 'FL_calf_joint', 'RR_hip_joint', 'RR_thigh_joint', 'RR_calf_joint', 'RL_hip_joint', 'RL_thigh_joint', 'RL_calf_joint']
FR_hip_position = current + increment * sign
current = FR_hip_position
if (current > max):
sign = -1
elif (current < max * -1):
sign = 1
js.position = [FR_hip_position, 0, -1.853, 0, 0, -1.853, 0, 0, -1.853, 0, 0, -1.853]
js.velocity = []
js.effort = []
pub.publish(js)
rate.sleep()
if __name__ == '__main__':
try:
mover()
except rospy.ROSInterruptException:
pass
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment