Go to Post I wonder if the GDC had his extraordinary achievements in mind for the 2012 game. - MagiChau [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

 
Reply
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 22-01-2014, 21:12
LFRobotics's Avatar
LFRobotics LFRobotics is offline
Registered User
FRC #4623
 
Join Date: Jan 2014
Location: Little Falls, MN
Posts: 95
LFRobotics is on a distinguished road
NEW PROGRAMMER - MOTOR PROGRAMMING

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.

PLEASE help!
THANKS!
Reply With Quote
  #2   Spotlight this post!  
Unread 22-01-2014, 22:16
gixxy's Avatar
gixxy gixxy is offline
Programming and Arduino Mentor
AKA: Gustave Michel III
FRC #3946 (Tiger Robotics)
Team Role: Mentor
 
Join Date: Nov 2011
Rookie Year: 2012
Location: Ruston, LA
Posts: 207
gixxy is on a distinguished road
Re: NEW PROGRAMMER - MOTOR PROGRAMMING

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...vFuyQQ1ErKgeDl



A double is a "double precision floating point" variable. Basically a float, decimal points, but larger to have more decimals of precision.


Good Luck!
__________________
Programmer - A creature known for converting Caffeine into Code.
Studying Computer Science @ Louisiana Tech University
Associate Consultant @ Fenway Group

2012-13: 3946 - Head of Programming, Electrical and Web
2014 - 3468 - Programming Mentor
2015 - Present - Lurker
Reply With Quote
  #3   Spotlight this post!  
Unread 22-01-2014, 23:31
shindigo shindigo is offline
Registered User
AKA: Mike Parker
FRC #0102
Team Role: Mentor
 
Join Date: Feb 2012
Rookie Year: 2009
Location: Somerville, NJ
Posts: 33
shindigo is an unknown quantity at this point
Re: NEW PROGRAMMER - MOTOR PROGRAMMING

Here is an outline of what you need to do to accomplish the goals you have laid out in your post:
1. 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.
2. 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.
3. 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.
5. 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.
6. 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...
Reply With Quote
  #4   Spotlight this post!  
Unread 23-01-2014, 07:38
notmattlythgoe's Avatar
notmattlythgoe notmattlythgoe is offline
Flywheel Police
AKA: Matthew Lythgoe
FRC #2363 (Triple Helix)
Team Role: Mentor
 
Join Date: Feb 2010
Rookie Year: 2009
Location: Newport News, VA
Posts: 1,728
notmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond repute
Re: NEW PROGRAMMER - MOTOR PROGRAMMING

Here is 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.
Reply With Quote
  #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
  #6   Spotlight this post!  
Unread 09-02-2014, 16:14
Ether's Avatar
Ether Ether is offline
systems engineer (retired)
no team
 
Join Date: Nov 2009
Rookie Year: 1969
Location: US
Posts: 8,102
Ether has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond repute
Re: NEW PROGRAMMER - MOTOR PROGRAMMING

Quote:
Originally Posted by LFRobotics View Post
what does double mean - I have been seeing it everywhere in the code.
Instead of giving you a fish...

Try typing the words Java double into Bing or Google.


Reply With Quote
Reply


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 12:42.

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