Java code to run robot

Hi everyone! I could use some assistance. This is our second year as an FRC team, but I am just learning Java code for myself to assist my kiddos. Here is my issue. When I follow Wpilib to create a new project, then click example to start the code, I feel like I am missing some code to get my robot to drive. Do I need a different wpilib code to drive my chassis? Do I need to program the motor controllers and I am missing that? I am a novice and just assumed that the example code would deploy and run the robot, but I know that I am missing something. Could somebody walk me through this step by step, pretty please? We have already checked all the wiring and reimaged the radio to our team and so on. We are coding with Java and using the FRC dashboard. Thank you everyone!!

The WPILib docs do a good job of explaining basic robot operation with WPILib code. You can find the “zero-to-robot” guide here: Introduction — FIRST Robotics Competition documentation

2 Likes

It all depends on what you’re using. If you’re using SPARK MAX then you need the rev lib. If you’re using PWM motor controllers then that’s already available in the WPIlib. You can always check out other team’s code for reference. Here is my team’s github: FRC-Team-333 · GitHub
we use tank drive chassis so I hope this is useful.

Also, if you want to create your own robot code, You should click “Template” not “Example”

1 Like

Yeah, the example project will do nothing when you push it to the robot. It is simply a framework that will allow you to build code from there. It provides you with the loops that execute at fixed intervals so you can put whatever logic you want in those loops. There are many great tutorials on youtube on how to start programming in Java in FRC. My recommendation is to start by trying to make a single motor spin. Then from there try to control it with a single axis from a joystick. Move on to reprogramming a simple robot. Good luck :slight_smile:

3 Likes

Building on this, it depends which example project you used. Some are for driving, some for running other mechanisms. They all assume your motor controllers are accessible on certain ports (either wired to a specific PWM port on the Rio, or have a specific CAN ID). You would need to look at the code and either change these numbers to match your robot, or change the wiring to match the code)

1 Like

It sounds like you are first trying to catch up with what has already been done in Java last season. If the robot program you used before needs better annotation for you to follow, then you could post a link to it here and I’d help decipher it.

If that isn’t right and you used LabView, then the same decisions from many options still have to be made in Java as they were in LV.

I and I’m sure many others will help you and if you can provide an exact description of your robot, then we can help you select the syntax. What motors, motor controllers, chassis/wheel configuration, joysticks, sensors, etc. are you using?

Following the advice of all the other posts is a great start then practice on your own robot. This season my team is presenting beginning Java with driving a Romi within a few hours of starting the Java lessons. If you have a robot or at least a roboRIO and a motor to play with that’s great. Add some sensors and you’ll learn a lot.

1 Like

You may have to update the firmware on the motor controllers if they are new, or old and out of date.

2 Likes

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.