Go to Post Now, everyone, say it with me: "It's just a TV show and FRC is just a robotics program. My life is a lot bigger than both of those things." Once you say this, I swear most of the arguments here would fade into oblivion. - itsjustjon [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
  #1   Spotlight this post!  
Unread 24-01-2016, 10:26
ahartnet's Avatar
ahartnet ahartnet is online now
Registered User
AKA: Andrew Hartnett
FRC #5414 (Pearadox)
Team Role: Mentor
 
Join Date: Jan 2011
Rookie Year: 2005
Location: Houston, Texas
Posts: 201
ahartnet has a reputation beyond reputeahartnet has a reputation beyond reputeahartnet has a reputation beyond reputeahartnet has a reputation beyond reputeahartnet has a reputation beyond reputeahartnet has a reputation beyond reputeahartnet has a reputation beyond reputeahartnet has a reputation beyond reputeahartnet has a reputation beyond reputeahartnet has a reputation beyond reputeahartnet has a reputation beyond repute
Robot preferences help

Hi

We're trying to get the robot preferences to work. We followed the example on the screen steps page (http://wpilib.screenstepslive.com/s/...martdashboard), but are confused with a number of things. We're doing command based programming in Java.

1) should this go in the robot init like in the example? Doesn't that mean you need to reboot the Rio every time you change the file?
2) we can't seem to get anything to show up in the preferences. The things that I have found in the forums are a couple of years old so I'm not sure if it's changed.
3) if we create a key in the preferences table that doesn't exist in the code does that have any impact?
4) we trying declaring the variables as public in our robot.java but while in other commands or subsystems it doesn't seem like we could use them. Is there something I'm missing there?

Thanks for any help!
Andrew
__________________
Team 451 The Cat Attack, Student Alumni (2005)
Team 1646 Precision Guessworks, Mentor (2006-2008)
Team 2936 Gatorzillas, Mentor (2011-2014)
Team 5414 Pearadox, Mentor (2015-Present)
Reply With Quote
  #2   Spotlight this post!  
Unread 24-01-2016, 13:03
Joe Ross's Avatar Unsung FIRST Hero
Joe Ross Joe Ross is offline
Registered User
FRC #0330 (Beachbots)
Team Role: Engineer
 
Join Date: Jun 2001
Rookie Year: 1997
Location: Los Angeles, CA
Posts: 8,572
Joe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond repute
Re: Robot preferences help

Quote:
Originally Posted by ahartnet View Post
1) should this go in the robot init like in the example? Doesn't that mean you need to reboot the Rio every time you change the file?
We typically read preferences either in disabled init or inline with where the data is used (based on how often we want to be able to updated it).

Quote:
Originally Posted by ahartnet View Post
2) we can't seem to get anything to show up in the preferences. The things that I have found in the forums are a couple of years old so I'm not sure if it's changed.
The code on screensteps doesn't put any data to the preferences, just reads existing data. You can either add the data using SmartDashboard, or put it in your code. Generally, if our robot code reads a value and it doesn't exist the code immediately puts a default value to preferences.

Quote:
Originally Posted by ahartnet View Post
3) if we create a key in the preferences table that doesn't exist in the code does that have any impact?
No.

Quote:
Originally Posted by ahartnet View Post
4) we trying declaring the variables as public in our robot.java but while in other commands or subsystems it doesn't seem like we could use them. Is there something I'm missing there?
You need to references them as Robot.value. Or you could just read the preferences in your command or subsystem.
Reply With Quote
  #3   Spotlight this post!  
Unread 24-01-2016, 15:49
ahartnet's Avatar
ahartnet ahartnet is online now
Registered User
AKA: Andrew Hartnett
FRC #5414 (Pearadox)
Team Role: Mentor
 
Join Date: Jan 2011
Rookie Year: 2005
Location: Houston, Texas
Posts: 201
ahartnet has a reputation beyond reputeahartnet has a reputation beyond reputeahartnet has a reputation beyond reputeahartnet has a reputation beyond reputeahartnet has a reputation beyond reputeahartnet has a reputation beyond reputeahartnet has a reputation beyond reputeahartnet has a reputation beyond reputeahartnet has a reputation beyond reputeahartnet has a reputation beyond reputeahartnet has a reputation beyond repute
Re: Robot preferences help

Thanks for the suggestions! I like putting it into the disabledInit() function.

Still having some problems though.

Code:
public class Robot extends IterativeRobot {
	public static double speed;
	Preferences prefs;
        //Other stuff
}
    public void disabledInit(){

    	speed = prefs.getDouble("speed", .5);
    	
    }
And then later on in a different class
Code:
     value = Robot.speed;
However we're having issues where we're getting an unhandled exception for a null pointer in the disabledInit function, so the driver station is listing as "no robot code"

Any suggestions?
__________________
Team 451 The Cat Attack, Student Alumni (2005)
Team 1646 Precision Guessworks, Mentor (2006-2008)
Team 2936 Gatorzillas, Mentor (2011-2014)
Team 5414 Pearadox, Mentor (2015-Present)
Reply With Quote
  #4   Spotlight this post!  
Unread 24-01-2016, 16:01
fovea1959's Avatar
fovea1959 fovea1959 is offline
Herder of programmers
AKA: Doug Wegscheid
FRC #3620 (The Average Joes)
Team Role: Mentor
 
Join Date: Jan 2011
Rookie Year: 2011
Location: St Joseph
Posts: 332
fovea1959 will become famous soon enough
Re: Robot preferences help

in addition to declaring

Code:
Preferences prefs;
are you initializing the 'prefs' variable before using it?

Code:
prefs = Preferences.getInstance();
Usually a NPE (NullPointerException) is caused by using a variable before initializing it.
Reply With Quote
  #5   Spotlight this post!  
Unread 24-01-2016, 17:14
ahartnet's Avatar
ahartnet ahartnet is online now
Registered User
AKA: Andrew Hartnett
FRC #5414 (Pearadox)
Team Role: Mentor
 
Join Date: Jan 2011
Rookie Year: 2005
Location: Houston, Texas
Posts: 201
ahartnet has a reputation beyond reputeahartnet has a reputation beyond reputeahartnet has a reputation beyond reputeahartnet has a reputation beyond reputeahartnet has a reputation beyond reputeahartnet has a reputation beyond reputeahartnet has a reputation beyond reputeahartnet has a reputation beyond reputeahartnet has a reputation beyond reputeahartnet has a reputation beyond reputeahartnet has a reputation beyond repute
Re: Robot preferences help

d'oh! That was at least part of the problem.

Still having some issues that might be related to the scope or static-ness of the variable. For some reason in order to acces it in a different class, the code wants us to make it static.

Code:
public static double speed;

public void disabledInit(){
        prefs = Preferences.getInstance();
    	speed = prefs.getDouble("speed", 0.0);    
	SmartDashboard.putNumber("Pref speed", speed);
    }
Code:
     
	SmartDashboard.putNumber("Pref speed in different class", Robot.speed);
In smart dashboard we'll get
"Pref speed": # (this updates appropriately when we disable)
"Pref speed in different class": 0.0 (this stays at whatever we initially set it to no matter what this doesnt surprise me because it's declared as static).

Thanks for all the help so far.
__________________
Team 451 The Cat Attack, Student Alumni (2005)
Team 1646 Precision Guessworks, Mentor (2006-2008)
Team 2936 Gatorzillas, Mentor (2011-2014)
Team 5414 Pearadox, Mentor (2015-Present)
Reply With Quote
  #6   Spotlight this post!  
Unread 24-01-2016, 17:42
ahartnet's Avatar
ahartnet ahartnet is online now
Registered User
AKA: Andrew Hartnett
FRC #5414 (Pearadox)
Team Role: Mentor
 
Join Date: Jan 2011
Rookie Year: 2005
Location: Houston, Texas
Posts: 201
ahartnet has a reputation beyond reputeahartnet has a reputation beyond reputeahartnet has a reputation beyond reputeahartnet has a reputation beyond reputeahartnet has a reputation beyond reputeahartnet has a reputation beyond reputeahartnet has a reputation beyond reputeahartnet has a reputation beyond reputeahartnet has a reputation beyond reputeahartnet has a reputation beyond reputeahartnet has a reputation beyond repute
Re: Robot preferences help

Alright, I think we have it figured out enough for how we'll use it. I think the issue is that we were trying to send the value into a function in a command group for autonomous. When we try to just read it in our teleop mode, we don't have the same problem. It's weird, but I think we can work around it.

If anyone else has a similar issue, for our command based programming we did still have to declare are variable in Robot class as:
public static double speed;

My suspicion is that it has to do with being used in a command group. When a new command group was made for our sendableChooser, it must poll what that variable is at that point in time. Then when that command group is called later, it must not look at if the variable has changed.

Thanks!
__________________
Team 451 The Cat Attack, Student Alumni (2005)
Team 1646 Precision Guessworks, Mentor (2006-2008)
Team 2936 Gatorzillas, Mentor (2011-2014)
Team 5414 Pearadox, Mentor (2015-Present)
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 11:53.

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