Trajectory creation

Discussions about all things Bitcraze
Post Reply
Smatic
Beginner
Posts: 4
Joined: Thu Apr 21, 2022 11:41 am

Trajectory creation

Post by Smatic »

Hello everyone,

i was able to fly my Crazyflie with a Positioningsystem from Point to Point. Now, i really would like to specify a trajectory for my Crazyflie. I just found some Examples from Crazyflie-lib. Such as the Bezier_trajectory.py.
I actually don't know where in the program the positions to be approached should be entered. Can somebody please explain me how it should work?

the Bezier_trahectory.py Code can be found here https://pastebin.com/NieZtgRa.




Yours, Smatic.
kristoffer
Bitcraze
Posts: 630
Joined: Tue Jun 30, 2015 7:47 am

Re: Trajectory creation

Post by kristoffer »

Hi!

The example you are looking at is unfortunately a bit tricky to use (I wrote it a long time ago).

A better way to go is to use the high level commander in the Crazyflie. It works by uploading a trajectory to the Crazyflie and then tell it to fly this path.
There are two trajectory formats, the compressed one is based on bezier curves and fairly easy to understand. You can read about it here: https://www.bitcraze.io/documentation/r ... y_formats/

An example of how to use it:
https://github.com/bitcraze/crazyflie-l ... pressed.py

The trajectory is defined on lines 52-58

Good luck!
Smatic
Beginner
Posts: 4
Joined: Thu Apr 21, 2022 11:41 am

Re: Trajectory creation

Post by Smatic »

Hello Kristoffer,

thank you very much for replying :) !.

I just have a question.

The CompressedStart(0.0, 0.0, 0.0, 0.0), describes the X,Y,Z and the Yaw as it mentioned in the documentation.
The Second line of code means: CompressedSegment(2.0, [0.0, 1.0, 1.0], [0.0, a, 0.0], [], []). Is it possible if you can describe me
this part more easily? ;)


Smatic
Smatic
Beginner
Posts: 4
Joined: Thu Apr 21, 2022 11:41 am

Re: Trajectory creation

Post by Smatic »

Hello its me again,

i would like to look at this line: CompressedSegment(2.0, [0.0, 0.0, 1], [0.0, 0.0, 1.0], [], []),

i understood that the 2.0 stands for the Duration. The first two brackets decribe the X and Y axis. (here, [0.0, 0.0, 1.0], [0.0, 0.0, 1.0],..) means, that the Crazyflie should fly to position x=1 and y=1 right? But what do the first two zeros indicate for example in [0.0, 0.0, 1.0]?


Yours,

Smatic
kristoffer
Bitcraze
Posts: 630
Joined: Tue Jun 30, 2015 7:47 am

Re: Trajectory creation

Post by kristoffer »

Code: Select all

CompressedStart(0.0, 0.0, 0.0, 0.0)
CompressedSegment(2.0, [0.0, 1.0, 1.0], [0.0, a, 0.0], [], [])
CompressedSegment(2.0, [1.0, b, 0.0], [-a, -c, 0.0], [], []),
CompressedSegment(2.0, [-b, -1.0, -1.0], [c, a, 0.0], [], []),
CompressedSegment(2.0, [-1.0, 0.0, 0.0], [-a, 0.0, 0.0], [], []),
It means that it will start at (0.0, 0.0, 0.0) and follow a cubic Bezier curve to (1.0, 0.0, 0.0), with control points in (0.0, 0.0, 0.0) and (1.0, a, 0.0)
It will continue along a cubic Bezier curve to (0.0, 0.0, 0.0), with control points in (1.0, -a, 0) and (b, -c, 0.0)
continue to (-1.0, 0.0, 0.0) with control points in (-b, c, 0.0) and (-1.0, a, 0.0)
and finally go back to (0.0, 0.0, 0.0) with control points in (-1.0, -a, 0.0) and (0.0, 0.0, 0.0)

If you plot the X and Y coordinates you can see that it will fly a figure 8, starting in the middle of the eight.
i would like to look at this line: CompressedSegment(2.0, [0.0, 0.0, 1], [0.0, 0.0, 1.0], [], []),

i understood that the 2.0 stands for the Duration. The first two brackets decribe the X and Y axis. (here, [0.0, 0.0, 1.0], [0.0, 0.0, 1.0],..) means, that the Crazyflie should fly to position x=1 and y=1 right? But what do the first two zeros indicate for example in [0.0, 0.0, 1.0]?
The first element of the lists represents the first control point, the second element of the lists is the second control point and the third element is the end point. In this case you would have your control points in (0.0, 0.0, ?) and (0.0, 0.0, ?), while the end point would be (1.0, 1.0, ?). Assuming your start point is (0.0, 0.0, ?) the Crazyflie would start by going in the direction of the first control point, which is (0.0, 0.0, 0.0), that is it would stay where it is. After some time it would go more towards the second control point, which is also (0.0, 0.0, 0.0), that is it would stay where it is. At the end it will go to the end point (1.0, 1.0, ?). To conclude you would get a motion where it starts at (0.0, 0.0, ?) and goes towards (1.0, 1.0, ?) at the end.

You can play with bezier curves here https://javascript.info/bezier-curve for instance. Note that there is a time component that is not obvious when looking at the curves like this. The positions of the control points not only affect the shape of the curve, but also velocity and acceleration. Putting the first control point at the same coordinate at the starting point means that it initially will not have any velocity. Similarly it will come to a stop if the second control point has the same coordinate as the end point. If the control points are at other coordinates, it will imply that the CF will have a velocity.
Smatic
Beginner
Posts: 4
Joined: Thu Apr 21, 2022 11:41 am

Re: Trajectory creation

Post by Smatic »

Hello kristoffer,

Just wanted to tell you That you are a beast in what you are doing. Thaaaank you veeerryyy muuuch 😁
kristoffer
Bitcraze
Posts: 630
Joined: Tue Jun 30, 2015 7:47 am

Re: Trajectory creation

Post by kristoffer »

Thanks!
Post Reply