Go to Post Bottom line: hobbiests, hackers, and tinkerers can fiddle with something and make it work. Engineers are people who [b]engineer[/b] solutions to problems. - Dave Flowerday [more]
Home
Go Back   Chief Delphi > Technical > Programming > Python
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
 
 
Thread Tools Rate Thread Display Modes
Prev Previous Post   Next Post Next
  #5   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
 


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 06:25.

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