I’m part of a newbie team this year and after some research and long hours of watching videos I have a basic idea of the concepts of java programming, but I’m not quite sure how to actually write code that will be able to drive the robot.
My first task is to find out how to write the code using tank drive with 4 CIM motors. Our team is planning on using the two included joysticks for left and right motor control.
It seems like setting up the tank drive system is relatively easy (to experienced programmers) but I don’t even know where to start. Can any of you offer any guidance as to how write the code for a tank drive system?
I have downloaded Netbeans and the FRC plugins so I think I am ready to start writing code. Any help would be greatly appreciated, thanks!
I would suggest loading one of the FRC sample projects this will show you plus give you a good point to start changing code. This is done by going to File -> New Project -> Samples -> FRC Java -> then choose a project.
RobotDrive drive = new RobotDrive(1,2,3,4);
Joystick leftStick = new Joystick(1);
Joystick rightStick = new Joystick(2);
public void operatorControl()
{
while(isOperatorControl() && isEnabled())
{
drive.tankDrive(leftStick, rightStick);
}
}
}
I basically just copied the quick start guide…
Some questions:
is this code even going to do anything?
when you create the joystick objects and put (1) and (2) for ports, how does the computer know that joysticks are connected? Same for the motors, is just putting 1,2,3,4 for the 4 motors going to work? (I guess I just don’t fully understand what ports we are connecting the motors and the joysticks to)
I think our team is planning on using the command based template when we code for the full robot, how do I implement this type of thing using the subsystem, command base, OI, and all of the different java files that go along with it? (It seems like the different parts need to be split up in order to work properly)
is this code even going to do anything? I am going to say yes. seem like no errors.
when you create the joystick objects and put (1) and (2) for ports, how does the computer know that joysticks are connected? You can see the Joystick and what port they are connected to by looking at the driverstation.
Same for the motors, is just putting 1,2,3,4 for the 4 motors going to work?Yes, this will work. These will be the PWM of the digtal side card. I would suggest doing this tho Jaguar LeftFront = new Jaguar(1); …
I think our team is planning on using the command based template when we code for the full robot, how do I implement this type of thing using the subsystem, command base, OI, and all of the different java files that go along with it? I would watch the videos i linked.
Thanks! So to deploy this to the robot I would connect the computer to the cRIO and then hit the “run” button? Will operator control be enabled automatically?
Ok so now that I think that the code I wrote will work, I want to put it in the command based template. I watched the videos that Brad Miller posted and I know how the template works but am not sure how to set it up to make the tank drive work.
I think we actually might be traveling to purdue for our regional competition. The queen city regional is on easter weekend and we are a christian school so that wouldn’t go so well.
And I did look at the gearsbot code and I wasn’t sure if we need to set it up the same way because we aren’t coding it to go a certain distance. Would I still set up the drivetrain as a PID subsystem?
I think I all I need to do is add a subsystem, command, and modify both the OI and the RobotMap and I should be good. I’ll try it out later and see what I come up with.
Well, if you have 4 motors, that should be correct. But if you only have 2 motors (one on the left and one on the right), it’ll be RobotDrive(1,2); – where 1 is the left motor and 2 is the right motor.