Go to Post So, please, can't we all just live and let live? - Alexa Stott [more]
Home
Go Back   Chief Delphi > Technical > Programming > Java
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
 
 
Thread Tools Rate Thread Display Modes
Prev Previous Post   Next Post Next
  #5   Spotlight this post!  
Unread 09-02-2014, 15:50
LaurenMary's Avatar
LaurenMary LaurenMary is offline
Team 2399 Head Programmer
FRC #2399 (The Fighting Unicorns)
Team Role: Programmer
 
Join Date: Dec 2012
Rookie Year: 2010
Location: cleveland
Posts: 5
LaurenMary is an unknown quantity at this point
Re: NEW PROGRAMMER - MOTOR PROGRAMMING

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/...ed-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:

leftFront.setX(.95);

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:

if(timer.get()<=2000){
kicker.setSpeed(.95);
}
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.
__________________
DFTBA
Reply With Quote
 


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -5. The time now is 11:08.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi