I am new to Java and don’t have much prior experience with coding. I have looked at some of the CTRE documentation, and some of WPILib documentation. I have a hard time putting it together though. I am asking if anyone has examples of moving a TalonSRX using an Xbox controller stick Y-Axis value. I am a little lost on getting the thing to move. It does use a can ID, if that makes a difference.
There’s a few different ways to structure your robot program. When writing a simple robot program, it’s generally easiest to start with what’s called the Timed robot. For more complex programs, the Command-Based framework is a better choice.
For Timed Robot, it would look something like this:
class MyRobot extends TimedRobot {
WPI_TalonSRX motor = new WPI_TalonSRX(/* can ID here */);
XboxController controller = new XboxController(1);
void teleopPeriodic() {
motor.set(controller.getLeftY());
}
}
The documentation tends to lead people towards command-based approaches, which have a bit steeper of a learning curve but are better as you transition from “just drive a motor with a joystick” to “write an autonomous program with a complex sequence of operations”.
I did forget to mention that the code I am writing is in a command based style. Thank you for the input though!
My opinion is that if you cannot make it work in the Robot.Java file, you are not ready to move on to command based programming. I would put some time into basic motor control in the simplest way possible before you mess around with command based stuff.
Using Peter_Johnson’s input, I believe I may have a solution that works. I wrote it into a subsystem for that part of the robot. I agree that command based is a very complicated subject. I will look into more basic concepts before I continue.
First of all, welcome to the hellish realm of robotics-centered software engineering (I’m kidding, it’s really fun)!
My father is a software mentor on my FRC team, and he wrote a pretty good tutorial introducing you to object-oriented programming (the model FRC teams use).
This tutorial starts from 0 and takes you from the basics of setting up your computer to compile and run Java, then continues to key concepts that you need to understand before you can get really good at programming. It also takes you through setting up the WPIlib release of VSCode on your computer, which is what we use to run code on robots.
This is the link to use, then just follow the tutorials
-PS: This doesn’t specifically cover your question but it should give you the foundation you need to learn more
Thank you, I will be sure to have a look later. This may be a helpful resource for our teams junior coders. I’ll recommend this to them as well.
On Sunday morning at 10am est, I’m doing a tutorial for another mentor on how to get a drive train running. We will be going over how to control rev sparks with an Xbox controller in the command-based format.
If you are a mentor, you are welcome to join. (If student, I just ask that you bring one of your mentors on too.)
Disclaimer: I am by no means a Java/programming expert. I’ve just had to learn recently to teach the students on my team.
In my experience learning and assisting teamates, I’ve found that as long as you have a working knowledge of how object-oriented programming works, and how FRCs compiler and workflow functions, you should be good. After that it’s just syntax and math.