Multi threading

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

Moderators: Benj, Mods

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

Multi threading

Post 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

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

Re: Multi threading

Post 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.

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

Re: Multi threading

Post 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

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

Re: Multi threading

Post 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.

Post Reply