Quote:
Originally Posted by sircedric4
Yikes, I thought for sure with 1800+ teams all wanting encoder driven robots there would have been an easier way. I have the basics of C down but everytime someone starts breaking out wrappers and stuff my brain just shuts down. I can handle the canned libraries and subroutines I write myself using old school subroutine and function practices but all these additional wrappers and classes and stuff is a different way of thinking. I will dig into the above code and see what I can do with it and see if I can understand it, but while thinking of this problem I realized another problem.
Seeing as I have both a left and a right encoder and RobotDrive controls all motors how do I keep two PIDControllers based on the different encoders from getting into a fist fight with each other? One will be telling RobotDrive to do one thing and the other another and I suspect only the last controller will actually have the power. I guess I will have to tie the two left motors controls and the two right motors controls into some sort of combination and use separate controllers for each side. Can I somehow wrap two Victors or Jaguars to be controlled by the same PIDController?
If I have to add all this code anyway instead of being able to just call a simple library function I may be better off just writing my own PID subroutine that is specific to my needs. At least then I might understand what everything is doing when it comes time to debug.
I think that I am not the only one that wants this information so thanks everyone and keep the info coming. I will continue to post my progress as I try to get this stuff working in the hopes it helps someone as much as me.
|
One way to deal with left and right encoders is as follows:
Code:
class AverageDistanceEncoder extends PIDSource
{
public:
AverageDistanceEncoder(Encoder *leftEncoder, Encoder *rightEncoder)
{
m_leftEncoder = leftEncoder;
m_rightEncoder = rightEncoder;
{
double pidGet()
{
return (m_leftEncoder->GetDistance() + m_rightEncoder->GetDistance())/2.0;
}
private:
Encoder* m_leftEncoder;
Encoder* m_rightEncoder;
};
This averages the left and right readings and would then command both sides of the drive to do the same thing As long as the robot drives relatively straight on its own, that should be all you need.
(In general, it is easiest to tell your robot just to drive in straight lines and turn in place in autonomous mode - fancy arcs can be quite a bit trickier).