|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
|
|
Thread Tools | Rate Thread | Display Modes |
|
|
|
#1
|
|||
|
|||
|
Re: [Q] How are we supposed to use threads in our robot code?
Are you saying that I have to use boost and WPILib's task class? I looked on WPILib's task documentation page , and it doesn't look like I need to. Just looking for clarification.
Also, on the above page, it says the task::run takes the arguments of types FUNCPTR and int. just asking, the fcptr is just the function name without any arguments or parentheses, correct? Also the arguments are of type int, does that mean I can only pass integers? Sorry for bombarding you with questions but, like I said, I'm new to this and have no coders on the team experienced enough with c++ to help us. |
|
#2
|
|||||
|
|||||
|
Re: [Q] How are we supposed to use threads in our robot code?
I would take a look at pthreads.
|
|
#3
|
||||
|
||||
|
Re: [Q] How are we supposed to use threads in our robot code?
Quote:
Quote:
Quote:
I recommend searching these forums for more information, other people have asked the same questions. |
|
#4
|
|||||
|
|||||
|
Re: [Q] How are we supposed to use threads in our robot code?
You will never need to use Boost or any external libraries for any multithreading in C++ for FRC, so save yourself some headaches and just WPILib because it works like a charm.
Here's some code that makes a separate thread to flip the state of a relay, which is spawned at TeleopInit, and killed off at DisabledInit. Code:
class Robot: public SimpleRobot{
Task secondThread;
Relay *relay;
public:
Robot():
secondThread("SecondThread",(FUNCPTR) Robot::threadFunction)
{
relay=new Relay(1);
}
void threadFunction(UINT32 relayPointer){
Relay *rly=(Relay*)relayPointer;
while(true){
rly->Set(Relay::kForward);
Wait(1);
rly->Set(Relay::kReverse);
Wait(1);
}
}
void Disabled(){
secondThread.Stop();
}
void Teleop(){
secondThread.Start((UINT32) relay);
}
};
START_ROBOT_CLASS(Robot)
;
http://www.chiefdelphi.com/forums/sh...ad.php?t=82398 If you need explanation of anything in this post, just refer to that post^ Last edited by Toa Circuit : 30-04-2013 at 22:01. Reason: Realizing a few things |
|
#5
|
||||
|
||||
|
Re: [Q] How are we supposed to use threads in our robot code?
My team produced a class this year which worked quite well and is quite extensible. All the source is on github. I also gave a pretty complete training discussion about how the class works and why in:
http://www.chiefdelphi.com/forums/sh...87#post1232587 If you have questions after reading that, feel free to contact me or post here. or there. Thanks, bob |
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|