Go to Post Most of us are pretty friendly. - StephLee [more]
Home
Go Back   Chief Delphi > Technical > Programming > Java
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Reply
Thread Tools Rate Thread Display Modes
  #61   Spotlight this post!  
Unread 23-01-2015, 12:38
notmattlythgoe's Avatar
notmattlythgoe notmattlythgoe is online now
Flywheel Police
AKA: Matthew Lythgoe
FRC #2363 (Triple Helix)
Team Role: Mentor
 
Join Date: Feb 2010
Rookie Year: 2009
Location: Newport News, VA
Posts: 1,722
notmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond repute
Re: Autonomous Help

Quote:
Originally Posted by curtis0gj View Post
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);
Reply With Quote
  #62   Spotlight this post!  
Unread 23-01-2015, 12:46
curtis0gj curtis0gj is offline
Registered User
FRC #5033 (Beavertronics)
Team Role: Programmer
 
Join Date: Jan 2015
Rookie Year: 2015
Location: Canada
Posts: 121
curtis0gj will become famous soon enough
Re: Autonomous Help

Quote:
Originally Posted by notmattlythgoe View Post
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);	
				}
				
    			}
Reply With Quote
  #63   Spotlight this post!  
Unread 23-01-2015, 12:47
notmattlythgoe's Avatar
notmattlythgoe notmattlythgoe is online now
Flywheel Police
AKA: Matthew Lythgoe
FRC #2363 (Triple Helix)
Team Role: Mentor
 
Join Date: Feb 2010
Rookie Year: 2009
Location: Newport News, VA
Posts: 1,722
notmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond repute
Re: Autonomous Help

Quote:
Originally Posted by curtis0gj View Post
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...
Reply With Quote
  #64   Spotlight this post!  
Unread 23-01-2015, 12:51
curtis0gj curtis0gj is offline
Registered User
FRC #5033 (Beavertronics)
Team Role: Programmer
 
Join Date: Jan 2015
Rookie Year: 2015
Location: Canada
Posts: 121
curtis0gj will become famous soon enough
Re: Autonomous Help

Quote:
Originally Posted by notmattlythgoe View Post
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.
Reply With Quote
  #65   Spotlight this post!  
Unread 23-01-2015, 12:52
Ether's Avatar
Ether Ether is offline
systems engineer (retired)
no team
 
Join Date: Nov 2009
Rookie Year: 1969
Location: US
Posts: 8,089
Ether has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond repute
Re: Autonomous Help

Quote:
Originally Posted by curtis0gj View Post
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


Reply With Quote
  #66   Spotlight this post!  
Unread 23-01-2015, 12:57
notmattlythgoe's Avatar
notmattlythgoe notmattlythgoe is online now
Flywheel Police
AKA: Matthew Lythgoe
FRC #2363 (Triple Helix)
Team Role: Mentor
 
Join Date: Feb 2010
Rookie Year: 2009
Location: Newport News, VA
Posts: 1,722
notmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond repute
Re: Autonomous Help

Quote:
Originally Posted by curtis0gj View Post
Hmm I've no idea what NullPointerExceptions but I don't think want any they sound pretty bad.
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.
Reply With Quote
  #67   Spotlight this post!  
Unread 23-01-2015, 13:03
curtis0gj curtis0gj is offline
Registered User
FRC #5033 (Beavertronics)
Team Role: Programmer
 
Join Date: Jan 2015
Rookie Year: 2015
Location: Canada
Posts: 121
curtis0gj will become famous soon enough
Re: Autonomous Help

Quote:
Originally Posted by notmattlythgoe View Post
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.
Reply With Quote
  #68   Spotlight this post!  
Unread 23-01-2015, 13:04
curtis0gj curtis0gj is offline
Registered User
FRC #5033 (Beavertronics)
Team Role: Programmer
 
Join Date: Jan 2015
Rookie Year: 2015
Location: Canada
Posts: 121
curtis0gj will become famous soon enough
Re: Autonomous Help

Quote:
Originally Posted by Ether View Post
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.
Reply With Quote
  #69   Spotlight this post!  
Unread 23-01-2015, 13:09
Ether's Avatar
Ether Ether is offline
systems engineer (retired)
no team
 
Join Date: Nov 2009
Rookie Year: 1969
Location: US
Posts: 8,089
Ether has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond repute
Re: Autonomous Help

Quote:
Originally Posted by curtis0gj View Post
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.



Reply With Quote
  #70   Spotlight this post!  
Unread 23-01-2015, 13:10
notmattlythgoe's Avatar
notmattlythgoe notmattlythgoe is online now
Flywheel Police
AKA: Matthew Lythgoe
FRC #2363 (Triple Helix)
Team Role: Mentor
 
Join Date: Feb 2010
Rookie Year: 2009
Location: Newport News, VA
Posts: 1,722
notmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond repute
Re: Autonomous Help

Quote:
Originally Posted by curtis0gj View Post
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?
Reply With Quote
  #71   Spotlight this post!  
Unread 23-01-2015, 13:13
curtis0gj curtis0gj is offline
Registered User
FRC #5033 (Beavertronics)
Team Role: Programmer
 
Join Date: Jan 2015
Rookie Year: 2015
Location: Canada
Posts: 121
curtis0gj will become famous soon enough
Re: Autonomous Help

Quote:
Originally Posted by notmattlythgoe View Post
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.
Reply With Quote
  #72   Spotlight this post!  
Unread 23-01-2015, 13:13
Fauge7 Fauge7 is offline
Head programmer
FRC #3019 (firebird robotics)
Team Role: Programmer
 
Join Date: Jan 2013
Rookie Year: 2012
Location: Scottsdale
Posts: 195
Fauge7 is a name known to allFauge7 is a name known to allFauge7 is a name known to allFauge7 is a name known to allFauge7 is a name known to allFauge7 is a name known to all
Re: Autonomous Help

This is why you should use command based robot, with a turn x degrees command, drive subsyem with your encoders
Reply With Quote
  #73   Spotlight this post!  
Unread 23-01-2015, 13:15
notmattlythgoe's Avatar
notmattlythgoe notmattlythgoe is online now
Flywheel Police
AKA: Matthew Lythgoe
FRC #2363 (Triple Helix)
Team Role: Mentor
 
Join Date: Feb 2010
Rookie Year: 2009
Location: Newport News, VA
Posts: 1,722
notmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond repute
Re: Autonomous Help

Quote:
Originally Posted by curtis0gj View Post
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?
Reply With Quote
  #74   Spotlight this post!  
Unread 23-01-2015, 13:16
curtis0gj curtis0gj is offline
Registered User
FRC #5033 (Beavertronics)
Team Role: Programmer
 
Join Date: Jan 2015
Rookie Year: 2015
Location: Canada
Posts: 121
curtis0gj will become famous soon enough
Re: Autonomous Help

Quote:
Originally Posted by Ether View Post
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.
Reply With Quote
  #75   Spotlight this post!  
Unread 23-01-2015, 13:22
curtis0gj curtis0gj is offline
Registered User
FRC #5033 (Beavertronics)
Team Role: Programmer
 
Join Date: Jan 2015
Rookie Year: 2015
Location: Canada
Posts: 121
curtis0gj will become famous soon enough
Re: Autonomous Help

Quote:
Originally Posted by notmattlythgoe View Post
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.
Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -5. The time now is 12:06.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


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