Go to Post I just want to see Aerial Assist again. Played on Lunacy regolith. With minibot poles. Which are on coopertition bridges. Is that too much to ask for? ;) - M. Lillis [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 19-09-2013, 08:01
Matt_4505 Matt_4505 is offline
Registered User
FRC #4505
Team Role: Programmer
 
Join Date: Nov 2012
Rookie Year: 2012
Location: United States
Posts: 16
Matt_4505 is on a distinguished road
First Year Java Autonomous Help

Hello,
This year, I am switching my team from Labview to Java. One issue I've had with the transition is how to program Autonomous methods in Java. I have tried to write a method that will move the robot backwards for a set amount of time, at a set speed. When I try to run it, the drive motors kick the bot back for a second and then stop instead of continuing to roll back. Any help would be appreciated.
Code:

public void moveBackward(double time, double motorPower){
Hardware.chassis.tankDrive(-motorPower, -motorPower);
Timer.delay(time);
Hardware.chassis.tankDrive(0, 0);
}
Reply With Quote
  #2   Spotlight this post!  
Unread 19-09-2013, 10:05
cgmv123's Avatar
cgmv123 cgmv123 is online now
FRC RI/FLL Field Manager
AKA: Max Vrany
FRC #1306 (BadgerBOTS)
Team Role: College Student
 
Join Date: Jan 2011
Rookie Year: 2011
Location: Madison, WI
Posts: 2,078
cgmv123 has a reputation beyond reputecgmv123 has a reputation beyond reputecgmv123 has a reputation beyond reputecgmv123 has a reputation beyond reputecgmv123 has a reputation beyond reputecgmv123 has a reputation beyond reputecgmv123 has a reputation beyond reputecgmv123 has a reputation beyond reputecgmv123 has a reputation beyond reputecgmv123 has a reputation beyond reputecgmv123 has a reputation beyond repute
Your input is good, but try this for the method:

double last = Timer.getFPGATimestamp
while *get timestamp*-last<time
*Set motor power*
*Reset motor power*

Try disabling motorSafety as well.
__________________
BadgerBOTS Robotics|@team1306|Facebook: BadgerBOTS
2016 FIRST Championship Tesla Division | 2016 Wisconsin Regional Engineering Inspiration Award

2015 FIRST Championship Carson Division | 2015 Wisconsin Regional Chairman's Award

2013 FIRST Championship Curie Division | 2013 Wisconsin Regional Chairman's Award

2012 FIRST Championship Archimedes Division | 2012 Wisconsin Regional Engineering Inspiration Award, Woodie Flowers Finalist Award (Lead Mentor Ben Senson)

Reply With Quote
  #3   Spotlight this post!  
Unread 19-09-2013, 10:28
Matt_4505 Matt_4505 is offline
Registered User
FRC #4505
Team Role: Programmer
 
Join Date: Nov 2012
Rookie Year: 2012
Location: United States
Posts: 16
Matt_4505 is on a distinguished road
Re: First Year Java Autonomous Help

Thanks, what method would I use to get the timestamp?
*Never mind, I found it
Reply With Quote
  #4   Spotlight this post!  
Unread 19-09-2013, 11:14
Joe Ross's Avatar Unsung FIRST Hero
Joe Ross Joe Ross is offline
Registered User
FRC #0330 (Beachbots)
Team Role: Engineer
 
Join Date: Jun 2001
Rookie Year: 1997
Location: Los Angeles, CA
Posts: 8,567
Joe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond repute
Re: First Year Java Autonomous Help

When you set up a project in Java, you choose what base class to use, Simple Robot or Iterative Robot (or command, which is based on iterative). There are descriptions of each here: http://wpilib.screenstepslive.com/s/...g-a-base-class

In LabVIEW, autonomous is called at the start of autonomous and stopped at the end of autonomous. You can put delays in autonomous in LabVIEW. Teleop, on the other hand, is called every 20ms. You can't put any delays in teleop or you will shut down communication.

In Java (and C++), Simple Robot behaves like LabVIEW's autonomous, for both teleop and autonomous. Iterative Robot behaves like LabVIEW's teleop, for both teleop and autonomous.

If you are using iterative robot, you can't use the long delay or cgmv123's while loop. Instead use an if statement that checks the time and either turns on or off the motor and doesn't do anything that takes a long time.

If you are using the command templates, it's very easy to make a command that sets a timeout in init, runs the motor and checks the time in execute, and stops the motor in finish.



Another possible problem is the motor safety. By default, robotDrive needs to be called every 0.1 seconds or else it will shut off the motor. This is important because if your code crashes, it makes sure the robot stops, rather then keep running the last speed. In your code, robotDrive wouldn't get called for the length of your delay. cgmv123's code works around this by calling very often in the while loop.
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 22:33.

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