Go to Post What a great organization! - HoltDan [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 02-02-2012, 22:02
NS_Radication's Avatar
NS_Radication NS_Radication is offline
Student
AKA: Marco Schoener
FRC #1369 (Minotaur)
Team Role: Programmer
 
Join Date: Jan 2012
Rookie Year: 2009
Location: Tampa
Posts: 88
NS_Radication is an unknown quantity at this point
Autonomous Motor Problems

This is my first year as a programmer for my FRC Team, but I have a Java background to work off of.

I am using Netbeans 7.1 with a default program with IterativeRobot and SimpleRobot subclasses. Both are default programs that I have used for testing verbatim and the results, after I have fixed electrical and network on the Classmate (2009) issues, is the Timer.delay() function.

Following examples are from the SimpleRobot program, the IterativeRobot program is the BuiltInDefaultCode code.

In Tele-Op, the motor will respond to the joystick and, by default, has a the delay set to 0.005 seconds:

driveTrain.tankDrive(leftStick, rightStick);
Timer.delay(0.005);

In Autonomous, it has a 2 second value with a movement at half speed.

for (int i; i < 4; i++)
{
driveTrain.drive(0.5, 0.0);
Timer.delay(2.0);
}

The issue is that instead of holding the motor value until the seconds expire, the Jaguar and motor will move for a split second and wait the entire 2 seconds until repeat.

If anyone has any solution, question, comment, advice, anti-Murphy's Law Orbital cannon, or other pieces of help, it would be GREATLY appreciated!

Thank you in advanced!
__________________
Team 1369
Senior
Head Programmer (Java)
Head Electrician
Reply With Quote
  #2   Spotlight this post!  
Unread 02-02-2012, 23:29
neal's Avatar
neal neal is offline
Neal
FRC #1777 (Viking Robotics)
Team Role: Mentor
 
Join Date: Jan 2012
Rookie Year: 2009
Location: United States
Posts: 56
neal is an unknown quantity at this point
Re: Autonomous Motor Problems

For the motor's safety, if it doesn't get called often, it'll automatically stop it. And Timer.delay() stops the whole thread.

I'm assuming you want to run the motor for 8 seconds, this is one way you could do:

Code:
public void autonomous() {
	Timer timer = new Timer();
	timer.start();
	while (isAutonomous() && isEnabled()) {
		if(timer.get() < 8) { // Double check this; don't exactly remember what it returns
			driveTrain.drive(0.5, 0.0);
		}
		Timer.delay(0.005);
	}
	timer.stop();
}
Reply With Quote
  #3   Spotlight this post!  
Unread 03-02-2012, 21:08
NS_Radication's Avatar
NS_Radication NS_Radication is offline
Student
AKA: Marco Schoener
FRC #1369 (Minotaur)
Team Role: Programmer
 
Join Date: Jan 2012
Rookie Year: 2009
Location: Tampa
Posts: 88
NS_Radication is an unknown quantity at this point
Re: Autonomous Motor Problems

This is what I pulled up for the Timer.get() API

get

public double get()

Get the current time from the timer. If the clock is running it is derived from the current system clock the start time stored in the timer class. If the clock is not running, then return the time when it was last stopped.

Returns:
Current time value for this timer in microseconds (uSeconds)

Will the new timer implemented within the method auto-start at 0 or will it have some other start area. And if it was started, would I subtract a [<desired time> + old time] - old time or what?

Any suggestions or comments would be very helpful and greatly appreciated.

Thank you again and continuously in advanced!
__________________
Team 1369
Senior
Head Programmer (Java)
Head Electrician
Reply With Quote
  #4   Spotlight this post!  
Unread 03-02-2012, 21:37
neal's Avatar
neal neal is offline
Neal
FRC #1777 (Viking Robotics)
Team Role: Mentor
 
Join Date: Jan 2012
Rookie Year: 2009
Location: United States
Posts: 56
neal is an unknown quantity at this point
Re: Autonomous Motor Problems

So you the 8 would be 8000000 for 8 seconds, since it returns microseconds.

All Timer's you create are independent from each other. You can start, stop, reset each Timer whenever you want.
Reply With Quote
  #5   Spotlight this post!  
Unread 03-02-2012, 22:35
kinganu123 kinganu123 is offline
Registered User
FRC #1747
Team Role: Mentor
 
Join Date: Jan 2010
Rookie Year: 2008
Location: Piscataway, NJ
Posts: 243
kinganu123 is on a distinguished road
Re: Autonomous Motor Problems

I disabled watchdog (this was two years ago) when I was doing autonomous for programming. Try doing the same with motorsafety.
Just make sure you start it again during teleop
__________________
Reply With Quote
  #6   Spotlight this post!  
Unread 04-02-2012, 17:45
Chiller Chiller is offline
Registered User
AKA: Connor Christie
FRC #4095 (RoXI Robotics)
Team Role: Programmer
 
Join Date: Jan 2012
Rookie Year: 2012
Location: Wisconsin
Posts: 118
Chiller is on a distinguished road
Re: Autonomous Motor Problems

Nonono you dont need the for loop or the while loop... All you do is do a simple drive function and then put Timer.delay(8); and then after that set the motors to 0 speed. You dont really want a while loop in autonomous because then you will be doin the same thing over again and I dont think you would want that...
Reply With Quote
  #7   Spotlight this post!  
Unread 04-02-2012, 21:03
Djur's Avatar
Djur Djur is offline
WPILib
AKA: Sam Carlberg
no team
Team Role: Mentor
 
Join Date: Jan 2011
Rookie Year: 2009
Location: Massachusetts
Posts: 182
Djur will become famous soon enough
Re: Autonomous Motor Problems

SimpleRobot only has one thread. If you look at the Timer.delay() method, you'll see that it calls Thread.sleep(). You aren't able to do anything until the Thread wakes up again.
__________________
WPILib dev (RobotBuilder, SmartDashboard, GRIP)
Reply With Quote
  #8   Spotlight this post!  
Unread 04-02-2012, 23:07
NS_Radication's Avatar
NS_Radication NS_Radication is offline
Student
AKA: Marco Schoener
FRC #1369 (Minotaur)
Team Role: Programmer
 
Join Date: Jan 2012
Rookie Year: 2009
Location: Tampa
Posts: 88
NS_Radication is an unknown quantity at this point
Re: Autonomous Motor Problems

Then what is your solution Djur, because the API does not have many solutions.
__________________
Team 1369
Senior
Head Programmer (Java)
Head Electrician
Reply With Quote
  #9   Spotlight this post!  
Unread 05-02-2012, 00:49
Ginto8's Avatar
Ginto8 Ginto8 is offline
Programming Lead
AKA: Joe Doyle
FRC #2729 (Storm)
Team Role: Programmer
 
Join Date: Oct 2010
Rookie Year: 2010
Location: Marlton, NJ
Posts: 174
Ginto8 is a glorious beacon of lightGinto8 is a glorious beacon of lightGinto8 is a glorious beacon of lightGinto8 is a glorious beacon of lightGinto8 is a glorious beacon of light
Re: Autonomous Motor Problems

One of the (sometimes) more annoying aspects of programming a robot is that everything has to be "refreshed" periodically. Certain sensors have to be sampled at a high rate to get good results, speed controllers will stop if you leave them on for too long without setting them, etc. This means that programming a robot actually lends itself fairly well to the IterativeRobot setup: you write your Continuous() and Periodic() methods in a way that won't actually stop the robot from running.

In your case, the best idea is probably to do something like this:
Code:
Timer t = new Timer();
t.start();
while(t.get() < TIME_LIMIT*1000000)
    doStuff();
where TIME_LIMIT is your desired length of time in seconds, and doStuff() does stuff (in this case sets motor speed).

If you look at the source of WPILibJ's Timer class, there are a few interesting features: a method reset(), which resets the Timer's value to 0; a constructor which actually calls reset(), meaning that a new Timer always starts at 0; and stop(), which, although it may seem counter-intuitive, does not actually reset it, just prevents it from counting any further. Basically, it does what you want and keeps all the "old time" stuff behind the scenes, so you don't have to worry about it.
Reply With Quote
  #10   Spotlight this post!  
Unread 04-02-2012, 23:07
NS_Radication's Avatar
NS_Radication NS_Radication is offline
Student
AKA: Marco Schoener
FRC #1369 (Minotaur)
Team Role: Programmer
 
Join Date: Jan 2012
Rookie Year: 2009
Location: Tampa
Posts: 88
NS_Radication is an unknown quantity at this point
Re: Autonomous Motor Problems

Well the issue is that whether there is a loop or not, it still stops for a split second and uses the delay() as the "do nothing" time. Can you be more specific, a simple code example perhaps?
__________________
Team 1369
Senior
Head Programmer (Java)
Head Electrician
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 11:21.

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