ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange |
1 | initial version |
Here is a solution by using /joint_states topic
the Arduino subscribes to this topic and controls 5 servo motors in this example
https://github.com/smart-methods/arduino_robot_arm_gripper/blob/main/arduino_code/arduino_code.ino
this a python code publishes to /joint_states topic
#!/usr/bin/env python
import rospy
from sensor_msgs.msg import JointState
from std_msgs.msg import Header
def talker():
pub = rospy.Publisher('joint_states', JointState, queue_size=10)
rospy.init_node('joint_state_publisher')
rate = rospy.Rate(10) # 10hz
joints_str = JointState()
joints_str.header = Header()
joints_str.header.stamp = rospy.Time.now()
joints_str.name = ['base_joint', 'shoulder', 'elbow', 'wrist', 'gripper']
joints_str.position = [0.5, 0.5, 0.5, 0.5, 0.0]
while not rospy.is_shutdown():
joints_str.header.stamp = rospy.Time.now()
pub.publish(joints_str)
rospy.loginfo("position updated")
rate.sleep()
if __name__ == '__main__':
try:
talker()
except rospy.ROSInterruptException:
pass
2 | No.2 Revision |
Here is a solution by using /joint_states topic
the Arduino subscribes to this topic and controls 5 servo motors in this example
https://github.com/smart-methods/arduino_robot_arm_gripper/blob/main/arduino_code/arduino_code.ino
this a python code publishes to /joint_states topic
#!/usr/bin/env python
import rospy
from sensor_msgs.msg import JointState
from std_msgs.msg import Header
def talker():
pub = rospy.Publisher('joint_states', JointState, queue_size=10)
rospy.init_node('joint_state_publisher')
rate = rospy.Rate(10) # 10hz
joints_str = JointState()
joints_str.header = Header()
joints_str.header.stamp = rospy.Time.now()
joints_str.name = ['base_joint', 'shoulder', 'elbow', 'wrist', 'gripper']
joints_str.position = [0.5, 0.5, 0.5, 0.5, 0.0]
while not rospy.is_shutdown():
joints_str.header.stamp = rospy.Time.now()
pub.publish(joints_str)
rospy.loginfo("position updated")
rate.sleep()
if __name__ == '__main__':
try:
talker()
except rospy.ROSInterruptException:
pass