Okay so I am a NEW programmer for the LF Robotics team - our old programer went off to college and left me to program this year. I tried for hours to program in a motor to, by the push of button four on the right joystick, start spinning for 5 seconds then by the push of button five on the right joystick it would shut off. I thought this would be simple but I guess I was mistaken. I am programming in java in command base. What do I need to do to complete this task? Also what does double mean - I have been seeing it everywhere in the code. I tried to make up some code by comparing our code from last year and instructions off of wpilib but both programs were completely different and neither worked. Could you also explain to me how to create an autonomous program.
For programming in the Command Based Template, I suggest you watch the videos by Brad Miller on the topic: http://www.youtube.com/playlist?list=PLYA9eZLlgz7vGUVGkGSvFuyQQ1ErKgeDl
A double is a “double precision floating point” variable. Basically a float, decimal points, but larger to have more decimals of precision.
Here is an outline of what you need to do to accomplish the goals you have laid out in your post:
- Create a subsystem to control access to the motor. This class will contain a member variable that is the speedcontroller for the motor, see Jaguar, Victor, or Talon.
- Within this subsystem you will create a Java function that will set the motor to a particular speed. Pass the speed as a parameter to the function.
- Create a Command that will turn the motor on. Inside the initialize or the execute this will call the function from step 2. In the end and interrupt functions you will want to set the motor speed to zero again by calling the function from step 2.
4 in the operator interface OI.java you will need to create the Joystick object and the button objects. Use the button’s whenPressed function to assign the command from step 3 to the button.
- At this point I’m a little confused about your requirements: you say you want the motor to run for 5 secs, but you also say you want to stop the motor with another button press. Which is it? If you want the Command to timeout after 5 secs use the set Timeout function of the command to set the timeout and check the isTimeout function in the isFinished function of the command.
- If you want to stop the motor with a second button, create the button in OI and have it call a Command that sets the motor speed to zero.
Hope that gets you going…
Hereis a presentation with some example code that our team presented at the VA FRC Workshop this past fall on Command Based Java for FRC. If you have any questions please feel free to email me, my address is at the end of the presentation.
It looks like you are programming your robot in a coding style called command based programming. I’ve been coding our robot this way for a few years and I’m pretty familiar with it. Here’s a FIRST link that goes into greater detail about it: http://wpilib.screenstepslive.com/s/3120/m/7952/l/105519-what-is-command-based-programming But essentially it is a style of programming that organizes your code into “subsytems”, classes that define the different parts and functions of the robot (i.e. a drive train or a claw), and “commands” that define actions of your robot which use capabilities of your robot (i.e. Joystick drive, using drive train).
They way your code should be structured is to create your motors in a subsystem and try to run them in a command. In your subsystem you would need to construct a motor (a jaguar, vector, CANJaguar, etc.) and would look something like this:
public CANJaguar leftFront = new CANJaguar(4);
This piece of code would create a CANJaguar controlled motor called leftFront connected to port 4. Talk to your electrical team to figure out what type of motor controllers you use.
In a command you could run this motor. Here is a piece of code that would run a motor:
This sets the speed of your motor to .95. This code would probably go in the execute section of your command. To run code for a certain period of time we use the Timer class. This a piece of code I wrote this year:
Basically has the motor run until the timer reaches 2 seconds.
All of your joystick and buttons should go in your OI. However, if your task it to run a motor for r5 seconds, two buttons really aren’t necessary. If you have a command that runs a motor for 5 seconds, you can just assign that command to a button and use the whenPressed button method. It will automatically turn off the motor after 5 seconds anyway.
The doble you keep seeing is a primitive number type. Its really just a number that has a decimal, so like 4.5, 6.333, 0.9, etc.
Instead of giving you a fish…
Try typing the words Java double into Bing or Google.