Go to Post I then asked if I could use a flux capacitor for power, but that didn't go over too well, either (they did say I could use it for decorative purposes, though). - Kevin Watson [more]
Home
Go Back   Chief Delphi > Technical > Programming > C/C++
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 17-03-2015, 21:37
DanG100 DanG100 is offline
DanG!
FRC #2367
Team Role: Programmer
 
Join Date: Mar 2015
Rookie Year: 2013
Location: California
Posts: 6
DanG100 is an unknown quantity at this point
Using a separate thread for driving motors?

After being plagued with issues at CVR, with MotorSafetyHelper timeout exceeded errors, I moved all drivetrain calls to a separate thread.

Has any team successfully, but the robot drive code into another thread, to prevent motor safety helper timeout? Or other tips to prevent from happening.
Reply With Quote
  #2   Spotlight this post!  
Unread 17-03-2015, 21:50
JefferMC JefferMC is offline
Registered User
AKA: Jeff Corbett
FRC #1319 (Flash)
Team Role: Mentor
 
Join Date: Nov 2012
Rookie Year: 2005
Location: United States
Posts: 44
JefferMC will become famous soon enough
Re: Using a separate thread for driving motors?

You could lengthen the timeout from the default of 0.10 seconds to something less touchy... like 0.21 seconds. A lot of teams just disable it altogether; safety is such a pesky thing.

Are you sure you're setting the motor values in every iterative pass?

Are your iterations taking more than 0.02 seconds to execute? Are you having to do a lot of computations (camera processing)?

Are you sending too much data to the dashboard (or too often) and having the communications jam up on you?
Reply With Quote
  #3   Spotlight this post!  
Unread 17-03-2015, 22:05
Ben Wolsieffer Ben Wolsieffer is offline
Dartmouth 2020
AKA: lopsided98
FRC #2084 (Robots by the C)
Team Role: Alumni
 
Join Date: Jan 2011
Rookie Year: 2011
Location: Manchester, MA (Hanover, NH)
Posts: 520
Ben Wolsieffer has much to be proud ofBen Wolsieffer has much to be proud ofBen Wolsieffer has much to be proud ofBen Wolsieffer has much to be proud ofBen Wolsieffer has much to be proud ofBen Wolsieffer has much to be proud ofBen Wolsieffer has much to be proud ofBen Wolsieffer has much to be proud of
Re: Using a separate thread for driving motors?

I would recommend not moving your drive code to a separate thread, because it is easy to create lots of subtle bugs this way, such as race conditions or deadlocks (less likely in robot code, but still possible).

The motor safety timer (ie. watchdog) also exists for a very good reason. If you run your drive code in a separate thread, and the main robot thread crashes, the robot will not stop like it is supposed to, possibly causing a runaway robot (edit: It will still stop when you press disable, but what I meant was that you might not be able to stop it quickly if the robot stops responding to joystick inputs and you do not realize it immediately).

My recommendation is that you figure out what part of the code is taking a long time to execute (and causing watchdog timeouts), and possibly move that to a separate thread (likely candidate: vision processing). I would look at Jeff's suggestions and try to see if you can find the root of the problem. I would not disable the safety until you have thoroughly examined your code, because the timeouts are likely a symptom of a real problem that could make your controls laggy or unresponsive.

If you do move code to a separate thread, make sure you understand well the concepts of multithreading, because threading bugs can be a huge pain to track down, especially under pressure at a competition.
__________________



2016 North Shore District - Semifinalists and Excellence in Engineering Award
2015 Northeastern University District - Semifinalists and Creativity Award
2014 Granite State District - Semifinalists and Innovation in Control Award
2012 Boston Regional - Finalists

Last edited by Ben Wolsieffer : 18-03-2015 at 17:40. Reason: Clarify one of my points
Reply With Quote
  #4   Spotlight this post!  
Unread 18-03-2015, 16:59
DanG100 DanG100 is offline
DanG!
FRC #2367
Team Role: Programmer
 
Join Date: Mar 2015
Rookie Year: 2013
Location: California
Posts: 6
DanG100 is an unknown quantity at this point
Re: Using a separate thread for driving motors?

But won't the FMS still disable the drive motors even if motorsafetyhelper is disabled?
Reply With Quote
  #5   Spotlight this post!  
Unread 18-03-2015, 17:11
Ben Wolsieffer Ben Wolsieffer is offline
Dartmouth 2020
AKA: lopsided98
FRC #2084 (Robots by the C)
Team Role: Alumni
 
Join Date: Jan 2011
Rookie Year: 2011
Location: Manchester, MA (Hanover, NH)
Posts: 520
Ben Wolsieffer has much to be proud ofBen Wolsieffer has much to be proud ofBen Wolsieffer has much to be proud ofBen Wolsieffer has much to be proud ofBen Wolsieffer has much to be proud ofBen Wolsieffer has much to be proud ofBen Wolsieffer has much to be proud ofBen Wolsieffer has much to be proud of
Re: Using a separate thread for driving motors?

Quote:
Originally Posted by DanG100 View Post
But won't the FMS still disable the drive motors even if motorsafetyhelper is disabled?
Yes, assuming you press the e-stop or disable button, but that might not happen immediately when someone realizes the robot is no longer responding to their inputs, especially while practicing. Admittedly, disabling the watchdog is not that big a deal safety wise, but it is more important in discovering that code is causing the robot controls to not run as fast as they should be.
__________________



2016 North Shore District - Semifinalists and Excellence in Engineering Award
2015 Northeastern University District - Semifinalists and Creativity Award
2014 Granite State District - Semifinalists and Innovation in Control Award
2012 Boston Regional - Finalists
Reply With Quote
  #6   Spotlight this post!  
Unread 18-03-2015, 17:28
Jefferson Jefferson is offline
Registered User
AKA: Jeff Clements
FRC #0016 (Bomb Squad)
Team Role: Mentor
 
Join Date: Jan 2011
Rookie Year: 2010
Location: Mountain Home, AR
Posts: 257
Jefferson has a brilliant futureJefferson has a brilliant futureJefferson has a brilliant futureJefferson has a brilliant futureJefferson has a brilliant futureJefferson has a brilliant futureJefferson has a brilliant futureJefferson has a brilliant futureJefferson has a brilliant futureJefferson has a brilliant futureJefferson has a brilliant future
Re: Using a separate thread for driving motors?

Quote:
Originally Posted by lopsided98 View Post
If you run your drive code in a separate thread, and the main robot thread crashes, the robot will not stop like it is supposed to, possibly causing a runaway robot.
Do you know this for a fact or just theorizing here? If the main robot thread actually crashes, the HAL + FRC firmware disable all outputs, right?

I'm not deeply familiar with these concepts. Maybe somebody could comment with a little more authority than I.
Reply With Quote
  #7   Spotlight this post!  
Unread 18-03-2015, 17:37
Ben Wolsieffer Ben Wolsieffer is offline
Dartmouth 2020
AKA: lopsided98
FRC #2084 (Robots by the C)
Team Role: Alumni
 
Join Date: Jan 2011
Rookie Year: 2011
Location: Manchester, MA (Hanover, NH)
Posts: 520
Ben Wolsieffer has much to be proud ofBen Wolsieffer has much to be proud ofBen Wolsieffer has much to be proud ofBen Wolsieffer has much to be proud ofBen Wolsieffer has much to be proud ofBen Wolsieffer has much to be proud ofBen Wolsieffer has much to be proud ofBen Wolsieffer has much to be proud of
Re: Using a separate thread for driving motors?

Quote:
Originally Posted by Jefferson View Post
Do you know this for a fact or just theorizing here? If the main robot thread actually crashes, the HAL + FRC firmware disable all outputs, right?

I'm not deeply familiar with these concepts. Maybe somebody could comment with a little more authority than I.
Sorry for the misunderstanding: I meant that it will run away until you realize what is happening and press disable/e-stop, which isn't that big a problem.
__________________



2016 North Shore District - Semifinalists and Excellence in Engineering Award
2015 Northeastern University District - Semifinalists and Creativity Award
2014 Granite State District - Semifinalists and Innovation in Control Award
2012 Boston Regional - Finalists
Reply With Quote
  #8   Spotlight this post!  
Unread 18-03-2015, 18:02
Jefferson Jefferson is offline
Registered User
AKA: Jeff Clements
FRC #0016 (Bomb Squad)
Team Role: Mentor
 
Join Date: Jan 2011
Rookie Year: 2010
Location: Mountain Home, AR
Posts: 257
Jefferson has a brilliant futureJefferson has a brilliant futureJefferson has a brilliant futureJefferson has a brilliant futureJefferson has a brilliant futureJefferson has a brilliant futureJefferson has a brilliant futureJefferson has a brilliant futureJefferson has a brilliant futureJefferson has a brilliant futureJefferson has a brilliant future
Re: Using a separate thread for driving motors?

Quote:
Originally Posted by lopsided98 View Post
Sorry for the misunderstanding: I meant that it will run away until you realize what is happening and press disable/e-stop, which isn't that big a problem.
But I still don't think that's the case. I don't believe separate threads outside the main robot thread can keep the robot alive if the main thread has died.
Reply With Quote
  #9   Spotlight this post!  
Unread 18-03-2015, 18:13
Ben Wolsieffer Ben Wolsieffer is offline
Dartmouth 2020
AKA: lopsided98
FRC #2084 (Robots by the C)
Team Role: Alumni
 
Join Date: Jan 2011
Rookie Year: 2011
Location: Manchester, MA (Hanover, NH)
Posts: 520
Ben Wolsieffer has much to be proud ofBen Wolsieffer has much to be proud ofBen Wolsieffer has much to be proud ofBen Wolsieffer has much to be proud ofBen Wolsieffer has much to be proud ofBen Wolsieffer has much to be proud ofBen Wolsieffer has much to be proud ofBen Wolsieffer has much to be proud of
Re: Using a separate thread for driving motors?

Quote:
Originally Posted by Jefferson View Post
But I still don't think that's the case. I don't believe separate threads outside the main robot thread can keep the robot alive if the main thread has died.
Yes, your right. I'm more used to working with Java, where this is not the case, but in C++ (which I just realized the OP was using), exiting the main thread does cause all other threads to terminate.
__________________



2016 North Shore District - Semifinalists and Excellence in Engineering Award
2015 Northeastern University District - Semifinalists and Creativity Award
2014 Granite State District - Semifinalists and Innovation in Control Award
2012 Boston Regional - Finalists
Reply With Quote
  #10   Spotlight this post!  
Unread 18-03-2015, 18:25
Ether's Avatar
Ether Ether is offline
systems engineer (retired)
no team
 
Join Date: Nov 2009
Rookie Year: 1969
Location: US
Posts: 8,044
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: Using a separate thread for driving motors?

Quote:
Originally Posted by Jefferson View Post
I don't believe separate threads outside the main robot thread can keep the robot alive if the main thread has died.
Quote:
Originally Posted by lopsided98 View Post
Yes, your [sic] right... in C++, exiting the main thread does cause all other threads to terminate.
Jefferson wrote "if the main thread has died", and lopsided98 wrote "exiting the main thread".

So it's not yet clear if you are both saying exactly the same thing. It depends on Jefferson's intended meaning of "died": If the main thread is blocked or busy-waiting for an event that never occurs, it could be considered to have "died" but not "exited".



Last edited by Ether : 18-03-2015 at 18:30.
Reply With Quote
  #11   Spotlight this post!  
Unread 18-03-2015, 18:33
Ben Wolsieffer Ben Wolsieffer is offline
Dartmouth 2020
AKA: lopsided98
FRC #2084 (Robots by the C)
Team Role: Alumni
 
Join Date: Jan 2011
Rookie Year: 2011
Location: Manchester, MA (Hanover, NH)
Posts: 520
Ben Wolsieffer has much to be proud ofBen Wolsieffer has much to be proud ofBen Wolsieffer has much to be proud ofBen Wolsieffer has much to be proud ofBen Wolsieffer has much to be proud ofBen Wolsieffer has much to be proud ofBen Wolsieffer has much to be proud ofBen Wolsieffer has much to be proud of
Re: Using a separate thread for driving motors?

Ether brings up a good point. I was thinking about the case where the main thread finished its execution or threw an exception, in which case all other threads would exit.

But if for the main thread locked up without actually exiting or crashing (something that becomes more likely when you start communicating between multiple threads), the other threads (such as the one controlling the driving) could continue executing. Like I mentioned before, the e-stop/disable buttons would still be able to stop the robot in this case.
__________________



2016 North Shore District - Semifinalists and Excellence in Engineering Award
2015 Northeastern University District - Semifinalists and Creativity Award
2014 Granite State District - Semifinalists and Innovation in Control Award
2012 Boston Regional - Finalists
Reply With Quote
  #12   Spotlight this post!  
Unread 18-03-2015, 19:51
connor.worley's Avatar
connor.worley connor.worley is offline
Registered User
FRC #0973 (Greybots)
Team Role: Mentor
 
Join Date: Mar 2011
Rookie Year: 2010
Location: Berkeley/San Diego
Posts: 601
connor.worley has a reputation beyond reputeconnor.worley has a reputation beyond reputeconnor.worley has a reputation beyond reputeconnor.worley has a reputation beyond reputeconnor.worley has a reputation beyond reputeconnor.worley has a reputation beyond reputeconnor.worley has a reputation beyond reputeconnor.worley has a reputation beyond reputeconnor.worley has a reputation beyond reputeconnor.worley has a reputation beyond reputeconnor.worley has a reputation beyond repute
Re: Using a separate thread for driving motors?

OP, would you mind posting your code? I would advise trying to find the root of the problem in the main thread rather than moving drive code out.
__________________
Team 973 (2016-???)
Team 5499 (2015-2016)
Team 254 (2014-2015)

Team 1538 (2011-2014)
2014 Driver (25W 17L 1T)
日本語でOK
Reply With Quote
  #13   Spotlight this post!  
Unread 18-03-2015, 19:57
Ether's Avatar
Ether Ether is offline
systems engineer (retired)
no team
 
Join Date: Nov 2009
Rookie Year: 1969
Location: US
Posts: 8,044
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: Using a separate thread for driving motors?

Quote:
Originally Posted by connor.worley View Post
I would advise trying to find the root of the problem
ditto that.

Reply With Quote
  #14   Spotlight this post!  
Unread 19-03-2015, 02:21
Jefferson Jefferson is offline
Registered User
AKA: Jeff Clements
FRC #0016 (Bomb Squad)
Team Role: Mentor
 
Join Date: Jan 2011
Rookie Year: 2010
Location: Mountain Home, AR
Posts: 257
Jefferson has a brilliant futureJefferson has a brilliant futureJefferson has a brilliant futureJefferson has a brilliant futureJefferson has a brilliant futureJefferson has a brilliant futureJefferson has a brilliant futureJefferson has a brilliant futureJefferson has a brilliant futureJefferson has a brilliant futureJefferson has a brilliant future
Re: Using a separate thread for driving motors?

Quote:
Originally Posted by Ether View Post
Jefferson wrote "if the main thread has died", and lopsided98 wrote "exiting the main thread".

So it's not yet clear if you are both saying exactly the same thing. It depends on Jefferson's intended meaning of "died": If the main thread is blocked or busy-waiting for an event that never occurs, it could be considered to have "died" but not "exited".


Good point. I meant exiting the main thread.

I'll throw in with everybody else and recommend finding the root cause of the motor safety errors in the first place.
Reply With Quote
  #15   Spotlight this post!  
Unread 19-03-2015, 11:59
DanG100 DanG100 is offline
DanG!
FRC #2367
Team Role: Programmer
 
Join Date: Mar 2015
Rookie Year: 2013
Location: California
Posts: 6
DanG100 is an unknown quantity at this point
Re: Using a separate thread for driving motors?

This is the code for the robot, except all the camera code was commented out at competition.
https://github.com/Saint-Francis-Rob...367/FinalRobot
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 14:01.

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