|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
| Thread Tools | Rate Thread | Display Modes |
|
#61
|
|||||
|
|||||
|
Re: Autonomous Help
Quote:
In robotInit(), delete the Encoder part of your encoder instantiaton. It should look like this: Code:
encoder = new Encoder(0, 1, false, EncodingType.k4X); |
|
#62
|
|||
|
|||
|
Re: Autonomous Help
Quote:
Yeah I think that could do it lol heres what I got. 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 = new Encoder(0, 1, false, EncodingType.k4X);
encoder.setDistancePerPulse(1);
encoder.getDistance();
}
public void autonomousPeriodic() {
gyro1.reset();
while(isAutonomous() && isEnabled()) {
double angle = gyro1.getAngle();
double distance = encoder.get();
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.get();
SmartDashboard.putNumber("Distance", distance2);
robot.drive(-0.20, -angle2 * Kp);
if(encoder.getDistance() < 10) {
robot.drive(0,0);
break;
}
Timer.delay(0.1);
}
}
|
|
#63
|
|||||
|
|||||
|
Re: Autonomous Help
Quote:
|
|
#64
|
|||
|
|||
|
Re: Autonomous Help
Quote:
![]() |
|
#65
|
||||
|
||||
|
Re: Autonomous Help
Quote:
e.g. What were you measuring these voltages with? etc |
|
#66
|
|||||
|
|||||
|
Re: Autonomous Help
Quote:
So what seems to have been happening in your old code was because you had that Encoder part on the one line you were declaring a new local variable called encoder which was only used locally, and when robotInit ended it was removed from memory. What this means is that the field you called encoder was never given a value. Take a look at the old code, I'm going to bold the local variable and underline the field so you can see what I'm talking about. 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() {
}
}
|
|
#67
|
|||
|
|||
|
Re: Autonomous Help
Quote:
Still not getting anything printed to my smartdash board do I need to make a new dashboard or something like that. |
|
#68
|
|||
|
|||
|
Re: Autonomous Help
We put the robot on a table and held it up right. Then we got a multimeter and used the dc volts setting. Let me know if you need more info and I can ask the electronic guy.
|
|
#69
|
||||
|
||||
|
Re: Autonomous Help
Quote:
I'm surprised you could actually see the hi/lo voltage transitions with just a multimeter if you were measuring while running your autonomous routine. Are you sure that's what was done? I had suggested turning the encoder very slowly by hand. |
|
#70
|
|||||
|
|||||
|
Re: Autonomous Help
You shouldn't need to create a new one. The Distance boxis appearing on the dashboard correct? It just isn't showing any numbers other than 0?
|
|
#71
|
|||
|
|||
|
Re: Autonomous Help
No the box does not even appear so that's why I am wondering if i need to create one or something.
|
|
#72
|
|||
|
|||
|
Re: Autonomous Help
This is why you should use command based robot, with a turn x degrees command, drive subsyem with your encoders
|
|
#73
|
|||||
|
|||||
|
Re: Autonomous Help
You don't need to create one, it should do it on it's own. This is a very interesting one indeed. So the robot is obviously running the code, but the data isn't making it to the SmartDashboard. Are there any errors on your drive station console or in the riolog?
|
|
#74
|
|||
|
|||
|
Re: Autonomous Help
Quote:
Okay, my mentor told me that he was not really seeing a square wave however, he did see a spike in voltage and a drop in voltage. But we will try spinning it slowly by hand, we took the lazy way out last time because we did not really want to take the encoder off. |
|
#75
|
|||
|
|||
|
Re: Autonomous Help
Quote:
|
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|