Discussion forum for the BasicX family of microcontroller chips.
|
I am a little new to the BX-24 chip and had a question about multitasking. I am building an autonomous sumo robot for a competition and need the sensors being read very quickly. I was wondering if I have the tasks that I want to run simotaniously in sub main in a do loop (as shown in the code below) is this the proper way to use multitasking and if it would work. Also if i call a sub program from a task will this halt multitasking? dim stacksonar(1 to 40) as byte dim stacklightsensors(1 to 40) as byte dim stackbumpers(1 to 40) as byte dim stackwhereto(1 to 40) as byte sub main() do calltask "lightsensorstask", stacklightsensors calltask "sonarstack", stacksonar calltask "bumperstask", stackbumpers calltask "wheretotask", stackwhereto loop end sub sub sonarintask() do call sleep (0.0) "statements" loop end sub sub lightsensorstask() do call sleep (0.0) "statements" loop end sub and so on..... |
|
|
|
do this. calling a sub will not hals multitaskin. Many tasks will slow thing down though. too many and you run out of stack space. just with the stacks here you are using 160 bytes of your 512. can the sonor, lightsensor and bumpers run in one "sensor" task? the code in a bx should be fast enough for that easly. dim stacksonar(1 to 40) as byte dim stacklightsensors(1 to 40) as byte dim stackbumpers(1 to 40) as byte dim stackwhereto(1 to 40) as byte sub main() calltask "lightsensorstask", stacklightsensors calltask "sonarstack", stacksonar calltask "bumperstask", stackbumpers calltask "wheretotask", stackwhereto ' you only need to call the tasks once ' the do/loop in the task will keep it going ' the main task runs also do call sleep (0.0) "statements" loop end sub sub sonarintask() do call sleep (0.0) "statements" loop end sub sub lightsensorstask() do call sleep (0.0) "statements" loop end sub ===== Tony Brenke North Tacoma, WA __________________________________________________ |
|
|
|
In my original code I had all the sensors being read in one big sub program and one big do loop. This wasnt fast enough. Each sensor will call a sub forward, back, right, or left (which control the motors) if they detect something Will putting them into one big task and splitting them into small subs within the task (like in the reply message) make it fater than using one big sub program? |
|
|
|
>Will putting them into one big task and splitting them into > small subs within the task (like in the reply > message) make it fater than using one big sub program? no. all tasks run on only one prossesor. put the sensors in a tight loop for reading there value and storing it in a varable. then read the varable in the main program and make the choises from there. that way the sensors are close to real time. there is a ballance you will have to work out. --- wrote: > In my original code I had all the sensors being read in one big sub > program and one big do loop. This wasnt fast enough. Each sensor > will call a sub forward, back, right, or left (which control the > motors) if they detect something Will putting them into one big task > > and splitting them into small subs within the task (like in the reply > > message) make it fater than using one big sub program? > ------------------------ Yahoo! Groups Sponsor > > ===== Tony Brenke North Tacoma, WA __________________________________________________ |
|
--- In basicx@y..., nick4562002@y... wrote: > In my original code I had all the sensors being read in one big sub > program and one big do loop. This wasnt fast enough. Each sensor > will call a sub forward, back, right, or left (which control the > motors) if they detect something Will putting them into one big task > and splitting them into small subs within the task (like in the reply > message) make it fater than using one big sub program? There whould be a definitive solution. Hooking all the sensor (maybe grouping some of them) to a sort of interrupt chip controller. This way the processor only analizes the change instead of pulling continuos them. This whould be a nice project for those already skilled whid the basic-x chip. Bye Kai |