I’ve been wanting to get motion profiling ready for this upcoming season. However, whenever I try to pull encoder positions, velocity, set positions to zero, etc… I end up with null pointers. Can anyone see what I’m missing? Full code is linked here. The null pointer first shows when zeroing the encoders on line 48 found here. Any help is appreciated. Thanks.
Could you post the stack trace? That would make it a lot easier for us to help
I currently do not have access to the bot. The next time I will is probably January 2nd.
You don’t even instantiate RobotMap. So you need RobotMap robotMap = new RobotMap(); somewhere
I think I see the problem.
Line 19 of Robot.java is creating a static field of type Sensors, which tells the JVM to load that class. This is happening as soon as code starts, and before robotInit (and therefore before you call RobotMap.init()). When the Sensors class loads, it initializes the fields for the talons to the values from RobotMap, which are null since they haven’t been initialized yet.
The solution is to put lines 27 and 28 in the constructor for Sensors.java, and you should probably go ahead and put lines 29 and 30 in there too.
He’s using RobotMap as a purely static class, so there’s no need to instantiate it.
Thanks. I will try this asap.
Ah oops. I forgot that outer classes cannot be static in Java. Haha