EasyC V4 PID Control Implementation?

Hello VexForum,

We have built a scissor lift for this year’s game, unfortunately we need to get each side to move up more uniformly. I know that if using the IMEs that there is just a basic PID Control function which can be used. We aren’t using IMEs (at least not yet anyway…). Does anyone have a PID Control Implementation that they’d share? We’d just like to look for reference. I’ve personally seen implementations in RobotC, yet converting it over doesn’t seem to be the easiest. I believe the joystick would only control one side (the master) and the other side would be controlled and updated via the loop (the slave), but getting it all worked out is the hard part. We currently have two motors on each side of our scissor lift (https://www.youtube.com/watch?v=mgsXG8wY4TU) which just climbs a rack [other half has since been added]. Anyone have any experience implementing in EasyC?

Thanks!
carp

PID control is a little trickier in EasyC due to the lack of RTOS or access to low level timers or interrupts. However, there are two ways it can be done.

  1. Create a function to perform the PID math, inputs to the function can be current and target positions, return value is motor drive. If you want you could combine all parameters into a structure and then pass a pointer. Call the function from the main while loop in operator control or autonomous, you will need some small delay in the while loop which will be code dependent but somewhere around 10-25mS.

  2. Use a repeating timer. Perform the PID math in the repeating timer callback, keep the code in this function to a minimum so as not to impede performance of the rest of your code. Set a global variable in the callback that is used to drive the motors from your main while loop, you could also use globals to pass target position etc. You need to use RegisterImeRepeatingTimer (according to the EasyC help file) when using IMEs rather than the standard function, no idea why, seems kludgy and something the library should have handled.

Method 2 is preferable and will work better, it is not influenced by “print to screen” or other debug statements you may add to the main code. Method 1 is simpler but you will need to keep tuning the PID if you add a significant of additional code of add debug statements.

Take a look at this old thread as, although it does not implement PID, it uses some of the techniques described above.

Preset arm heights in EasyC v4

see post #25 for an example of using a repeating timer.

FYI, converting pure ROBOTC code to EasyC is not hard, however, the lack of “tasks” often means the code structure may need to be changed a little. My old PID library should port over with very little change.

Edit.

I should add that EasyC also has some bullt in PID for use with the IMEs. Never used this and it only works with the IMEs but it implements (more or less) what I described as method 2. There’s also a new function called RegisterImeInterruptServiceRoutine that may be of help