Skip to content

Commit

Permalink
#70 Improved take off/landing of swarm sequence
Browse files Browse the repository at this point in the history
Using velocity control for take off and landing to avoid problems if the crazyflies are not on the correct starting points
  • Loading branch information
krichardsson committed Feb 2, 2018
1 parent b3656e3 commit 8bdd63b
Showing 1 changed file with 20 additions and 9 deletions.
29 changes: 20 additions & 9 deletions examples/swarmSequence.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,18 +226,29 @@ def reset_estimator(scf):


def take_off(cf, position):
steps = 10
for i in range(10):
z = i * position[2] / steps
cf.commander.send_setpoint(position[1], position[0], 0,
int(z * 1000))
time.sleep(0.3)
take_off_time = 1.0
sleep_time = 0.1
steps = int(take_off_time / sleep_time)
vz = position[2] / take_off_time

print(vz)

for i in range(steps):
cf.commander.send_velocity_world_setpoint(0, 0, vz, 0)
time.sleep(sleep_time)


def land(cf, position):
cf.commander.send_setpoint(position[1], position[0], 0,
int(0.2 * 1000))
time.sleep(1.5)
landing_time = 1.0
sleep_time = 0.1
steps = int(landing_time / sleep_time)
vz = -position[2] / landing_time

print(vz)

for i in range(steps):
cf.commander.send_velocity_world_setpoint(0, 0, vz, 0)
time.sleep(sleep_time)

cf.commander.send_setpoint(0, 0, 0, 0)
# Make sure that the last packet leaves before the link is closed
Expand Down

8 comments on commit 8bdd63b

@bcmack
Copy link

@bcmack bcmack commented on 8bdd63b Feb 6, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When running this with 1 crazyflie, how can I get the position data from the Crazyflie? I would like to be able to debug where the Crazyflie actually thinks it is.

@krichardsson
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The position is available as log data from the Crazyflie.
You will have to set up a subscription for the appropriate log data and will receive the data through a callback.
Take a look at the autonomousSequence.py example for an implementation.

@cnoe
Copy link

@cnoe cnoe commented on 8bdd63b Feb 8, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am working with bcmack on a senior project using the crazyflie 2.0. We were able to get the position data just like you said. But we are still not able to get the crazyflie to go to a desired position.

In autonomousSequence.py, you are using the commander.send_setpoint() command to give the desired location you want the crazyflie to go. I noticed in commander.py that this function takes in pitch, roll ,yaw, and thrust; not x, y, z, yaw. How are the pitch, roll, yaw, and thrust being applied to take the crazyflie to a specific location?

@cnoe
Copy link

@cnoe cnoe commented on 8bdd63b Feb 8, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We figured out our issue. We did not realize that a yaw of 0 corresponds to the front of the drone facing the positive x-axis, not the positive y-axis, as we were thinking.

p.s. The autonomous sequence example works great, we hope to expand to the swarm sequence in the coming weeks.

@krichardsson
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The API is a bit confusing, due to historical reasons. There is on going work (bitcraze/crazyflie-firmware#293) that hopefully will sole the problem in the future.

The line
cf.param.set_value('flightmode.posSet', '1')
sets the crazyflie in position control mode.

The method
def send_setpoint(self, roll, pitch, yaw, thrust):
in the Commander class, gets a new meaning in position control mode, something like this
def send_setpoint(self, pos_x_in_m, pos_y_in_m, yaw, pos_z_in_mm):

Note the mixup of meters for x and y while z is expressed in millimeters.

set all to 0 to turn off the motors.
comander.send_setpoint(0, 0, 0, 0)

Sounds exciting with a swarm, please share any awesomeness! Drop us an email at [email protected]

@cnoe
Copy link

@cnoe cnoe commented on 8bdd63b Feb 27, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are working on flying 2 Crazyflies with the swarm sequence. However, the program is hanging on "Waiting for estimator to find position". The Crazyflies aren't getting their positions from the loco decks. Is there something we need to do with the LOCO setup that is different from the autonomousSequence?

image

@krichardsson
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi!
This means that the Kalman position estimator does not converge.

No, should not be any difference regarding the scripts.

You have to run the LPS system in TDoA mode though to support multiple copters. The TDoA mode is a bit more sensitive to anchor placements, try to put the copters on a box or something to move them closer to the center of the flying space (well inside the convex hull) to see if it makes a difference. In some cases it seems as the estimator does not converge if the copter is in the same plane as the anchors (or even under), for instance when it is on the floor.

We try to use github issues for bug reports or feature requests and prefer to handle support questions in the forum. The idea is to collect all information about how to use the system in one place to make it easier for other users to find it. Would it be possible for you post a question about this in the forum instead?

@cnoe
Copy link

@cnoe cnoe commented on 8bdd63b Mar 1, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I can post it there shortly.

Please sign in to comment.