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)

notmattlythgoe 23-01-2015 12:38

Re: Autonomous Help
 
Quote:

Originally Posted by curtis0gj (Post 1432724)
Sure! What we did was while running an autonomous movement code we were measuring dc voltage across the +5 and the common and we got a reading of +5. Then we ran it across the signal cables to the common and it was showing a square wave pretty much.

I think I found the problem.

In robotInit(), delete the Encoder part of your encoder instantiaton. It should look like this:

Code:

encoder = new Encoder(0, 1, false, EncodingType.k4X);

curtis0gj 23-01-2015 12:46

Re: Autonomous Help
 
Quote:

Originally Posted by notmattlythgoe (Post 1432734)
I think I found the problem.

In robotInit(), delete the Encoder part of your encoder instantiaton. It should look like this:

Code:

encoder = new Encoder(0, 1, false, EncodingType.k4X);



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);       
                                }
                               
                            }


notmattlythgoe 23-01-2015 12:47

Re: Autonomous Help
 
Quote:

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


Looks good. I'm still trying to figure out why you weren't getting NullPointerExceptions with the other code...

curtis0gj 23-01-2015 12:51

Re: Autonomous Help
 
Quote:

Originally Posted by notmattlythgoe (Post 1432742)
Looks good. I'm still trying to figure out why you weren't getting NullPointerExceptions with the other code...

Hmm I've no idea what NullPointerExceptions but I don't think want any they sound pretty bad.::safety::

Ether 23-01-2015 12:52

Re: Autonomous Help
 
Quote:

Originally Posted by curtis0gj (Post 1432724)
we were measuring dc voltage across the +5 and the common and we got a reading of +5. Then we ran it across the signal cables to the common and it was showing a square wave pretty much.

Would you please describe your test setup?
e.g. What were you measuring these voltages with? etc



notmattlythgoe 23-01-2015 12:57

Re: Autonomous Help
 
Quote:

Originally Posted by curtis0gj (Post 1432744)
Hmm I've no idea what NullPointerExceptions but I don't think want any they sound pretty bad.::safety::

A NullPointerException happens when you try to access an object like an encoder, but the object has never been given an initial value.

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

Do you see how the underlined one never has the statement new Encoder(...) called for it? So it was never given an initial value.

curtis0gj 23-01-2015 13:03

Re: Autonomous Help
 
Quote:

Originally Posted by notmattlythgoe (Post 1432751)
A NullPointerException happens when you try to access an object like an encoder, but the object has never been given an initial value.

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

Do you see how the underlined one never has the statement new Encoder(...) called for it? So it was never given an initial value.


Still not getting anything printed to my smartdash board do I need to make a new dashboard or something like that.

curtis0gj 23-01-2015 13:04

Re: Autonomous Help
 
Quote:

Originally Posted by Ether (Post 1432745)
Would you please describe your test setup?
e.g. What were you measuring these voltages with? etc



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.

Ether 23-01-2015 13:09

Re: Autonomous Help
 
Quote:

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

It just sounded like you were using either an oscilloscope or on-board voltage sampling. (You said it was "showing" a square wave).

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.




notmattlythgoe 23-01-2015 13:10

Re: Autonomous Help
 
Quote:

Originally Posted by curtis0gj (Post 1432755)
Still not getting anything printed to my smartdash board do I need to make a new dashboard or something like that.

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?

curtis0gj 23-01-2015 13:13

Re: Autonomous Help
 
Quote:

Originally Posted by notmattlythgoe (Post 1432767)
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?

No the box does not even appear so that's why I am wondering if i need to create one or something.

Fauge7 23-01-2015 13:13

Re: Autonomous Help
 
This is why you should use command based robot, with a turn x degrees command, drive subsyem with your encoders

notmattlythgoe 23-01-2015 13:15

Re: Autonomous Help
 
Quote:

Originally Posted by curtis0gj (Post 1432772)
No the box does not even appear so that's why I am wondering if i need to create one or something.

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?

curtis0gj 23-01-2015 13:16

Re: Autonomous Help
 
Quote:

Originally Posted by Ether (Post 1432765)
It just sounded like you were using either an oscilloscope or on-board voltage sampling. (You said it was "showing" a square wave).

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.





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.

curtis0gj 23-01-2015 13:22

Re: Autonomous Help
 
Quote:

Originally Posted by notmattlythgoe (Post 1432775)
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?

None in the ds error box but I don't know how to check the roborio error log.


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