|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
| Thread Tools | Rate Thread | Display Modes |
|
#31
|
|||
|
|||
|
Re: Autonomous Help
Quote:
|
|
#32
|
|||
|
|||
|
Re: Autonomous Help
Okay we testing out the encoder with our multimeter the volts seem good we got .4 to 5v however I am still not getting a number on my smartdash and I am not stopping. Here's the whole program.
Code:
package org.usfirst.frc.team5033.robot;
import edu.wpi.first.wpilibj.Encoder;
import edu.wpi.first.wpilibj.Gyro;
import edu.wpi.first.wpilibj.IterativeRobot;
import edu.wpi.first.wpilibj.Joystick;
import edu.wpi.first.wpilibj.RobotDrive;
import edu.wpi.first.wpilibj.Timer;
import edu.wpi.first.wpilibj.CounterBase.EncodingType;
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;
public class Robot extends IterativeRobot {
RobotDrive robot;
Joystick stick;
Encoder encoder;
Gyro gyro1;
static final double Kp = 0.05;
public void robotInit() {
robot = new RobotDrive(0, 1);
stick = new Joystick(0);
gyro1 = new Gyro(0);
gyro1.reset();
gyro1.initGyro();
Encoder encoder = new Encoder(0, 1, false, EncodingType.k4X);
encoder.setDistancePerPulse(0.001);
encoder.getDistance();
}
public void autonomousPeriodic() {
gyro1.reset();
while(isAutonomous() && isEnabled()) {
double angle = gyro1.getAngle();
double distance = encoder.getDistance();
SmartDashboard.putNumber("Angle", angle);
SmartDashboard.putNumber("Distance", distance);
robot.drive(-0.25, 1);
if(angle > 150) {
robot.drive(0,0);
gyro1.reset();
encoder.reset();
Timer.delay(0.5);
break;
}
Timer.delay(0.1);
}
while (isAutonomous() && isEnabled()) {
double angle2 = gyro1.getAngle();
double distance2 = encoder.getDistance();
SmartDashboard.putNumber("Distance", distance2);
robot.drive(-0.20, -angle2 * Kp);
if(encoder.getDistance() < 10) {
robot.drive(0,0);
break;
}
Timer.delay(0.1);
}
}
public void teleopPeriodic() {
while (isOperatorControl() && isEnabled()) {
SmartDashboard.putNumber("angle", gyro1.getAngle());
stick.getThrottle();
robot.arcadeDrive(stick.getY(), -stick.getX(), false);
Timer.delay(0.1);
}
}
public void testPeriodic() {
}
}
|
|
#33
|
|||||
|
|||||
|
Re: Autonomous Help
Quote:
|
|
#34
|
|||
|
|||
|
Re: Autonomous Help
I can try this tomorrow but do I need to maybe setup the dash board to display the distance or will it just appear?
|
|
#35
|
|||||
|
|||||
|
Re: Autonomous Help
It will just appear. You are bringing up the java dashboard not the default one right?
|
|
#36
|
|||
|
|||
|
Re: Autonomous Help
Yeah what I do is switch my ds setting from remote to java and this opens my smart dashboard that I have setup with a camera and the angle reading.
|
|
#37
|
|||
|
|||
|
Re: Autonomous Help
Is there a better way to open smart dashboard for java?
|
|
#38
|
|||||
|
|||||
|
Re: Autonomous Help
That's the way we do it too. There a way to set the default to be the SmartDashboard, but I'd have to look into how to do that again.
|
|
#39
|
|||
|
|||
|
Re: Autonomous Help
So setting the pulse to 1 does not work is there anything else I can try?
Last edited by curtis0gj : 23-01-2015 at 09:51. |
|
#40
|
|||||
|
|||||
|
Re: Autonomous Help
Try doing encoder.start() in robotInit() after you declare the encoder. This method used to exist in last year's API but I don't see it in the documentation right now.
|
|
#41
|
|||
|
|||
|
Re: Autonomous Help
Quote:
start(); but it just gave me errors I guess there's no such thing this year. |
|
#42
|
|||||
|
|||||
|
Re: Autonomous Help
Can you try changing your getDistance() to just get().
|
|
#43
|
|||
|
|||
|
Re: Autonomous Help
In the init?
|
|
#44
|
|||||
|
|||||
|
Re: Autonomous Help
Code:
double distance2 = encoder.get(); |
|
#45
|
|||
|
|||
|
Re: Autonomous Help
How about double distance = encoder.get(); as well?
|
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|