Velocity(RPM) based control loop

So what i want to do is have 2 separate control loops, one for each side of the tank drive. The way i want to implement this is to have the control loop adjust the PWM passed to the motors to match a certain velocity. I cannot though wrap my head around the process required to do this. Please Help.

-APozharskiy

Any reason why you can’t just have one loop? For instance:


task drive
{
  while(true)
  {
    //Adjust left speed here

    //Adjust right speed here

    motor[driveLeft] = leftSpeed;
    motor[driveRight] = rightSpeed;
  }
}

EDIT:
Reading over this again, you want to have a controller manage velocity correct? How I would approach this would have a task that loops every 1ms(or any amount that gives you enough accuracy) and counts how many encoder ticks have passed, and have a PD controller manage that speed.

For instance,


task drive
{
  while(true)
  {
    //Check how many encoder ticks have gone by
    
    //Do PD calculations

    motor[driveLeft] = leftSpeed;
    motor[driveRight] = rightSpeed;
    delayMs(1);
  }
}

Oh sorry i forgot to mention i was useing PROS and IME getVelocity() functions to monitor speed.

(i should also clarify i’m not sure how the adjustment loops would even work mathematically (PID Loop?) and that is the bulk of my question

You can use PID, I’m not sure exactly what the PROS function returns, the raw velocity coming from an IME needs to be converted into something useful, but assuming that you can either use this or calculate velocity by monitoring the change in position every few mS, the error in velocity becomes the input into the PID function. If velocity is too small, more drive to the motor etc. You will need to leave some headroom, that is, aim for maximum velocity somewhat lower than the motor can actually achieve.

Oh sorry I’m not totally familiar with PROs, so I won’t be much help there. For PID controllers, check out George’s Guide!