View Single Post
  #3   Spotlight this post!  
Unread 14-03-2011, 01:55
Bethie42's Avatar
Bethie42 Bethie42 is offline
Registered User
AKA: Bethany Carlson
FRC #0956 (Eagle Cybertechnology)
Team Role: Alumni
 
Join Date: Dec 2009
Rookie Year: 2008
Location: Oregon
Posts: 126
Bethie42 is a splendid one to beholdBethie42 is a splendid one to beholdBethie42 is a splendid one to beholdBethie42 is a splendid one to beholdBethie42 is a splendid one to beholdBethie42 is a splendid one to beholdBethie42 is a splendid one to beholdBethie42 is a splendid one to behold
Re: Limit switches in autonomous

Quote:
Originally Posted by virtuald View Post
Nothing looks wrong in your code, so it might be some problem with your initialization -- or possibly your autonomous function isn't being called for some reason -- use the normal printf and check NetConsole's output to see if it ever actually happens.

As another suggestion, you can wire limit switches directly to the Jaguar, and it will automatically turn itself off when the switch is pressed. Refer to the Jaguar user's guide for more information.
Thanks for your response.
The rest of our autonomous code is definitely running, so do you think the limit-switch if-statement itself is not getting called? Here is our initialization:

We understand that it's not legal to control a Jag [actually, now we are using Victors] directly using a limit switch unless you are using CAN [which looked to be a bigger headache than it's worth] as per <R55> J.

When we originally encountered this problem, we planned to workaround it by just running the elevator motor up in autonomous until we reach the scoring grid: we figured that we would reach the scoring grid about the same time the elevator reached the top and started to stall. This would have worked very nicely, except that we recently replaced our wimpy little window-motor with a Fischer-Price motor that cleanly sheared our elevator belt the other day when we ran it just a bit too far! Now I am very wary of running autonomous that way unless I scale the motor back to about 20% rather than 100%. I eagerly await our Week 4 regional....

Thanks again for any help you can give.

Code:
#include "WPILib.h"
//#include "Vision/AxisCamera.h"
//#include "Vision/HSLImage.h"
#include "DriverStationLCD.h"
#include <math.h>

// mapping of solenoids to ports
#define GRIPPER_SOL 1
#define ELBOW_SOL 2
#define DEPLOYMENT_SOL 3

class Team956 : public IterativeRobot
{
	
	RobotDrive *robotDrive;		// robot will use PWM 1-4 for drive motors
	
	// Declare a variable for the driver station object
	DriverStation *driverStation;	// driver station object
	DriverStationLCD *driverStationLCD; // Driver station LCD for printouts
	UINT32 priorPacketNumber;	    // keep track of the most recent packet number from the DS
	UINT8 dsPacketsReceivedInCurrentSecond;	// keep track of the ds packets received in the current second
	
	
	Joystick *rJS;         // joystick 1
	Joystick *lJS;         // joystick 2 
	Joystick *elevatorJS;  //controls elevator for gripper 
	
	//PWM *rMotor1;    //interferes with RobotDrive object
	//PWM *rMotor2;
	//PWM *lMotor1;
	//PWM *lMotor2;   
	
	Victor *elevatorVictor; //elevator delivery system for gripper, y-axis, controlled by joystick
	Victor *deploymentVictor; // Motor for deployment of minibot
	
	
	Solenoid *gripperSol; //opens and closes  gripper 
	Solenoid *elbowSol; //raises and lowers 'elbow'
	Solenoid *deploymentSol; // Opens and closes 'latch' for surgical tubing
	
	Relay *compressorRelay; //relay for compressor
		
	DigitalInput *pneumaticLimitSwitch; // shuts off compressor when PSI = 120
	DigitalInput *lLineTracker;			// line tracking sensors
	DigitalInput *mLineTracker;
	DigitalInput *rLineTracker;
	DigitalInput *outDeploymentLimitSwitch; // Shuts off deployment victor if max extension
	DigitalInput *inDeploymentLimitSwitch; // Min extension reached
	DigitalInput *topElevatorLimitSwitch; 
	DigitalInput *bottomElevatorLimitSwitch;
	
	
	
	DigitalInput *rEnCA; //Right encoder channel A
	DigitalInput *rEnCB; //Right encoder channel B
	DigitalInput *lEnCA; //Left  encoder channel A
	DigitalInput *lEnCB; //Left  encoder channel B  
	DigitalInput *elevatorEncoderCA;
	DigitalInput *elevatorEncoderCB;
	
	Encoder *rEncoder; //Right encoder
	Encoder *lEncoder; //Left encoder
	
	
//	AxisCamera &camera; //Camera now wired directly to radio
	
	
	
	// Local variables to count the number of periodic loops performed
	UINT32 autoPeriodicLoops;
	UINT32 disabledPeriodicLoops;
	UINT32 telePeriodicLoops;
	
	enum state {DRIVE=0, STOP=1,SCORE=2, BACKUP=3}; 
	state autoState;
	int leftValue;	
	int middleValue;
	int rightValue;
	 
	int autoFlag;
	int aState;
	
	int LencVal;
	int RencVal;
	
	float speed;
	
	bool atCross; 
		
public:

 // Constructor for the "Team956" Class.

	Team956(void) /* :	camera(AxisCamera::GetInstance())*/
	{
		printf("Team956 Constructor Started\n");

		// Create a robot using standard right/left robot drive on PWMS 1, 2, 3, and #4
		robotDrive = new RobotDrive(1,2,3,4); //used to be(1, 3, 2, 4);  changed for Left on PWM's 3,4 and Right on 1,2
		robotDrive->SetSafetyEnabled(false); //disables MotorSafety watchdog
		
		// Acquire the Driver Station object 
		driverStation = DriverStation::GetInstance();
		driverStationLCD = DriverStationLCD::GetInstance();
		priorPacketNumber = 0;
		dsPacketsReceivedInCurrentSecond = 0;
		
	// joysticks
		rJS = new Joystick(1);
		lJS = new Joystick(2);
		elevatorJS = new Joystick(3); //controls elevator for gripper 
		
	
	// PWM's
		//rMotor1 = new PWM(1);  // commented out becuase 'RobotDrive initializes motors
		//rMotor2 = new PWM(2);
		//lMotor1 = new PWM(3);
		//lMotor2 = new PWM(4);
			
		elevatorVictor = new Victor(5);
		elevatorVictor->SetSafetyEnabled(false); //disable the Victor MotorSafety watchdog
		deploymentVictor = new Victor(6);
		deploymentVictor->SetSafetyEnabled(false); 
		
	// solonoids
		gripperSol = new Solenoid(GRIPPER_SOL); 
		
		elbowSol = new Solenoid(ELBOW_SOL);
		deploymentSol= new Solenoid(DEPLOYMENT_SOL);
			
		
	// digital i/o
		pneumaticLimitSwitch = new DigitalInput(1);
		rLineTracker = new DigitalInput(2); 
		mLineTracker = new DigitalInput(3);
		lLineTracker = new DigitalInput(4);
		
	    rEnCA = new DigitalInput(5);
		rEnCB = new DigitalInput(6);
		lEnCA = new DigitalInput(7);
		lEnCB = new DigitalInput(8);  
		
		outDeploymentLimitSwitch = new DigitalInput(9);
		inDeploymentLimitSwitch = new DigitalInput(10);
		topElevatorLimitSwitch = new DigitalInput(11);
		bottomElevatorLimitSwitch = new DigitalInput(12);
	
		
		
		//aChannel, bChannel, reverse direction if encoders are oriented backwards (usually false), type of encoding (1x, 2x, 4x)
		rEncoder = new Encoder(rEnCA->GetChannel(),rEnCB->GetChannel(),false,Encoder::k4X);
		lEncoder = new Encoder(lEnCA->GetChannel(),lEnCB->GetChannel(),false,Encoder::k4X);
		
/*		camera.WriteResolution(AxisCamera::kResolution_320x240);
		camera.WriteCompression(20); // }from 2010ImageDemo
		camera.WriteBrightness(0);     
*/		
		GetWatchdog().SetEnabled(false); // User watchdog should be disabled even without this...
		//GetWatchdog().SetExpiration(10);	//sets watchdog expiration to 1 second
		compressorRelay = new Relay(1, Relay::kForwardOnly);

	

		// Initialize counters to record the number of loops completed in autonomous and teleop modes
		autoPeriodicLoops = 0;
		disabledPeriodicLoops = 0;
		telePeriodicLoops = 0;
		
		// autonomous stuff
    	autoState = DRIVE;
    	
		            
	atCross = false; 
	autoFlag = false;  // Lisa, can we comment these out?

		printf("BuiltinDefaultCode Constructor Completed\n");
	}
	

	
	/// Init Routines 
	void RobotInit(void) {
		
		printf("RobotInit() completed.\n");
	}
	
	void DisabledInit(void) {
		disabledPeriodicLoops = 0;			// Reset the loop counter for disabled mode
	}

	void AutonomousInit(void) {
		autoPeriodicLoops = 0;				// Reset the loop counter for autonomous mode
		rEncoder->Reset();
		lEncoder->Reset(); 
		rEncoder->Start(); // Start getting values from the encoders
		lEncoder->Start();
		driverStationLCD->Clear();
		
	}

	void TeleopInit(void) {
		telePeriodicLoops = 0;				// Reset the loop counter for teleop mode
		dsPacketsReceivedInCurrentSecond = 0;	// Reset the number of dsPackets in current second
		rEncoder->Reset();
		lEncoder->Reset(); 
		rEncoder->Start(); // Start getting values from the encoders
		lEncoder->Start();
		driverStationLCD->Clear();
		
	}
__________________
Robot is now a verb.

We're back to square one...while we're at it, let's redesign square one!

Team 956: Celebrating ten years of FIRST!

Code:
Team record 2002-2011
2002: Highest Rookie Seed, AOR
2003, 2006, 2012: Xerox Creativity Award, AOR
2006: Semi-finalist, Sacramento Regional
2009: Quarter-finalist, AOR
2010: Quarter-finalist, AOR
2011: Semi-finalist, AOR, and Dean's List finalist, AOR 

Personal record: 
2008: Lead scout
2009: Lead scout, publicity
2010: Lead scout, publicity, fundraising, Chairman's, videography
2011: Team captain, lead programmer, fundraising, Chairman's, publicity, wrench-turning, Dean's List finalist at Autodesk Oregon Regional
Reply With Quote