# Motion magic with pigeon to drive a curved line

Hello everyone, we will soon get a pigeon and I want to use it in a motion magic close loop with encoders (pigeon will run in a cascade loop just like driving straight in the examples).

So the encoders will be on each side to drive at a certain distance and a pigeon turn at a given angle, together they will make the robot drive at a curve line.
The question is, if it’s even correct to use the pigeon with encoders to drive at a curve line.
I think that the encoder will try to compensate for the turn difference so at the end, after driving the curve line, the encoders will fix the heading of the robot to angle 0 but the cascade loop will return the robot heading to the given target and so on…
So I could calculate angle to encoders unit and set the setpoint accordingly
left turn:
`left.set(distance - angle * Angle_To_Encoders_Units) right.set(distance + angle * Angle_To_Encoders_Units)`

Does the math makes sense or I have to generate the path and use MP mode?

Ammm, does anyone have any insight on this?

I would recommend using a path and Motion Profiling, but note that getting that to play well with a Pigeon and an encoder is currently very difficult, and the implementation is flawed (you cannot use independent velocity feedforwards on the left and right sides). If you want to get a controlled arc, follow the path on the RoboRIO-side instead, and use the Talons to closed-loop to each point in the profile.

1 Like

Huh? We added feedforwards for both PID0 and PID1. This was mentioned in the kickoff blog.
https://phoenix-documentation.readthedocs.io/en/latest/blog/blog-kickoff.html
So use PID0 arb feed forward for the straight-drive. Use PID1 arb feed forward for your turn.

Shouldn’t be. Example here. Fill in the arb feed forwards with whatever you want.

1 Like

But the example will still work just with `config_F`right? What would you push to the arb feed forwards anyway?

We had great results using two encoders and a pigeon with the motion profile arc model from CTRE. Like you mentioned it uses two cascaded PID loops. The main PID controls distance using the sum of the left and right encoders, the auxilliary PID controls angle using the pigeon. Combining of the two PID signals for the left and right drive motors is handled automatically.
MotionProfile_AuxMotionProfileArc

You’re going to need more than Just Motion Magic for this problem. Motion Magic is designed to remove error from a linear system while respecting maximum velocity and acceleration, but in your case you aren’t trying to remove a single point of error, and if you try to run Motion Magic on each wheel by setting them to a desired point, you will find that they will correct themselves to that point and then stop, effectively driving in a linear pattern.

What you need is a bunch of setpoints across time. Then continuously use a controller to close the error between those setpoints at different times. This process is what Jaci’s Pathfinder does.

So I can’t just use angle and distance and generate a motion profile on the fly?

You could theoretically do that, but you can’t use Motion Magic for it. Motion Magic is designed to close an error on an linear system, and moving across 2D space with a tank drive is, by definition, nonlinear. You’ll need to generate a spline and waypoints based on your distance and angle, and then follow those setpoints.

1 Like

Ammm I see… I guess we will go for MP arc mode then, thanks for your help guys!