Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   Java (http://www.chiefdelphi.com/forums/forumdisplay.php?f=184)
-   -   Multiple Counter objects with Analog Triggers issues. (http://www.chiefdelphi.com/forums/showthread.php?t=134316)

AlexanderTheOK 14-02-2015 20:27

Re: Multiple Counter objects with Analog Triggers issues.
 
One thing I almost forgot to post in this thread. The code I posted in the beginning of the thread WILL NOT WORK reliably to count rollovers on the MA3 encoders. This is because the original code did not make a call to the "setFiltered" method. This takes a boolean and is made specifically to facilitate rollovers. The corrected code looks like this:

Code:

public class Robot extends IterativeRobot {
       
        Joystick controller = new Joystick(0);
       
       
        VictorSP motor1 = new VictorSP(7);
        VictorSP motor2 =  new VictorSP(17);
       
        AnalogInput ma31 = new AnalogInput(0);
        AnalogInput ma32 = new AnalogInput(3);
       
        AnalogTrigger Trigger1 = new AnalogTrigger(ma31);
        AnalogTrigger Trigger2 = new AnalogTrigger(ma32);
       
        Counter Counter1 = new Counter();
        Counter Counter2 = new Counter();
       
    /**
    * This function is run when the robot is first started up and should be
    * used for any initialization code.
    */
    public void robotInit() {
           
            Trigger1.setLimitsVoltage(0.5, 4.5);
            Trigger2.setLimitsVoltage(0.5,4.5);

        Trigger1.setFiltered(true);
        Trigger2.setFiltered(true);
       
            Counter1.setUpDownCounterMode();
            Counter2.setUpDownCounterMode();
           
            Counter1.setUpSource(Trigger1, AnalogTriggerType.kRisingPulse);
            Counter1.setDownSource(Trigger1, AnalogTriggerType.kFallingPulse);

            Counter2.setUpSource(Trigger2, AnalogTriggerType.kRisingPulse);
            Counter2.setDownSource(Trigger2, AnalogTriggerType.kFallingPulse);
           
    }

    /**
    * This function is called periodically during autonomous
    */
    public void autonomousPeriodic() {

    }

    /**
    * This function is called periodically during operator control
    */
    public void teleopPeriodic() {
           
            if(controller.getRawButton(1)) motor1.set(0.2);
            else if(controller.getRawButton(2)) motor1.set(-0.2);
            else if(controller.getRawButton(3)) motor2.set(0.2);
            else if(controller.getRawButton(4)) motor2.set(-0.2);
            else{
                    motor1.set(0);
                    motor2.set(0);
            }
        System.out.println(Counter1.get()+ "    " + Counter2.get() + "  " + ma31.getVoltage()+ "  " + ma32.getVoltage());
    }
   
    /**
    * This function is called periodically during test mode
    */
    public void testPeriodic() {
   
    }
   
}


This is unrelated to the issue this thread is about, but future readers who may be using code from chief delphi may come across this and use the original code as an example, so I will leave this here to avoid confusing anyone.

Huge thanks to Brad Miller, Joe Hersh, and Kevin O'Connor. I would be struggling with a lot of communications code and an offboard processor to make our first swerve drive work if it wasn't for the fast and precise work and diagnosis of these fine gentlemen.


All times are GMT -5. The time now is 13:07.

Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi