forked from HBPNeurorobotics/hbpprak_2018_throwing
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrecord_cylinder.py
26 lines (22 loc) · 1.2 KB
/
record_cylinder.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# Imported Python Transfer Function
import numpy as np
import sensor_msgs.msg
@nrp.MapCSVRecorder("cylinder_recorder", filename="cylinder_position.csv",
headers=["Time", "py", "dist"])
@nrp.Robot2Neuron()
def record_cylinder (t,cylinder_recorder):
from rospy import ServiceProxy
from gazebo_msgs.srv import GetModelState, GetLinkState
from gazebo_msgs.msg import LinkState
model_name = 'cylinder'
state_proxy = ServiceProxy('/gazebo/get_model_state', GetModelState, persistent=False)
position_proxy = ServiceProxy('/gazebo/get_link_state', GetLinkState, persistent=False)
cylinder = state_proxy(model_name, "world")
hand = position_proxy('robot::hand_f2_link', 'world')
if cylinder.success and hand.success:
cylinder_position = np.array([cylinder.pose.position.x, cylinder.pose.position.y, cylinder.pose.position.z])
hand_position = np.array([hand.link_state.pose.position.x, hand.link_state.pose.position.y,hand.link_state.pose.position.z])
distance = np.linalg.norm(cylinder_position - hand_position)
cylinder_recorder.record_entry(t,
cylinder_position[1],
distance)