![]() |
Running different functions at the same time?
Hi,
So we are planning on making a shooter to throw the boulders into the high goal. I need to be able to spin the shooter motor while the pneumatics are being retracted. My thought would be to have another thread using Python's threading module and just starting a new thread for the motor but I don't know if that is the recommended way of accomplishing it. Here is an example of what I have. I need that for loop to be going while the pneumatics are being set to false. Code:
if self.arm1.get()==True:Thanks! |
Re: Running different functions at the same time?
There are a number of ways of dealing with this in python. Threads are one of them -- but I generally recommend avoiding threads in robot programming, as it's too easy to get it wrong and there are other ways of doing it that work just as well for many (but not all) problems.
The traditional way of dealing with this sort of thing is through logical constructs referred to as state machines. The idea is to execute the same piece over and over again (but not in a loop), Code:
if self.state == 0:Another way of dealing with this that's unique to python is by using generators (the Yeti framework that team 4819 has does this), but it's more of an advanced topic. |
Re: Running different functions at the same time?
Quote:
|
Re: Running different functions at the same time?
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: |
Re: Running different functions at the same time?
Quote:
But, you can do something like this: Code:
if self.state == 1: |
| All times are GMT -5. The time now is 19:52. |
Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi