Go to Post How many programmers does it take to change a light bulb? None. They'll just say it's a hardware problem. - crafty [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 17-02-2016, 08:22
Tominator368 Tominator368 is offline
Registered User
AKA: Thomas Schweich
FRC #4500 (Robohounds)
Team Role: Programmer
 
Join Date: Jan 2015
Rookie Year: 2013
Location: STL
Posts: 5
Tominator368 is an unknown quantity at this point
TeleopPeriodic doesn't seem to iterate fast enough to smoothly run motors

Once we finished wiring our robot, we decided to quickly throw together a program which would allow us to test all of our motors. It was simply an iterative robot which instantiated motors controllers like
Code:
Victor motor = new Victor(0);
for each motor we wanted to test, and then in TeleopPeriodic, had code that looked like:
Code:
void teleopPeriodic() {
   motor.set(.5);
}
Just to see if they would run, if we hooked them up right. But when I ran this code on a motor, it behaved sluggishly and was jittery. My theory was that the set() function wasn't being called rapidly enough, so I decided to place the call in a while loop so that it would iterate faster (I know you're not supposed to do this, since it screws up the timing completely) as follows:
Code:
void teleropPeriodic() {
   while(true) {
      motor.set(.5)
   } 
}
Lo and behold, the motor ran perfectly. Isn't the iterative code supposed to iterate fast enough to run a motor? Obviously we don't want to use a while loop in our actual code, since that would literally bring the period to a halt. If you are supposed to be able to do this, what might be causing the problem for us? Thanks.

Last edited by Tominator368 : 17-02-2016 at 08:23. Reason: Spacing
Reply With Quote
  #2   Spotlight this post!  
Unread 17-02-2016, 08:42
RufflesRidge RufflesRidge is offline
Registered User
no team
 
Join Date: Jan 2012
Location: USA
Posts: 989
RufflesRidge has a brilliant futureRufflesRidge has a brilliant futureRufflesRidge has a brilliant futureRufflesRidge has a brilliant futureRufflesRidge has a brilliant futureRufflesRidge has a brilliant futureRufflesRidge has a brilliant futureRufflesRidge has a brilliant futureRufflesRidge has a brilliant futureRufflesRidge has a brilliant futureRufflesRidge has a brilliant future
Re: TeleopPeriodic doesn't seem to iterate fast enough to smoothly run motors

Quote:
Originally Posted by Tominator368 View Post
If you are supposed to be able to do this, what might be causing the problem for us? Thanks.
Massive packet loss is the first thing that comes to mind. The TeleopPeriodic function runs once per received packet. Nominally, this is every 20ms, but if you have a bad WiFi signal or other cause of substantial packet loss, it could be much slower.

Have you looked at the DS charts tab while this was happening or the DS log after?
Reply With Quote
  #3   Spotlight this post!  
Unread 17-02-2016, 09:42
Arhowk's Avatar
Arhowk Arhowk is offline
FiM CSA
AKA: Jake Niman
FRC #1684 (The Chimeras) (5460 Mentor)
 
Join Date: Jan 2013
Rookie Year: 2013
Location: Lapeer
Posts: 542
Arhowk is a splendid one to beholdArhowk is a splendid one to beholdArhowk is a splendid one to beholdArhowk is a splendid one to beholdArhowk is a splendid one to beholdArhowk is a splendid one to behold
Re: TeleopPeriodic doesn't seem to iterate fast enough to smoothly run motors

Your analysis of the cause of the problem is incorrect. Motors will continue to go at the rate that they were previously assigned. If you were to place that motor set out of the while true loop, the motor should behave (rather it be jittery or smooth)

Speaking remotely, there are a few probable causes for what you are experiencing. Since your code runs multiple motors in the first scenario, is it possible a typo caused you to set the same motor twice with two different values? Is there nothing else being done to the motors in that scenario?

Are your communications totally perfect with 2-10ms ping and no packet loss? You could just be blocking the code that checks for proper router communication in the while true loop
__________________
FRC Team 1684 - Head Programmer (2013-2016)
FRC Team 5460 - Programming Mentor (2015-2016)

FIRST in Michigan - Technical Crew (2015-continuing)
Reply With Quote
  #4   Spotlight this post!  
Unread 17-02-2016, 11:43
Tominator368 Tominator368 is offline
Registered User
AKA: Thomas Schweich
FRC #4500 (Robohounds)
Team Role: Programmer
 
Join Date: Jan 2015
Rookie Year: 2013
Location: STL
Posts: 5
Tominator368 is an unknown quantity at this point
Re: TeleopPeriodic doesn't seem to iterate fast enough to smoothly run motors

Quote:
Originally Posted by Arhowk View Post
Your analysis of the cause of the problem is incorrect. Motors will continue to go at the rate that they were previously assigned. If you were to place that motor set out of the while true loop, the motor should behave (rather it be jittery or smooth)
Could you explain this further? I'm quite sure motors will not keep their most recent value, at least, for instance, if I were to simply call a set() function in robotInit() so that it was only set once; the motor wouldn't run infinitely in this scenario. By outside the while true loop, do you mean before it so that it is set and then the while loop prevents another iteration?

Quote:
Speaking remotely, there are a few probable causes for what you are experiencing. Since your code runs multiple motors in the first scenario, is it possible a typo caused you to set the same motor twice with two different values? Is there nothing else being done to the motors in that scenario?
Good point, but I tried with only one motor and came up with the same results.

Quote:
Are your communications totally perfect with 2-10ms ping and no packet loss? You could just be blocking the code that checks for proper router communication in the while true loop
Quite possibly not. As the other comment mentioned, I'll need to check that tonight and post back. Thanks!
Reply With Quote
  #5   Spotlight this post!  
Unread 17-02-2016, 12:09
virtuald's Avatar
virtuald virtuald is offline
RobotPy Guy
AKA: Dustin Spicuzza
FRC #1418 (), FRC #1973, FRC #4796, FRC #6367 ()
Team Role: Mentor
 
Join Date: Dec 2008
Rookie Year: 2003
Location: Boston, MA
Posts: 1,050
virtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant future
Re: TeleopPeriodic doesn't seem to iterate fast enough to smoothly run motors

It would be interesting if you calculated the average/min/max delay time between calls to teleopPeriodic.

Incidentally, the possible inconsistency of packet arrival times is why I tend to use SampleRobot instead of IterativeRobot.
__________________
Maintainer of RobotPy - Python for FRC
Creator of pyfrc (Robot Simulator + utilities for Python) and pynetworktables/pynetworktables2js (NetworkTables for Python & Javascript)

2017 Season: Teams #1973, #4796, #6369
Team #1418 (remote mentor): Newton Quarterfinalists, 2016 Chesapeake District Champion, 2x Innovation in Control award, 2x district event winner
Team #1418: 2015 DC Regional Innovation In Control Award, #2 seed; 2014 VA Industrial Design Award; 2014 Finalists in DC & VA
Team #2423: 2012 & 2013 Boston Regional Innovation in Control Award


Resources: FIRSTWiki (relaunched!) | My Software Stuff
Reply With Quote
  #6   Spotlight this post!  
Unread 17-02-2016, 12:13
Mark McLeod's Avatar
Mark McLeod Mark McLeod is offline
Just Itinerant
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: 8,753
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: TeleopPeriodic doesn't seem to iterate fast enough to smoothly run motors

Quote:
Originally Posted by Tominator368 View Post
Could you explain this further? I'm quite sure motors will not keep their most recent value, at least, for instance, if I were to simply call a set() function in robotInit() so that it was only set once; the motor wouldn't run infinitely in this scenario.
Actually, the motor does keep the same value until your code changes it to something else.

The motor will however stop if there is a motor safety engaged. The motor safety times out if the motor isn't continuously set, because it assumes the code is locked up after ~.1 second or whatever time you set the motor exception to, and cuts off the PWM to prevent a runaway motor.
If your code disabled the motor safety then the motor would suddenly burst back to life at whatever speed was set however long ago.
The motor safety is optional, but is probably engaged by default.
__________________
"Rationality is our distinguishing characteristic - it's what sets us apart from the beasts." - Aristotle

Last edited by Mark McLeod : 17-02-2016 at 12:22.
Reply With Quote
  #7   Spotlight this post!  
Unread 18-02-2016, 08:34
RufflesRidge RufflesRidge is offline
Registered User
no team
 
Join Date: Jan 2012
Location: USA
Posts: 989
RufflesRidge has a brilliant futureRufflesRidge has a brilliant futureRufflesRidge has a brilliant futureRufflesRidge has a brilliant futureRufflesRidge has a brilliant futureRufflesRidge has a brilliant futureRufflesRidge has a brilliant futureRufflesRidge has a brilliant futureRufflesRidge has a brilliant futureRufflesRidge has a brilliant futureRufflesRidge has a brilliant future
Re: TeleopPeriodic doesn't seem to iterate fast enough to smoothly run motors

Quote:
Originally Posted by Mark McLeod View Post
If your code disabled the motor safety then the motor would suddenly burst back to life at whatever speed was set however long ago.
The motor safety is optional, but is probably engaged by default.
I don't remember in LabVIEW, but in C++ and Java the motor will not restart unless you call Set(). Simply disabling motor safety after it has expired will not cause the motor to restart.

In all 3 languages, MotorSafety is on by default for RobotDrive and off by default for everything else.
Reply With Quote
  #8   Spotlight this post!  
Unread 18-02-2016, 09:18
Mark McLeod's Avatar
Mark McLeod Mark McLeod is offline
Just Itinerant
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: 8,753
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: TeleopPeriodic doesn't seem to iterate fast enough to smoothly run motors

Yep, because the safety turning the motor off was the last setting the motor saw.
__________________
"Rationality is our distinguishing characteristic - it's what sets us apart from the beasts." - Aristotle
Reply With Quote
  #9   Spotlight this post!  
Unread 17-02-2016, 11:33
Tominator368 Tominator368 is offline
Registered User
AKA: Thomas Schweich
FRC #4500 (Robohounds)
Team Role: Programmer
 
Join Date: Jan 2015
Rookie Year: 2013
Location: STL
Posts: 5
Tominator368 is an unknown quantity at this point
Re: TeleopPeriodic doesn't seem to iterate fast enough to smoothly run motors

Quote:
if you have a bad WiFi signal or other cause of substantial packet loss, it could be much slower.
This is distinctly possible, I hadn't thought to check latency. I'll report back once I'm able to test again this evening. If it is latency, what might be causing it? The computer running the code was in the same room as the router. Come to think of it, the code was deployed from a computer which is not the classmate, and may have had a firewall, etc. Could that be the cause? Thanks.
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 10:26.

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