Go to Post Though, of course, if the old one you like is shot, then you can just beat your new one with a hammer until it works the way you want. - Kevin Sevcik [more]
Home
Go Back   Chief Delphi > Technical > Programming > WindRiver C++
CD-Events   CD-Media   CD-Spy   FRC-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 04-10-2012, 11:45 AM
Batman Batman is offline
Registered User
AKA: Evan Wiederspan
FRC #3663 (CPR)
Team Role: Programmer
 
Join Date: Feb 2012
Rookie Year: 2012
Location: Bothell, WA
Posts: 4
Batman is an unknown quantity at this point
SetSafetyEnabled() and SetExpiration()

During the beginning of the season, our robot had about a quarter to a half second of lag, which I thought was just caused by a bad wireless connection. Then I noticed that all of the motors in the code (there are about 7) were set as follows:

motor1->SetSafetyEnabled(true);
motor1->SetExpiration(0.1);

So just because I had some free time I changed these settings on all the motors to the following:

motor1->SetSafetyEnabled(false);
motor1->SetExpiration(0.5);

When I did this, the robot started to run without any lag at all. What exactly do these functions do, and does anyone have any idea on how they would cause lag with the previous settings?
Reply With Quote
  #2   Spotlight this post!  
Unread 04-10-2012, 11:58 AM
Mark McLeod's Avatar
Mark McLeod Mark McLeod is offline
Itinerant Programmer
AKA: Hey dad...Father...MARK
FRC #0358 (Robotic Eagles)
Team Role: Engineer
 
Join Date: Mar 2003
Rookie Year: 2002
Location: Hauppauge, Long Island, NY
Posts: 7,188
Mark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond repute
Re: SetSafetyEnabled() and SetExpiration()

If SetSafetyEnabled is false, then the SetExpiration doesn't matter.

These are safeties for the drive motors that shut them down if the code goes for too long (.1 second as specified by SetExpiration) without setting the motor power. It's there to protect you, from infinite code loops or usually during debugging when you could set the motor speed and have a breakpoint that allows the robot to keep running without stopping or responding to driver controls.

If that solved your issue, then it can mean your code is laggy and not running as fast as you want it to (doing too much or having delays in your code), or your code is structured so that you aren't revisiting the motor often enough (set and leave until a change is necessary). Check the Charts tab of the Driver Station to see what communication delays may be happening.

You can run on the field without the Safety, but make sure the robot's up on blocks if you're running in debug with breakpoints set.
__________________
"A child of five could understand this. Fetch me a child of five." - Groucho Marx

Last edited by Mark McLeod : 04-10-2012 at 01:01 PM.
Reply With Quote
  #3   Spotlight this post!  
Unread 04-10-2012, 12:03 PM
DjScribbles DjScribbles is offline
Programming Mentor
AKA: Joe S
FRC #2474 (Team Excel)
Team Role: Mentor
 
Join Date: Oct 2011
Rookie Year: 2012
Location: Niles MI
Posts: 281
DjScribbles is a splendid one to beholdDjScribbles is a splendid one to beholdDjScribbles is a splendid one to beholdDjScribbles is a splendid one to beholdDjScribbles is a splendid one to beholdDjScribbles is a splendid one to beholdDjScribbles is a splendid one to beholdDjScribbles is a splendid one to behold
Re: SetSafetyEnabled() and SetExpiration()

If you don't call the motor periodically to set the speed (even if you are setting it to the same value again), it will be stopped and throw an error to the dashboard.

My understanding is that the lag comes from the time it takes to throw that error constantly across the network.

You can resolve the error by ensuring all your motors are being set all the time to a value whenever they are in use and set to 0 when not in use; you can then re-enable the safety.

It's a good idea to use the safety for your drive system especially, so that the robot can't get stuck moving at full throttle if there are communication issues; the safety timer should automatically stop your robot if it's not under control.
Reply With Quote
  #4   Spotlight this post!  
Unread 01-19-2013, 04:25 PM
jfitz0807 jfitz0807 is offline
Registered User
FRC #2877 (Ligerbots)
Team Role: Parent
 
Join Date: Jan 2009
Rookie Year: 2009
Location: Newton, MA
Posts: 23
jfitz0807 is an unknown quantity at this point
Re: SetSafetyEnabled() and SetExpiration()

We're using java and we had the same problem. We tried:

motor1->SetSafetyEnabled(true);
motor1->SetExpiration(10.0);

Even with these settings, the motor was running jerkily. The jerks were occurring much more frequently than 10 seconds. I know this because the command was defined to run for 3 seconds.

If we disabled the SetSafetyEnabled, the motor ran smoothly.

Any thoughts on why the system seems to think it needs to shut down the motor before the code can get through a single loop of the teleopPeriodic?
Reply With Quote
  #5   Spotlight this post!  
Unread 01-20-2013, 02:03 PM
TeraViks's Avatar
TeraViks TeraViks is offline
Registered User
AKA: Brian Induni
FRC #3145 (TeraViks)
Team Role: Coach
 
Join Date: Dec 2009
Rookie Year: 2009
Location: Hayden, Idaho
Posts: 33
TeraViks is a jewel in the roughTeraViks is a jewel in the roughTeraViks is a jewel in the roughTeraViks is a jewel in the rough
Re: SetSafetyEnabled() and SetExpiration()

Mark,

I'm interested in your comments "...it can mean your code is laggy and not running as fast as you want it to (doing too much or having delays in your code), or your code is structured so that you aren't revisiting the motor often enough (set and leave until a change is necessary)...".

We've had these same issues and I don't understand how to programatically affect timing to revisit the motor (or other object). Can you give some instruction or code snippet that might help? Thanks so much!
__________________
Brian
FIRST team 3145 (notice I'm doing Dean's homework!)
The TeraViks
Coeur d'Alene, Idaho
Reply With Quote
  #6   Spotlight this post!  
Unread 01-21-2013, 12:28 AM
bob.wolff68's Avatar
bob.wolff68 bob.wolff68 is offline
Da' Mentor Man
FRC #1967
Team Role: Mentor
 
Join Date: Jan 2012
Rookie Year: 2007
Location: United States
Posts: 117
bob.wolff68 is just really nicebob.wolff68 is just really nicebob.wolff68 is just really nicebob.wolff68 is just really nicebob.wolff68 is just really nice
Re: SetSafetyEnabled() and SetExpiration()

If you really have a laggy problem and are trying to figure out what is taking all the time, there are a number of tactics to take. One tactic that can be helpful is getting quantitative values that show "how much time does this part take?" Without a good professional profiler, you can use the 'old school' method of timing...usually you will have a good sense of what's taking all the time - like vision code processing takes a lot of time. Get a value...

I'd suggest something like:
Code:
int loopstart, loopend, videostart, videoend;
while (IsOperatorControl())
{
  loopstart = GetUsClock(); // microseconds since startup

 [ code code code ]
  // start of vision code
  videostart = GetUsClock(); // microseconds since startup
  ProcessImage();
  videoend = GetUsClock(); // microseconds since startup
[ code code code ]
  loopend = GetUsClock(); // microseconds since startup
  SmartDashboard::PutNumber("LoopTime-ms", (loopend-loopstart)/1000);
  SmartDashboard::PutNumber("VideoTime-ms", (videoend-videostart)/1000);
  
}
The gist here is to get an idea of at least two things -- how long does it take you to loop the loop and how long does your "big possible offender" take to run? In SmartDashboard, you can have these values plotted as a graph rather than as just numbers "flitting" on the dashboard. That helps to see if you have consistent results or if your processing is for some reason sporatic.
__________________
~~~~~~~~~~~~~~~~~~~
Bob Wolff - Software from the old-school
Mentor / C / C++ guy
Team 1967 - The Janksters - San Jose, CA
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 08:51 PM.

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


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