Go to Post The best way to brainstorm is to just do it. - EricH [more]
Home
Go Back   Chief Delphi > Technical > Programming > Java
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
 
 
Thread Tools Rate Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Spotlight this post!  
Unread 10-02-2015, 19:41
AlexanderTheOK AlexanderTheOK is offline
Guy
no team
 
Join Date: Jan 2014
Rookie Year: 2012
Location: Los Angeles
Posts: 146
AlexanderTheOK is just really niceAlexanderTheOK is just really niceAlexanderTheOK is just really niceAlexanderTheOK is just really nice
Multiple Counter objects with Analog Triggers issues.

As the title suggests I am having issues with the Counter class. I am specifically using MA3 encoders and using the Counter and Analog Trigger classes to keep track of rollovers. This works fine when using a single MA3, however, with multiple it seems that only the counter created first in code works. The others don't throw exceptions, dont give errors, just simply don't register rollovers and simply don't count. I know the analog inputs themselves are working fine, as well as the analog triggers, so I have narrowed it down to the counter.

The barebones code I used to test this issue is below. If anybody can tell me where I screwed up I would be very grateful.

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);
    	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() {
    
    }
    
}
Thanks for your time and advice in advance.
Reply With Quote
 


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


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

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


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