|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
| Thread Tools | Rate Thread | Display Modes |
|
#1
|
||||
|
||||
|
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:
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);
Last edited by Nathan Powell : 17-01-2014 at 17:28. Reason: mistyped word. |
|
#2
|
||||
|
||||
|
Re: Programming Help: E4P Encoder
You can edit your post if you want.
|
|
#3
|
||||||
|
||||||
|
Re: Programming Help: E4P Encoder
At what rate does it increase?
|
|
#4
|
||||
|
||||
|
Re: Programming Help: E4P Encoder
It's now increasing in increments of 2 about every quarter second.
|
|
#5
|
||||
|
||||
|
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.
|
|
#6
|
||||
|
||||
|
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. |
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|