I have a putnumber in my codeI(which can be found here in driveTrain2020 not src/main) for the smart dashboard which should update constantly but is not. I have tried a print line with one of the values and it does seem that the value is updating constantly but it is simply not updating on the smart dashboard.
Thanks for providing a link to your code. Which specific file is the putNumber() call in?
under the subsystems folder in ColorWheel.java
Does smartdashboard show that it’s connected to the robot?
It does not specifically show that it is connected to the robot but the values do pop up when the robot code is deployed. The problem is though I can see the values they are not updating even though it is connected to the robot.
Likely related to this:
Scheduler isn’t running properly due to mixing old and new command-based frameworks.
I changed all the old command framework stuff to the new command framework stuff.
Can you create a minimal reproduction project and share with the group?
If you can’t reproduce this with a new project, then it’s definitely something in your code
unfortunately I cannot test code right now because I am away from a roborio until tomorrow or potentially Tuesday. I was hoping to get this posted before I left but I hit the post limit of a new account. I can create a minimal reproduction still.
One thing I am noticing here, is you are using the old Command Based Framework, but your ColorWheel subsystem is using the new Command Based Framework’s SubsystemBase (which is where the Periodic method comes from).
I’d have to really look into the background WPILIB code, but its possible that there is some disconnect between the two meaning the “periodic” method isn’t actually being called “periodicly”.
You might be looking in the wrong folder because in the driveTrain2020 folder from the main page not in src/main should show that I have updated all my code to the new command framework. I know the code runs periodically because the print line I used to test if it runs periodically was constantly getting an updated number.
here is a minimal build of the color sensor subsystem.
Does that reproduce your issue? I don’t see any SmartDashboard calls anywhere
I forgot to add some code it should be in the github now
You’re only updating the detectedColor
variable with sensor data once when the ColorWheel subsystem is constructed in RobotContainer. Try updating the variable periodically like you did with IR
That will cause some issues because in the actual color sensor code (found here) has a match color variable that relies on the detectedColor that needs to be called outside of the periodic which can’t be done because things in the periodic cannot be made public.
Did you confirm that your minimal example reproduces your issue? I trust that the values won’t update, given @maccopacco’s comment, so I’m going to say it doesn’t truly reproduce your issue.
Since we’re attempting to debug via code review, it’s critically important that we look at the correct code.
Why do you believe that? Linking the source would be a big help explaining what the intent behind it is.
I believe you may have an issue with the understanding of when things happen and scope.
Any line outside a method will be called when the object is constructed. In your case, this is only happening once (it should). Anything you want to frequently update will need to go in the periodic method.
Scope is where a variable is accessible from. public
means that variable is accessible outside of the ColorWheel
class. private
means the variable is only accessible within the class.
Where we declare variables defines the scope. If you declare a variable within periodic, it will not be accessible outside of that method no matter what, hence why it doesn’t allow you to put public
in front of it.
If you want to use information gathered within periodic()
outside of periodic()
, store the information into a variable outside of periodic, hence with a higher scope and more accessibility.
It may look like this:
public class ColorWheel extends SubsystemBase {
private final ColorSensorV3 colorSensor = new ColorSensorV3(i2cPort);
private final ColorMatch colorMatcher = new ColorMatch(); //declare and instantiate
public Color detectedColor; //declaring variable
public ColorMatchResult match; //declaring variable
public void periodic(){
detectedColor = colorSensor.getColor();
match = colorMatcher.matchClosestColor(detectedColor);
}
}
If you don’t need to use those variables outside of periodic, then you should declare them in periodic. You just won’t use public because you don’t get to control the scope within a method (you still kind of can, but that’s not something to get into).
I made another post a while back helping somebody with scope if that may give some insight.
the match color variable needs to be called outside of periodic because it sets up when the thing that will manipulate the wheel will activate in a method in the subsystem public void CPMotorControl(final double encoderValues, final double distance, final double circ){ while(Robot.colorCase != match.color){ SpinColorWheel spinColorWheel = new SpinColorWheel(22,rS775Encoder,controlPanelSpinner); }
. I feel like your explanation could solve the issue but I won’t be able to test the code for a day or two because I won’t be in a place with a roborio or the color sensor tomorrow.
sorry for the long time to respond but today is the first day that I am able to test the code and it looks like your solution works.