Go to Post oooh tight leather bumpers...sexy! - Nuttyman54 [more]
Home
Go Back   Chief Delphi > Technical > Programming > C/C++
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Reply
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 01-16-2014, 06:21 PM
Nathan Powell's Avatar
Nathan Powell Nathan Powell is offline
The Prime Function
FRC #2582 (PantherBots)
Team Role: Alumni
 
Join Date: Jan 2012
Rookie Year: 2012
Location: Lufkin, TX
Posts: 37
Nathan Powell is an unknown quantity at this point
Programming Help: E4P Encoder

Greetings.
This year my team has decided to use AndyMark E4P encoders on our drive train for use in autonomous. We are using the SmartDashboard as an alternative to the FRC Dashboard. However, after mounting them and and running the code, we encountered some difficulties:
  • The encoder rate begins counting in increments of 1 as soon as tele-op is enabled. Disabling stops it, but it begins again when enabled
  • Whenever the encoders are plugged in, our drive chain does not work. Either it doesn't respond to the joystick input, or the encoders might be blocking it somehow.
We've checked the wires, and tried different variations of the code below. I've also searched Chief Delphi, but nothing I've found seems to work. Can anyone offer assistance?

Code:
#include "WPILib.h"
#include "AnalogRangeFinder.h"

//#define ANALOG_CHANNEL_FOR_SONAR 1

/**
 * This is a demo program showing the use of the RobotBase class.
 * The SimpleRobot class is the base of a robot application that will automatically call your
 * Autonomous and OperatorControl methods at the right time as controlled by the switches on
 * the driver station or the field controls.
 */ 
//static int ULTRASONIC_ECHO_PULSE_OUTPUT = 3;
//static int ULTRASONIC_TRIGGER_PULSE_INPUT = 4;

class RobotDemo : public SimpleRobot
{
	RobotDrive Tank_Drive; // robot drive system
	Joystick stick; 
	Encoder en_right;
	Encoder en_left;
	Victor Arm_Motor;
	//AnalogChannel pot;
	//AnalogRangeFinder us;
	//PIDController *armPID;
	LiveWindow *lw;
	//SmartDashboard sm;
	
	//DigitalInput ULTRASONIC_PING;
	//DigitalOutput ULTRASONIC_ECHO;
	
	
	
public:
	RobotDemo(void):
		Tank_Drive(3,4,2,1),
		stick(1),
		en_right (5, 6, true),
		en_left (7, 8, true),
		//us (1, 2),
		Arm_Motor (3)
		//pot (1, 1)
		//us (ANALOG_CHANNEL_FOR_SONAR)
		
		
	{
		//armPID->Enable();
		
		//pot = new AnalogChannel(1);
		//armPID = new PIDController(1, 1, 0, &pot, &Arm_Motor);
		lw = LiveWindow::GetInstance();
		//lw -> AddSensor("Arm", "Potentiometer", pot);
		
		en_right.SetMinRate(10);
		en_left.SetMinRate(10);
		en_right.SetDistancePerPulse(200);
		en_left.SetDistancePerPulse(200);
		
		//us.SetDistanceUnits(Ultrasonic::kInches);
		//us.SetAutomaticMode(TRUE);
		
		Tank_Drive.SetExpiration(0.1);
		
		
	}

	/**
	 * Drive left & right motors for 2 seconds then stop
	 */
	void Autonomous(void)
	{
		en_right.Start();
		en_left.Start();
		Tank_Drive.SetSafetyEnabled(false);
		Tank_Drive.Drive(-0.5, 0.0); 	// drive forwards half speed
		Wait(2.0); 				//    for 2 seconds
		Tank_Drive.Drive(0.0, 0.0); 	// stop robot
		en_right.Stop();
		en_left.Stop();
		en_right.Reset();
		en_left.Reset();
	}

	/**
	 * Runs the motors with arcade steering. 
	 */
	void OperatorControl(void)
	{
		en_right.Start();
		en_left.Start();
		Tank_Drive.SetSafetyEnabled(true);
		while (IsOperatorControl())
		{
			//double range = us.GetRangeInches();
			//DriverStation::GetInstance();
			//DriverStation::CheckAnalogChannel(1);
			//armPID -> SetInputRange(.8, 1);
			//armPID -> SetOutputRange(.25, .5);
			//armPID -> SetSetpoint(3);
			
			
			
			//Tank_Drive.ArcadeDrive(stick); // drive with arcade style (use right stick)
			Tank_Drive.SetLeftRightMotorOutputs(1 * (stick.GetRawAxis(2)) + stick.GetRawAxis(1), 1 * (stick.GetRawAxis(2)) - stick.GetRawAxis(1));
			//Tank_Drive.TankDrive(stick.GetRawAxis(5), stick.GetRawAxis(2));
			
			//if (stick.GetTrigger()){
			//
			//armPID -> Enable();		//Starts calculating the PID values
			//}
			
			//always check the cRIO card first!!
			//SmartDashboard::PutNumber("Potentiometer 1: ", pot.GetVoltage());
			

                        SmartDashboard::PutNumber("Encoder 1 Rate: ", en_right.GetRaw());
			SmartDashboard::PutNumber("Encoder 2 Rate: ", en_left.GetRaw());
			

//SmartDashboard::PutNumber("Encoder 1 Count ", en_right.Get());
			//SmartDashboard::PutNumber("Encoder 2 Count: ", en_left.Get());
			//SmartDashboard::PutNumber("Rangefinder 1: ", range);
			//SmartDashboard::PutNumber("Y-Axis", stick.GetRawAxis(2));
			//SmartDashboard::PutNumber("X-Axis", stick.GetRawAxis(1));
			//SmartDashboard::PutNumber("armPID: ", armPID -> Get());
			Wait(0.005);				// wait for a motor update time
			//armPID -> Disable();
			
		}en_right.Stop();
		en_left.Stop();
		en_right.Reset();
		en_left.Reset();
	}
	
	/**
	 * Runs during test mode
	 */
	void Test() {
		//DriverStation::GetInstance();
			//		DriverStation::CheckAnalogChannel(1);
	}
};

START_ROBOT_CLASS(RobotDemo);
I know, my code's a little messy at the moment, but I've been working on other sensors in addition to the encoder. Sorry for the inconvenience.

Last edited by Nathan Powell : 01-17-2014 at 05:28 PM. Reason: mistyped word.
Reply With Quote
  #2   Spotlight this post!  
Unread 01-16-2014, 06:35 PM
Ether's Avatar
Ether Ether is offline
systems engineer (retired)
no team
 
Join Date: Nov 2009
Rookie Year: 1969
Location: US
Posts: 7,999
Ether has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond repute
Re: Programming Help: E4P Encoder

Quote:
Originally Posted by Nathan Powell View Post
I meant "inconvenience". Apologies.
You can edit your post if you want.


Reply With Quote
  #3   Spotlight this post!  
Unread 01-16-2014, 07:41 PM
Joe Ross's Avatar Unsung FIRST Hero
Joe Ross Joe Ross is offline
Registered User
FRC #0330 (Beachbots)
Team Role: Engineer
 
Join Date: Jun 2001
Rookie Year: 1997
Location: Los Angeles, CA
Posts: 8,547
Joe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond repute
Re: Programming Help: E4P Encoder

At what rate does it increase?
Reply With Quote
  #4   Spotlight this post!  
Unread 01-17-2014, 05:28 PM
Nathan Powell's Avatar
Nathan Powell Nathan Powell is offline
The Prime Function
FRC #2582 (PantherBots)
Team Role: Alumni
 
Join Date: Jan 2012
Rookie Year: 2012
Location: Lufkin, TX
Posts: 37
Nathan Powell is an unknown quantity at this point
Re: Programming Help: E4P Encoder

It's now increasing in increments of 2 about every quarter second.
Reply With Quote
  #5   Spotlight this post!  
Unread 01-17-2014, 05:38 PM
Nathan Powell's Avatar
Nathan Powell Nathan Powell is offline
The Prime Function
FRC #2582 (PantherBots)
Team Role: Alumni
 
Join Date: Jan 2012
Rookie Year: 2012
Location: Lufkin, TX
Posts: 37
Nathan Powell is an unknown quantity at this point
Re: Programming Help: E4P Encoder

When I remove the parameters I set (.SetMinRate(10) and .SetDistancePerPulse(200)) it increased in increments of one about every half second. Not sure why, though.
Reply With Quote
  #6   Spotlight this post!  
Unread 01-17-2014, 07:40 PM
Nathan Powell's Avatar
Nathan Powell Nathan Powell is offline
The Prime Function
FRC #2582 (PantherBots)
Team Role: Alumni
 
Join Date: Jan 2012
Rookie Year: 2012
Location: Lufkin, TX
Posts: 37
Nathan Powell is an unknown quantity at this point
Re: Programming Help: E4P Encoder

Never mind: it turns out that the electrical team did not check the PWM wires as close as they claimed, as opposed to a coding error.
-sigh-
Thanks to everyone who offered their advice.
Reply With Quote
Reply


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 09:15 AM.

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