質問編集履歴
2
コピーを貼り付けました
test
CHANGED
File without changes
|
test
CHANGED
@@ -48,7 +48,9 @@
|
|
48
48
|
|
49
49
|
|
50
50
|
|
51
|
-
a=b=x=lstick_lr=lstick_fb=rstick_lr=rstick_fb=
|
51
|
+
a=b=x=y=lstick_lr=lstick_fb=rstick_lr=rstick_fb=0
|
52
|
+
|
53
|
+
pitch=roll=yaw=thrust=0
|
52
54
|
|
53
55
|
|
54
56
|
|
@@ -56,135 +58,135 @@
|
|
56
58
|
|
57
59
|
def __init__(self):
|
58
60
|
|
59
|
-
self._joy_sub = rospy.Subscriber('joy',Joy,self.joy_callback, queue_size=1)
|
61
|
+
self._joy_sub = rospy.Subscriber('joy',Joy,self.joy_callback, queue_size=1)
|
60
|
-
|
62
|
+
|
61
|
-
self.pub_takeoff = rospy.Publisher('/ardrone/takeoff', Empty)
|
63
|
+
self.pub_takeoff = rospy.Publisher('/ardrone/takeoff', Empty)
|
62
|
-
|
64
|
+
|
63
|
-
self.pub_land = rospy.Publisher('/ardrone/land', Empty)
|
65
|
+
self.pub_land = rospy.Publisher('/ardrone/land', Empty)
|
64
|
-
|
66
|
+
|
65
|
-
self.pub_reset = rospy.Publisher('/ardrone/reset', Empty)
|
67
|
+
self.pub_reset = rospy.Publisher('/ardrone/reset', Empty)
|
66
|
-
|
68
|
+
|
67
|
-
self.pub_velocity = rospy.Publisher('/cmd_vel', Twist,queue_size=1)
|
69
|
+
self.pub_velocity = rospy.Publisher('/cmd_vel', Twist,queue_size=1)
|
68
|
-
|
70
|
+
|
69
|
-
self.pub_check = rospy.Publisher('check',Int32 ,queue_size=1) #for_rosbag
|
71
|
+
self.pub_check = rospy.Publisher('check',Int32 ,queue_size=1) #for_rosbag
|
70
|
-
|
72
|
+
|
71
|
-
self.pub_check_mag = rospy.Publisher('check_mag',Int32 ,queue_size=1)
|
73
|
+
self.pub_check_mag = rospy.Publisher('check_mag',Int32 ,queue_size=1)
|
72
|
-
|
73
|
-
|
74
|
-
|
74
|
+
|
75
|
+
|
76
|
+
|
75
|
-
self.mag_sub = rospy.Subscriber("/ardrone/
|
77
|
+
self.mag_sub = rospy.Subscriber("/ardrone/navdata/mag", Navdata, self.mag_callback)
|
76
|
-
|
77
|
-
|
78
|
+
|
79
|
+
|
78
80
|
|
79
81
|
def mag_callback(self, mag_msg):
|
80
82
|
|
81
|
-
global mag
|
83
|
+
global mag
|
82
|
-
|
84
|
+
|
83
|
-
mag = mag_msg.magY
|
85
|
+
mag = mag_msg.magY
|
84
|
-
|
85
|
-
|
86
86
|
|
87
87
|
|
88
88
|
|
89
89
|
def joy_callback(self, joy_msg):
|
90
90
|
|
91
|
-
|
91
|
+
global a,b,x,y,lstick_lr,lstick_fb,rstick_lr,rstick_fb
|
92
|
-
|
92
|
+
|
93
|
-
a = float(joy_msg.buttons[1])
|
93
|
+
a = float(joy_msg.buttons[1])
|
94
|
-
|
94
|
+
|
95
|
-
b = float(joy_msg.buttons[2])
|
95
|
+
b = float(joy_msg.buttons[2])
|
96
|
-
|
96
|
+
|
97
|
-
x = float(joy_msg.buttons[0])
|
97
|
+
x = float(joy_msg.buttons[0])
|
98
|
-
|
98
|
+
|
99
|
-
y = float(joy_msg.buttons[3])
|
99
|
+
y = float(joy_msg.buttons[3])
|
100
|
-
|
100
|
+
|
101
|
-
|
101
|
+
lb = float(joy_msg.buttons[4])
|
102
|
-
|
102
|
+
|
103
|
-
|
103
|
+
rb = float(joy_msg.buttons[5])
|
104
|
-
|
104
|
+
|
105
|
-
|
105
|
+
lt = float(joy_msg.buttons[6])
|
106
|
-
|
106
|
+
|
107
|
-
|
107
|
+
rt = float(joy_msg.buttons[7])
|
108
|
-
|
108
|
+
|
109
|
-
start = float(joy_msg.buttons[9])
|
109
|
+
start = float(joy_msg.buttons[9])
|
110
|
-
|
110
|
+
|
111
|
-
select = float(joy_msg.buttons[8])
|
111
|
+
select = float(joy_msg.buttons[8])
|
112
|
-
|
112
|
+
|
113
|
-
|
113
|
+
lstick_botton = float(joy_msg.buttons[10])
|
114
|
-
|
114
|
+
|
115
|
-
|
115
|
+
rstick_botton = float(joy_msg.buttons[11])
|
116
|
-
|
117
|
-
|
118
|
-
|
116
|
+
|
117
|
+
|
118
|
+
|
119
|
-
lstick_lr = float(joy_msg.axes[0]) #left_and_right//roll
|
119
|
+
lstick_lr = float(joy_msg.axes[0]) #left_and_right//roll
|
120
|
-
|
120
|
+
|
121
|
-
lstick_fb = float(joy_msg.axes[1]) #front_and_back//pitch
|
121
|
+
lstick_fb = float(joy_msg.axes[1]) #front_and_back//pitch
|
122
|
-
|
122
|
+
|
123
|
-
rstick_lr = float(joy_msg.axes[2]) #rotation//yaw
|
123
|
+
rstick_lr = float(joy_msg.axes[2]) #rotation//yaw
|
124
|
-
|
124
|
+
|
125
|
-
rstick_fb = float(joy_msg.axes[3]) #up_and_down//thrust
|
125
|
+
rstick_fb = float(joy_msg.axes[3]) #up_and_down//thrust
|
126
|
-
|
126
|
+
|
127
|
-
plusbotton_lr = float(joy_msg.axes[4])
|
127
|
+
plusbotton_lr = float(joy_msg.axes[4])
|
128
|
-
|
128
|
+
|
129
|
-
plusbotton_fb = float(joy_msg.axes[5])
|
129
|
+
plusbotton_fb = float(joy_msg.axes[5])
|
130
130
|
|
131
131
|
|
132
132
|
|
133
133
|
def move_controller(self):
|
134
134
|
|
135
|
-
|
135
|
+
global roll,pitch,yaw,thrust
|
136
|
+
|
136
|
-
|
137
|
+
roll = lstick_lr
|
138
|
+
|
137
|
-
|
139
|
+
pitch = lstick_fb
|
138
|
-
|
139
|
-
|
140
|
+
|
140
|
-
|
141
|
-
|
141
|
+
thrust = rstick_fb
|
142
|
-
|
142
|
+
|
143
|
-
|
143
|
+
yaw = rstick_lr
|
144
|
+
|
145
|
+
return roll,pitch,yaw,thrust
|
144
146
|
|
145
147
|
|
146
148
|
|
147
149
|
def main(self):
|
148
150
|
|
151
|
+
print(y,Navdata)
|
152
|
+
|
149
|
-
|
153
|
+
self.move_controller()
|
150
|
-
|
154
|
+
|
151
|
-
|
155
|
+
self.pub_velocity.publish(Twist(Vector3(pitch,roll,thrust),Vector3(0,0,yaw)))
|
152
|
-
|
153
|
-
|
154
|
-
|
156
|
+
|
155
|
-
if a == 1:
|
157
|
+
if a == 1:
|
156
|
-
|
158
|
+
|
157
|
-
|
159
|
+
self.pub_takeoff.publish(Empty())
|
158
|
-
|
160
|
+
|
159
|
-
|
161
|
+
rospy.sleep(4.0)
|
160
|
-
|
162
|
+
|
161
|
-
|
163
|
+
self.pub_velocity.publish(Twist(Vector3(0,0,0),Vector3(0,0,0)))
|
162
|
-
|
164
|
+
|
163
|
-
elif b == 1:
|
165
|
+
elif b == 1:
|
164
|
-
|
166
|
+
|
165
|
-
|
167
|
+
self.pub_land.publish(Empty())
|
166
|
-
|
168
|
+
|
167
|
-
|
169
|
+
self.pub_velocity.publish(Twist(Vector3(0,0,0),Vector3(0,0,0)))
|
168
|
-
|
170
|
+
|
169
|
-
|
171
|
+
elif x == 1:
|
170
|
-
|
172
|
+
|
171
|
-
|
173
|
+
self.pub_reset.publish(Empty())
|
174
|
+
|
175
|
+
|
176
|
+
|
177
|
+
if __name__ == '__main__':
|
172
178
|
|
173
179
|
|
174
180
|
|
175
|
-
|
176
|
-
|
177
|
-
if __name__ == '__main__':
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
181
|
+
rospy.init_node('moving_node', anonymous=True)
|
182
|
-
|
182
|
+
|
183
|
-
|
183
|
+
s = controll()
|
184
|
-
|
184
|
+
|
185
|
-
|
185
|
+
s.main()
|
186
|
+
|
186
|
-
|
187
|
+
#controll()
|
188
|
+
|
187
|
-
|
189
|
+
rospy.spin()
|
188
190
|
|
189
191
|
```
|
190
192
|
|
1
インデントを修正しました。こちらが自分の編集しているプログラムと同じインデントになっています。
test
CHANGED
File without changes
|
test
CHANGED
@@ -88,7 +88,7 @@
|
|
88
88
|
|
89
89
|
def joy_callback(self, joy_msg):
|
90
90
|
|
91
|
-
global a,b,x,lstick_lr,lstick_fb,rstick_lr,rstick_fb
|
91
|
+
global a,b,x,lstick_lr,lstick_fb,rstick_lr,rstick_fb
|
92
92
|
|
93
93
|
a = float(joy_msg.buttons[1])
|
94
94
|
|
@@ -98,57 +98,57 @@
|
|
98
98
|
|
99
99
|
y = float(joy_msg.buttons[3])
|
100
100
|
|
101
|
-
lb = float(joy_msg.buttons[4])
|
101
|
+
lb = float(joy_msg.buttons[4])
|
102
|
-
|
102
|
+
|
103
|
-
rb = float(joy_msg.buttons[5])
|
103
|
+
rb = float(joy_msg.buttons[5])
|
104
|
-
|
104
|
+
|
105
|
-
lt = float(joy_msg.buttons[6])
|
105
|
+
lt = float(joy_msg.buttons[6])
|
106
|
-
|
106
|
+
|
107
|
-
rt = float(joy_msg.buttons[7])
|
107
|
+
rt = float(joy_msg.buttons[7])
|
108
|
-
|
108
|
+
|
109
|
-
|
109
|
+
start = float(joy_msg.buttons[9])
|
110
|
-
|
110
|
+
|
111
|
-
|
111
|
+
select = float(joy_msg.buttons[8])
|
112
|
-
|
112
|
+
|
113
|
-
lstick_botton = float(joy_msg.buttons[10])
|
113
|
+
lstick_botton = float(joy_msg.buttons[10])
|
114
|
-
|
114
|
+
|
115
|
-
rstick_botton = float(joy_msg.buttons[11])
|
115
|
+
rstick_botton = float(joy_msg.buttons[11])
|
116
|
-
|
117
|
-
|
118
|
-
|
116
|
+
|
117
|
+
|
118
|
+
|
119
|
-
|
119
|
+
lstick_lr = float(joy_msg.axes[0]) #left_and_right//roll
|
120
|
-
|
120
|
+
|
121
|
-
|
121
|
+
lstick_fb = float(joy_msg.axes[1]) #front_and_back//pitch
|
122
|
-
|
122
|
+
|
123
|
-
|
123
|
+
rstick_lr = float(joy_msg.axes[2]) #rotation//yaw
|
124
|
-
|
124
|
+
|
125
|
-
|
125
|
+
rstick_fb = float(joy_msg.axes[3]) #up_and_down//thrust
|
126
|
-
|
126
|
+
|
127
|
-
|
127
|
+
plusbotton_lr = float(joy_msg.axes[4])
|
128
|
-
|
128
|
+
|
129
|
-
|
129
|
+
plusbotton_fb = float(joy_msg.axes[5])
|
130
130
|
|
131
131
|
|
132
132
|
|
133
133
|
def move_controller(self):
|
134
134
|
|
135
|
-
global pitch,roll,yaw,thrust
|
135
|
+
global pitch,roll,yaw,thrust
|
136
|
-
|
136
|
+
|
137
|
-
pitch = lstick_lr
|
137
|
+
pitch = lstick_lr
|
138
|
-
|
138
|
+
|
139
|
-
roll = lstick_fb
|
139
|
+
roll = lstick_fb
|
140
|
-
|
140
|
+
|
141
|
-
thrust = rstick_fb
|
141
|
+
thrust = rstick_fb
|
142
|
-
|
142
|
+
|
143
|
-
yaw = rstick_lr
|
143
|
+
yaw = rstick_lr
|
144
144
|
|
145
145
|
|
146
146
|
|
147
147
|
def main(self):
|
148
148
|
|
149
|
-
pitch,roll,yaw,thrust = self.move_controller()
|
149
|
+
pitch,roll,yaw,thrust = self.move_controller()
|
150
|
-
|
150
|
+
|
151
|
-
self.pub_velocity.publish(Twist(Vector3(pitch,roll,thrust),Vector3(0,0,yaw)))
|
151
|
+
self.pub_velocity.publish(Twist(Vector3(pitch,roll,thrust),Vector3(0,0,yaw)))
|
152
152
|
|
153
153
|
|
154
154
|
|
@@ -160,15 +160,15 @@
|
|
160
160
|
|
161
161
|
self.pub_velocity.publish(Twist(Vector3(0,0,0),Vector3(0,0,0)))
|
162
162
|
|
163
|
-
|
163
|
+
elif b == 1:
|
164
164
|
|
165
165
|
self.pub_land.publish(Empty())
|
166
166
|
|
167
167
|
self.pub_velocity.publish(Twist(Vector3(0,0,0),Vector3(0,0,0)))
|
168
168
|
|
169
|
-
elif x == 1:
|
169
|
+
elif x == 1:
|
170
|
-
|
170
|
+
|
171
|
-
print(Navdata)
|
171
|
+
print(Navdata)
|
172
172
|
|
173
173
|
|
174
174
|
|