Positional Motor Control using CANJaguar

Hello all!

I’ve returned once again to the glorious lands of CD to get some help with a puzzling problem I’m having.
This year our shooter will be mounted on a pivot point and will be attached to a CAM…(http://en.wikipedia.org/wiki/Cam)
I need to be able to rotate this CAM a specific distance/#ofdegrees from a set base position. I will need to be able to push a button and have the CAM rotate to the desired position and stay there until the button is released. Once released I would like the CAM to return to the home position. Or position 0.
I would imagine this would be simple to do…but I have been having some issues with my test-bed not functioning as expected.

Whenever the button is pushed the motor does travel the short distance expected, but when the button is released the motor does not return to 0.
Also, my getDistance(); method is not returning the distance of 5. It returns a value of about 2.35 when the motor stops. I tried using some of the other encoderDrive, PIDexample programs that use connection to the Jaguar through PWM and had zero success getting them to work at all.

At this juncture…I’m stumped by such a simple problem.

    public void robotInit() {
        TEST_Speed = 0;
        try{
           PIDTEST = new CANJaguar(3);
           PIDTEST.changeControlMode(CANJaguar.ControlMode.kPosition);
           PIDTEST.setPositionReference(CANJaguar.PositionReference.kQuadEncoder);   
           PIDTEST.configMaxOutputVoltage(100);
           PIDTEST.configEncoderCodesPerRev(80);
           PIDTEST.setPID(2.0, 0.0, 0.0);           
           PIDTEST.enableControl();
        }
        catch (Exception e){}
               

    }


Public void CAM_Control(){

       if(joy1.getRawButton(7)){
       try {
             TEST_Distance = PIDTEST.getPosition();
             PIDTEST.setX(5);

            } catch(Exception e) {}
       }
       else{
          try {
               TEST_Tistance = PIDTEST.getPosition();
                PIDTEST.setX(0);
 
               } catch(Exception e) { }
       }


}

Bump

Sorry John, usually I stay out of conversations that I don’t have a reasonable answer to, and this is one of them.

The code looks good other than this typo?] near the bottom:
TEST_Tistance = PIDTEST.getPosition();

But that should be caught at compile time.

The only suggestion I have is to print the exception in your catch blocks. You could be getting a CANTimeoutException when you start your move. Sometimes this resets the Jag, and would result in an incomplete move, and the inability to go back to position 0, since you would by default the Jag would reset into VBus mode.

The most common cause of a timeout when you start a big position move on the Jags is overdrawing current. I’d find that hard to believe with a cam setup though. Flipping the limit switch jumpers sideways to enable the ramping feature on the Jags is a quick and easy way to avoid over-drawing current in these kinds of applications.

Does it work as expected in BDC-COMM?

Here’s what we do:

                armMotor.changeControlMode(CANJaguar.ControlMode.kPosition);
                armMotor.setPositionReference(CANJaguar.PositionReference.kPotentiometer);
                armMotor.configPotentiometerTurns(10);
                armMotor.configNeutralMode(CANJaguar.NeutralMode.kBrake);
                armMotor.setPID(P, I, D);
                armMotor.setX(position);
                armMotor.enableControl();