bitcraze / crazyflie-clients-python

Host applications and library for Crazyflie written in Python.
Other
310 stars 472 forks source link

Question on control using LPS #324

Closed KhristopherK closed 6 years ago

KhristopherK commented 6 years ago

Hi,

We are currently setting up the LPS with the crazyflie and I have a couple of questions.

1) I've been going through the motion_commander library. I'm I correct in assuming that the functions available there are not taking using any kind of feedback from the LPS.

2) We are also tried the autonomousSequence example available, but can't see where in the code the position feedback occurs. In the run_sequence funcion, the cf.commande.send_setpoint seems to be taking in the target position we want the aircraft to be, however in the library, send_setpoint takes in aircraft attitude. Could you please explain a little bit more about it.

We don't mind writing a control loop to link some of the motion_commander functions with the LPS, but wanted to check that I'm not repeating the work. If there is nothing we will add it to the project.

Thanks,

Khris

ataffanel commented 6 years ago

Hi,

The Crazyflie has onboard PID controllers for velocity and position.

  1. Using the motion_commander you are sending velocity setpoints to the Crazyflie. The Crazyflie will use the velocity estimation it gets from its sensors (LPS included) to follow the setpoints.

  2. The autonomousSequence example is sending position setpoints, the Crazyflie will use its position estimation to control its position following the setpoint. What you are seeing in the example is a 'hack' we have been using to send position in the attitude packet. This was done at a time where we did not have an infrastructure in place to send position setpoint. We are planing to change that by adding a real position setpoint packet at some point.

In conclusion I do not think you need to start by implementing a control loop, there is one already working in the Crazyflie.

KhristopherK commented 6 years ago

Hi,

Thanks for the quick comeback. I understood item 2). Noted.

On item 1) looking again at the code it seems to assume a position based on the velocity and the distance it was commanded to. no feedback. We tried the following tests:

Is there any configuration or setting which should be active on the CF itself? for example in the autonomousSequence we set the aircraft to "cf.param.set_value('flightmode.posSet', '1')". should this be done in the script which uses the motion_commander library?

Thanks again,

Khris

ataffanel commented 6 years ago

Hi, Your observation are interesting, you are observing the limit of the velocity estimation and velocity control of the Crazyflie. Maybe the Ki part of the velocity PID is a bit weak for velocity control.

If when requesting hover at 0m/s in X/Y, the crazyflie (roughly) hover in place, then there is a feedback from the LPS since it is not possible to hover without extra sensor like the flow deck or the positioning system.

The motion_commander library only sends velocity setpoints, this is the reason it is working the way it is. It could be interesting to have a synchronous API like the motion API but sending position setpoints, however it has not been done yet.

The parameter "cf.param.set_value('flightmode.posSet', '1')" enables the hack to send position setpoint in the attitude packet. The motion controller is sending velocity setpoint using a dedicated packet (which is much more clean and should be implemented for position control too).

KhristopherK commented 6 years ago

Hi,

I've just tried requesting hover at 0m/s as per your suggestion and at the same time i'm reading the position of the aircraft as per LPS. I can see the aircraft drifting without attempting to correct it. I've tried different gains and still nothing. But this makes sense, as you point out these are limitations of the velocity estimation.

I can see in the cf configuration parameters that there are parameters for position control. I'm guessing this is for the part of the cascade for position control using LPS. Is there any python API yet for this. Or is what would be use when implementing the position control in the motion_commander?

By the way I'm using the LPS in TRW mode.

Thanks for your patience,

krichardsson commented 6 years ago

Hi!

Just to give some background to why the Motion commander is designed the way it is. When I wrote it the intention was to make it easy to use the Flow deck and enable fairly novice users to script autonomous flight. since the Flow deck only supports tracking of motion as opposed to absolute position, I think this makes sens.

Currently there is no API similar to the MotionCommander that supports absolute position setpoints. It would be fairly easy to extend the MotionCommander or to write a "PostionCommander". I'm not sure which is the best solution? Extending the MotionCommander might be confusing to a novice user playing with the Flow deck, while it probably would make sense to a LPS user?

For an example of sending absolute position setpoints, take a look at https://github.com/bitcraze/crazyflie-lib-python/blob/master/examples/autonomousSequence.py

KhristopherK commented 6 years ago

Thanks for the insight, I understand now how the motion commander works. I agree maybe a "PositionCommander" for the LPS would make sense. I did look at the autonomousSequence.py scrip but couldn't find where in the code the position feedback happens (see first comment on it).

krichardsson commented 6 years ago

Correct, there is no feedback loop in the autonomousSequence.py script, the feedback loop is in the controller in Crazyflie. The script only feeds setpoints to the controller.

KhristopherK commented 6 years ago

hi.

Is the feedback on the controller on actual position, it it getting position from LPS several times a second and then comparing that where it should be?, do you know at what rate?

Thanks,

krichardsson commented 6 years ago

Hi! A lot of interesting and relevant questions :-) We are trying to use issues in github for bugs and feature request though, and use https://forum.bitcraze.io/ for discussions like this. Please post this question there instead.

See you in the forum!

br Kristoffer

KhristopherK commented 6 years ago

You are right. I'll use the forum instead.

Thanks,

Khris