Multi threading

For Formula AllCode users to discuss projects, programs, and any other issues related to the Formula AllCode robotics platform.

Moderators: Benj, Mods

mark_harrison
Posts: 2
Joined: Thu Sep 29, 2016 2:51 pm
Contact:

Multi threading

Postby mark_harrison » Thu Sep 29, 2016 2:55 pm

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

User avatar
Benj
Matrix Staff
Posts: 14157
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4330 times
Been thanked: 4080 times
Contact:

Re: Multi threading

Postby Benj » Thu Sep 29, 2016 4:43 pm

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.

mark_harrison
Posts: 2
Joined: Thu Sep 29, 2016 2:51 pm
Contact:

Re: Multi threading

Postby mark_harrison » Mon Oct 03, 2016 5:33 pm

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

User avatar
Benj
Matrix Staff
Posts: 14157
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4330 times
Been thanked: 4080 times
Contact:

Re: Multi threading

Postby Benj » Mon Oct 03, 2016 5:48 pm

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.