if the pan_error is less than zero you have to drive the robot urret one way and if it is greater than zero, you have to drive the robot urret the other way.
Do you also mean without a tilt servo? I think its simpler with servos, have the camera parallel to the side of your bot, and just turn until the pan angle on your camera is 0, or within 1 to -1 degrees. Otherwise, the pan error method would work. As for tilt you would have to decide how close you want your bot, if you have your camera tilted at 19-20 degrees, your bot will be centered at around 25 feet from the net. Just put the bot however close you want it to the net, point the camera’s tilt at the light, fasten it tight. Then just use the pan error method with the tilt_error instead.
I actually mean without BOTH servos… our mentors dont want them because something could potentially happen :-/ who knows. Any way, im thinking now to run a little loop thats similar to a pid that just compares the error in certain directions, if its towards the right, move the left motor, if its toward the left, move the right motor… hopefully that would work…
Okay, I have something mocked up now… How does this look??
if (swt_camera)
{
// If the image is not center, check with the allowable error range
if (pan_error > PAN_ALLOWABLE_ERROR_DEFAULT)
{
// Attempt to turn left
pwm_rightDrive_cim = pwm_rightDrive_cim = 200;
pwm_leftDrive_cim = pwm_leftDrive_fp = 120;
}
else if(pan_error < -1 * PAN_ALLOWABLE_ERROR_DEFAULT)
{
// Attempt to turn right
pwm_rightDrive_cim = pwm_rightDrive_cim = 120;
pwm_leftDrive_cim = pwm_leftDrive_fp = 200;
}
else
{
// Set drive motors to neutral
pwm_rightDrive_cim = pwm_rightDrive_cim = 127;
pwm_leftDrive_cim = pwm_leftDrive_fp = 127;
// Tell the controller that it is now on target :D
Tracking_State += STATE_PAN_ON_TARGET;
}
Oops… I just realized that we need to set what color to track with Track_color(???)… What has your team been using for these values? And where should track_color go? Should it be where the switch is turned on? Or is this already pre set? IM USING THE STREAMLINED VERSION
I just commented out the parts where it sent data to the pwm outs so that my code that I wrote earlier today -^ should have the camera control the bot instead of servos… It sounds risky to me
It’s going to be a bumpy ride. Chances are your robot isn’t going to stop dead right on target, it will glide, spin back quickly, glide…overshooting back and forth. A basic P loop would help, but that would always introduce a steady state error.
P = error * gain;
Error is the pan_error, gain is the factor at which the motor responds, the higher, the more the motor responds. The problem is as you get close, the error decreases, meaning motor output decreases. Eventually the power level will get low enough that you stop moving. This is called “Steady state error” you can only get so close before the power output is insufficient to move. You can turn up the gain, but that will very likely make it oscillate again. You should look in to PID control, or even PI, if you search around here and on google I’ll bet you can find some nice references. Also, if by experimenting you determine you need a minimum PWM value of Z to keep moving, you can do a check that if the error is past the deadband and the PWM is below Z, set it to Z, that’s a crude PI, with a fixed I output. That should work but it won’t be as precise as PI. Does this reply make any sense?
Although that is probably too complex for your use, it should give you a good idea of how PID loops work and how you can make yours. Good luck and feel free to ask more questions.
:-/ I don’t really understand the pid code… It seems a tad bit complex I think i might have to hope the bot doesnt over shoot, or i can just move the values by a little bit or make a different if and then loop that compares the values of the pan error and the allowable error that just changes the values of the motors instead of being high speed or low speed…
During user mode, you can just pulse the button that alligns the robot, and have a feedback that shows whether the bot is within the allowable deadband…and thus lessening the overshoot.
if (swt_camera)
{
if (pan_error < 5 | pan_error > -5)
{
// Set drive motors to neutral
pwm_rightDrive_cim = pwm_rightDrive_cim = 127;
pwm_leftDrive_cim = pwm_leftDrive_fp = 127;
// Tell the controller that it is now on target
Tracking_State += STATE_PAN_ON_TARGET;
}
else
{
// If the image is not center, check with the allowable error range
if (pan_error > PAN_ALLOWABLE_ERROR_DEFAULT)
{
// Attempt to turn left
pwm_rightDrive_cim = pwm_rightDrive_cim = 200;
pwm_leftDrive_cim = pwm_leftDrive_fp = 120;
}
else if(pan_error < -1 * PAN_ALLOWABLE_ERROR_DEFAULT)
{
// Attempt to turn right
pwm_rightDrive_cim = pwm_rightDrive_cim = 120;
pwm_leftDrive_cim = pwm_leftDrive_fp = 200;
}
else
{
// Set drive motors to neutral
pwm_rightDrive_cim = pwm_rightDrive_cim = 127;
pwm_leftDrive_cim = pwm_leftDrive_fp = 127;
// Tell the controller that it is now on target
Tracking_State += STATE_PAN_ON_TARGET;
}
}
}
Sorry I can’t really format it inside this little form :-/
Here is a more complex PID version. I won’t claim its perfect, but it works fairly well. This uses integer math, and it divides by the constants to make them less than 1.0. The “JERK” part is a kludge that we needed to get past the problem of too much friction in out drive train.