Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   Java (http://www.chiefdelphi.com/forums/forumdisplay.php?f=184)
-   -   Autonomous Help (http://www.chiefdelphi.com/forums/showthread.php?t=133182)

curtis0gj 22-01-2015 10:23

Re: Autonomous Help
 
Quote:

Originally Posted by Ether (Post 1432101)
The E4P-250-250-N-S-D-D-B has single-ended outputs, and according to the datasheet you should get a square wave on each of the 2 output signal channels (A & B).

As you manually rotate the encoder shaft (very very slowly), you should see the voltage going from ~5V to ~0.4V on each channel.



Alright I will give this a shot I'm not the best with electrical stuff but this sounds doable.

curtis0gj 22-01-2015 16:23

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() {
   
    }
   
}


notmattlythgoe 22-01-2015 17:25

Re: Autonomous Help
 
Quote:

Originally Posted by curtis0gj (Post 1432297)
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() {
   
    }
   
}


Try setting the distance per pulse to 1.

curtis0gj 22-01-2015 17:57

Re: Autonomous Help
 
Quote:

Originally Posted by notmattlythgoe (Post 1432335)
Try setting the distance per pulse to 1.

I can try this tomorrow but do I need to maybe setup the dash board to display the distance or will it just appear?

notmattlythgoe 22-01-2015 18:01

Re: Autonomous Help
 
Quote:

Originally Posted by curtis0gj (Post 1432351)
I can try this tomorrow but do I need to maybe setup the dash board to display the distance or will it just appear?

It will just appear. You are bringing up the java dashboard not the default one right?

curtis0gj 22-01-2015 18:08

Re: Autonomous Help
 
Quote:

Originally Posted by notmattlythgoe (Post 1432354)
It will just appear. You are bringing up the java dashboard not the default one right?

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.

curtis0gj 23-01-2015 09:44

Re: Autonomous Help
 
Quote:

Originally Posted by curtis0gj (Post 1432359)
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.

Is there a better way to open smart dashboard for java?

notmattlythgoe 23-01-2015 09:47

Re: Autonomous Help
 
Quote:

Originally Posted by curtis0gj (Post 1432613)
Is there a better way to open smart dashboard for java?

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.

curtis0gj 23-01-2015 09:49

Re: Autonomous Help
 
Quote:

Originally Posted by notmattlythgoe (Post 1432615)
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.

So setting the pulse to 1 does not work is there anything else I can try?

notmattlythgoe 23-01-2015 09:54

Re: Autonomous Help
 
Quote:

Originally Posted by curtis0gj (Post 1432617)
So setting the pulse to 1 does not work is there anything else I can try?

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.

curtis0gj 23-01-2015 09:57

Re: Autonomous Help
 
Quote:

Originally Posted by notmattlythgoe (Post 1432618)
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.

Yeah I have been encoder
start(); but it just gave me errors I guess there's no such thing this year.

notmattlythgoe 23-01-2015 09:59

Re: Autonomous Help
 
Quote:

Originally Posted by curtis0gj (Post 1432620)
Yeah I have been encoder
start(); but it just gave me errors I guess there's no such thing this year.

Can you try changing your getDistance() to just get().

curtis0gj 23-01-2015 10:01

Re: Autonomous Help
 
Quote:

Originally Posted by notmattlythgoe (Post 1432622)
Can you try changing your getDistance() to just get().

In the init?

notmattlythgoe 23-01-2015 10:03

Re: Autonomous Help
 
Code:

double distance2 = encoder.get();

curtis0gj 23-01-2015 10:07

Re: Autonomous Help
 
Quote:

Originally Posted by notmattlythgoe (Post 1432626)
Code:

double distance2 = encoder.get();

How about double distance = encoder.get(); as well?


All times are GMT -5. The time now is 10:30.

Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi