Drivetrain.turnToHeading PID paremeter tuning

Hi @tfriez

Is there a way to adjust the PID parameters that are used in the function Drivetrain.turnToHeading?

Thanks

The smartdrive turnToHeading does not use a PID loop, in the most recent versions of VEXcode it’s using a P loop, earlier versions were even simpler than that. If you are using C++ then there is a class member function you can use to change the proportional constant, it’s called setTurnConstant and can take values between 0.1 and 4.0. The default value for IQ is 2.0 (on V5 it’s 1.0), making that value larger will cause turns to be quicker, but they may overshoot.

8 Likes

Thanks @jpearman

How do I access to the setTurnConstant function?


it does not show in the drop down menu.
Do we need to include another library?

It doesn’t show as part of the simplified autocomplete we use in VEXcode. Just type it in, for example.

Drivetrain.setTurnConstant(2.5);
4 Likes

Thanks!
is there a list of commands that do not show in the autocomplete and a description of these commands?

I don’t think so, there are only. a few things like that and I guess it’s thought IQ users generally wouldn’t use them. drivetrain turns using the gyro are pretty simple, usually if you wanted more control, or a full PID loop, you would need to write the control loop yourself.

The best way for an advanced user to see everything available would be to look at the library headers which are fairly easy to find in the VEXcode application folder.

2 Likes

Thanks.
For example I see setTurnThreshold( double t ). Is that to define how close you want to get to the target angle before exiting the loop?
in our case, we have seen the robot overshooting the target and oscillating when using the “Turn to heading 90degree” block.
The behavior is different when we use “turn to rotation 90degree” for some reason: it does not oscillate.

1 Like

setTurnThreshold is used to set the threshold that determines when a rotate command has achieved the requested position, default is 1 degree. turnToRotation should have the exact same functionality as turnToHeading, they both decide how far the robot needs to turn and which direction, then call a generic turn function that executes the move.

If the robot is oscillating, then try reducing the turn constant or slow it down a bit, it sounds like it may be trying to rotate at high speed.

The drivetrain class is intended to be used as a basic means of moving and rotating the robot primarily in a classroom setting using a standard IQ clawbot build. It’s hard to make a generic algorithm work for competition robots that may have very different characteristics, that’s why we recommend you write your own code that is tuned for your build.

4 Likes

yes, last year’s robot was much lighter and only had a 1:1 gear ratio (vs ~2:1 now). The Turn to heading command was working well.
We’ll try to use the setTurnConstant to improve first.

By the way, we really like the new graphics that show the angle in the help function. Very nice and clean look in the new version!
image

1 Like

see below form Modkit:
image

Is there a way to do something similar in VexCode IQ, while keeping the smart drivetrain?
We see in the dropdown command “LeftDriveSmart” for example, but it does not seem to be an active function.

Does this also work without having your drive motors set as a drivetrain?