Skip to content

Commit 765436b

Browse files
committed
updates for requested changes
1 parent e997a35 commit 765436b

File tree

1 file changed

+26
-27
lines changed

1 file changed

+26
-27
lines changed

rotors_driver/src/rotors_driver_node.py

Lines changed: 26 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,13 @@
1717
class States(Enum):
1818

1919
ARMING = 1
20-
TAKEOFF = 2
21-
LANDING = 3
20+
ARMED = 2
21+
TAKINGOFF = 3
2222
FLYING = 4
23-
DISARMING = 5
23+
LANDING = 5
24+
LANDED = 6
25+
DISARMING = 7
26+
DISARMED = 8
2427

2528
class RotorsConstraints:
2629
MIN_SPEED = 10
@@ -40,7 +43,7 @@ def __init__(self):
4043
self.mav_name = rospy.get_param('drone_model', 'firefly')
4144
self.drone_state_upd_freq = rospy.get_param('drone_state_timer_frequency', 0.01)
4245
self.misc_state_upd_freq = rospy.get_param('misc_state_timer_frequency', 1.0)
43-
self.drone_flight_state = States.LANDING
46+
self.drone_flight_state = States.LANDED
4447
self.current_state = Odometry()
4548
self.current_x=self.current_state.pose.pose.position.x
4649
self.current_y=self.current_state.pose.pose.position.y
@@ -166,13 +169,13 @@ def odom_callback(self,msg):
166169

167170
self.frame_id = self.current_state.header.frame_id
168171

169-
if self.current_z<0.1:
170-
self.drone_flight_state = States.LANDING
172+
if self.current_z<0.09:
173+
self.drone_flight_state = States.LANDED
171174
else:
172175
self.drone_flight_state = States.FLYING
173176

174177

175-
def rotors_takeoff_land(self,req):
178+
def rotors_landing(self,req):
176179
quaternion = tf.transformations.quaternion_from_euler(0, 0, 0.0)
177180
traj = MultiDOFJointTrajectory()
178181

@@ -182,11 +185,7 @@ def rotors_takeoff_land(self,req):
182185
traj.joint_names.append('base_link')
183186
traj.header=header
184187

185-
if req:
186-
transforms =Transform(translation=Point(0.0, 0.0, 1.0), rotation=Quaternion(quaternion[0],quaternion[1],quaternion[2],quaternion[3]))
187-
velocities =Twist()
188-
accelerations=Twist()
189-
else:
188+
if not req:
190189
transforms =Transform(translation=Point(self.current_x, self.current_y, 0.0), rotation=Quaternion(quaternion[0],quaternion[1],quaternion[2],quaternion[3]))
191190
velocities =Twist(linear = Vector3(x=0.0, y=0.0, z=0.0), angular=Vector3(x=0.0, y=0.0, z=0.0) )
192191
accelerations=Twist(linear = Vector3(x=0.0, y=0.0, z=0.0), angular=Vector3(x=0.0, y=0.0, z=0.0) )
@@ -197,13 +196,11 @@ def rotors_takeoff_land(self,req):
197196
traj.points.append(point)
198197

199198

200-
self.firefly_command_publisher.publish(traj)
201-
time.sleep(1) #change the time if altitude val doesn't change
202-
if req and 0.8<self.current_z<1.2:
203-
return True, 0
204-
elif not req and 0.0<=self.current_z<0.1:
205-
rospy.loginfo("Firefly Disarming")
206-
self.drone_flight_state = States.DISARMING
199+
200+
while not(0.0<=self.current_z<0.1):
201+
self.firefly_command_publisher.publish(traj)
202+
203+
if not req :
207204
return True, 0
208205
else:
209206
return False,1
@@ -218,12 +215,14 @@ def rotors_arm(self, req):
218215
if req.value:
219216
rospy.loginfo("Firefly Arming")
220217
self.drone_flight_state = States.ARMING
221-
time.sleep(1) # waits 1 sec
222-
tk_req = CommandTOL()
218+
time.sleep(0.01)
219+
self.drone_flight_state = States.ARMED
223220
return True, 1
224221
else:
225222
rospy.loginfo("Firefly Disarming")
226223
self.drone_flight_state = States.DISARMING
224+
time.sleep(0.01)
225+
self.drone_flight_state = States.DISARMED
227226
return False, 0
228227

229228
def rotors_set_mode(self, req):
@@ -236,9 +235,8 @@ def rotors_land(self, req):
236235

237236
rospy.loginfo("Landing!")
238237
self.drone_flight_state = States.LANDING
239-
240-
241-
success, result = self.rotors_takeoff_land(0)
238+
success, result = self.rotors_landing(0)
239+
self.drone_flight_state = States.LANDED
242240
return success, result
243241

244242
def rotors_change_speed(self, speed):
@@ -288,6 +286,10 @@ def publish_position_desired(self, msg):
288286
yaw_des = msg.yaw
289287
yaw_rate_des = msg.yaw_rate
290288

289+
if self.drone_flight_state == 6 and int(desired_z_to_go):
290+
self.drone_flight_state = States.TAKINGOFF
291+
292+
291293
if (desired_x_to_go ==0.0 and desired_y_to_go ==0.0 and yaw_des == 0.0) and (vx_des >0.0 or vy_des >0.0 or yaw_rate_des>0) and vz_des >=0.0:
292294
desired_x_to_go=self.current_x+(vx_des*self.sample_time)
293295
desired_y_to_go=self.current_y+(vy_des*self.sample_time)
@@ -314,9 +316,6 @@ def publish_position_desired(self, msg):
314316
print("no motion asked")
315317

316318

317-
318-
319-
320319
quaternion = tf.transformations.quaternion_from_euler(0, 0, desired_yaw_to_go)
321320

322321
traj = MultiDOFJointTrajectory()

0 commit comments

Comments
 (0)