ROS kinetic, Ubuntu 16.04, Gazebo 7.0?
Gazebo 환경은 환경 내의 모든 물체들을 한번에 /gazebo/model_states라는 이름으로 담아 전달한다.
약 1000hz의 속도인데다, 쓸데없는 바닥 요소도 포함하고 있으므로 이 중에서 특정 물체들만을 골라 전달하도록 하는 코드를 작성했다.
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
|
#!/usr/bin/env python
import rospy
import rospkg
import roslib
from gazebo_msgs.msg import ModelStates
from std_msgs.msg import Float32MultiArray
from geometry_msgs.msg import Twist
def callback(msg):
obj_pub_node = rospy.Publisher("object_info", Float32MultiArray, queue_size=100)
rate = rospy.Rate(10)#10 hz
#After Receive the Topic --> make new Topic which is customized
get_obj_list = [1,3]#model_states[1], model_states[3] object topic
global pos_x, pos_y, pos_z, ori_x, ori_y, ori_z, ori_w
global linear_x, linear_y, linear_z, angular_x, angular_y, angular_z
id = 100
while not rospy.is_shutdown():
obj = [0, 0, 0, 0, 0, 0, 0]
for i in range(len(msg.pose)):
if i in get_obj_list:
obj_id = id
#position
pos_x = msg.pose[i].position.x
pos_y = msg.pose[i].position.y
pos_z = msg.pose[i].position.z
#orientation
ori_x = msg.pose[i].orientation.x
ori_y = msg.pose[i].orientation.y
ori_z = msg.pose[i].orientation.z
ori_w = msg.pose[i].orientation.w
#twist
linear_x = msg.twist[i].linear.x
linear_y = msg.twist[i].linear.y
linear_z = msg.twist[i].linear.z
angular_x = msg.twist[i].angular.x
angular_y = msg.twist[i].angular.y
angular_z = msg.twist[i].angular.z
#Real Sending Topic define
obj[0] = pos_x
obj[1] = pos_y
obj[2] = pos_z
obj[3] = angular_x
obj[4] = angular_y
obj[5] = angular_z
obj[6] = id
#print(obj)
publish_obj = Float32MultiArray(data=obj)
obj_pub_node.publish(publish_obj)
rate.sleep()
id += 1
else:
continue
def subscriber():
rospy.init_node('objectPerception', anonymous=True)
rospy.Subscriber("/gazebo/model_states", ModelStates, callback)
# spin() simply keeps python from exiting until this node is stopped
rospy.spin()
if __name__ == '__main__':
try:
subscriber()
except rospy.ROSInterruptException:
pass
|
cs |
필요한 부분은 position에 해당되는 x,y,z좌표이며 orientation값 자체가 quaternion값으로 나오게 되는데 우리는 euler angle값이 필요하므로
ModelStates() 형식 중 euler값 alpha, beta, gamma만을 담아 float32multiarray형태의 topic으로 감싸서 보내주도록 하였다.
gazebo/ModelStates Documentation
File: gazebo/ModelStates.msg Raw Message Definition #This message is deprecated. Please use the version in gazebo_msgs instead. # broadcast all model states in world frame string[] name # model names g
docs.ros.org
마지막으로 각 물체들마다 id값으로 구분해야 하기 때문에 어쩔수 없이 100, 101, 102같은 어설픈 id값을 줬다.
이걸 받아 Cm측에 전달하는 코드는 추후 추가.
BBOX 가져오는 코드는 이걸 쓰면 될듯?
GetBoundingBox() values not changing after scale in gazebo (using : visual_plugin) - Gazebo: Q&A Forum
GetBoundingBox() values not changing after scale in gazebo (using : visual_plugin) edit Gazebo ver: 7.0, ROS : Kinetic [Posted in ros.answers, closed and told to post here] Hello, I am using a visual_plugin to get the box corner points, so later while scal
answers.gazebosim.org
'ROS . V-REP' 카테고리의 다른 글
0913.ttt (0) | 2019.06.08 |
---|---|
Error : Could not find the required component 'gazebo_plugins'. (ROS kinetic, Ubuntu 16.04) (0) | 2019.04.15 |
gazebo model texture (.dae file)/텍스쳐 어두워짐 (0) | 2019.02.15 |
rosjava message 추가할 때 (0) | 2019.02.10 |
[ROS]catkin_make node생성이 되지 않을 때 (0) | 2018.09.28 |