Skip to content

Commit 7c0bd34

Browse files
authored
dynamixel control
1 parent ccc3ef0 commit 7c0bd34

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

Scripts/subscriber.py

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#! /usr/bin/env python
2+
from std_msgs.msg import Int64
3+
import rospy
4+
from dynamixel_workbench_msgs.msg import DynamixelStateList
5+
from dynamixel_workbench_msgs.srv import DynamixelCommand,DynamixelCommandRequest
6+
7+
d=0
8+
position=0
9+
client=rospy.ServiceProxy('/dynamixel_workbench/dynamixel_command',DynamixelCommand)
10+
11+
def callback1(dir1):
12+
global d,position
13+
#rospy.loginfo(dir1.data)
14+
d=dir1.data
15+
# rospy.loginfo(d)
16+
req =DynamixelCommandRequest()
17+
req.id=50
18+
req.addr_name="Goal_Position"
19+
req.value=position+(d*200)
20+
rospy.loginfo(position+(d*200))
21+
resp=client(req)
22+
23+
def callback2(pos):
24+
global position
25+
rospy.loginfo(pos.dynamixel_state[2].present_position)
26+
position=(pos.dynamixel_state[2].present_position)
27+
rospy.loginfo(position)
28+
29+
def listener():
30+
rospy.init_node("Subscriber")
31+
rospy.Subscriber("/direction",Int64,callback1)
32+
rospy.Subscriber("/dynamixel_workbench/dynamixel_state",DynamixelStateList,callback2)
33+
34+
35+
36+
if __name__=="__main__":
37+
# while True:
38+
listener()
39+
rospy.spin()

0 commit comments

Comments
 (0)