Page 1 of 1

Multi threading

Posted: Thu Sep 29, 2016 2:55 pm
by mark_harrison
Hi all - just starting to get to grips with Formula Allcode through VB and connecting to the robot via Bluetooth.

Does anybody know if it's possible to multithread? For example to have a siren sounding as the robot moves? I've given it a whirl but it doesn't seem to like it.

Thanks
Mark

Re: Multi threading

Posted: Thu Sep 29, 2016 4:43 pm
by Benj
Hi Mark,

You should be able to use the SetMotors function and then call the PlayNote function while the robot is moving. The SetMotors function does not use encoder feedback and so will immediately return allowing you to call other functions.

Note that using SetMotors if using speeds below 20 the motor may not start or may be less balanced as it just controls the PWM signals to the motors.

Re: Multi threading

Posted: Mon Oct 03, 2016 5:33 pm
by mark_harrison
Thanks Benj

What's the tactic for getting more than one robot to 'dance' in time with another? If you can't multithread then how do you send simultaneous commands to the different ports? Or would you have to run the code from an SD card and sync them by pressing a button on them all at the same time?

cheers
Mark

Re: Multi threading

Posted: Mon Oct 03, 2016 5:48 pm
by Benj
Hi Mark,

Getting multiple robots to dance together is usually a case of giving each robot a command at high speed. Usually this is enough to make it appear that the robots are exactly in sync even though there could be a few nano/micro/milliseconds between each robot. As you can send out commands at high speed but generally the robot is moving for seconds the illusion of dancing in sync should be easy to achieve.

e.g.

Code: Select all

FA1 = OpenCom (0)
FA2 = OpenCom (1)

FA1.SetMotors(50, 50)
FA2.SetMotors(50, 50)

Delay 1 Second

FA1.SetMotors(-50, 50)
FA2.SetMotors(-50, 50)

Delay 1 Second

Your method of storing commands on an SD card and pressing each switch at the same time would also work but in manually pressing the switch you will likely incur larger delays then using the API method.