View Single Post
  #1   Spotlight this post!  
Unread 24-01-2016, 18:55
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,043
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: Running different functions at the same time?

Quote:
Originally Posted by TimTheGreat View Post
The good (and bad) thing about motors is if you don't tell them what to do, they'll do the last thing they were told. This means if you forget to set a motor to 0 when you're done with it it will stay turned on. You can use this to your advantage

Code:
if state == 1:
    motor.set(1)
    state = 2
if state == 2:
    do_pneumatic_stuff()
    #because the motor hasn't been set to 0, it's still set to 1
    if pneumatic_stuff_done:
        state == 3
if state == 3
    motor.set(0) #Now we set it to 0 to stop it
While you're right that this technique works, I highly recommend against it. Instead, I would explicitly set the motor in each branch, so you can be absolutely sure that the motor is doing what you want.

But, you can do something like this:

Code:
if self.state == 1:
    self.piston.fire()
elif state == 2:
    something_else

.. 

self.motor.set(1)
As you can see, as long as the motor setting is *always* happening and isn't excluded by some if statement, then you're fine.
__________________
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