Learning on ActivityBot. How do I execute multiple tasks at once?
cstambaugh
Posts: 7
I purchased the activity bot a couple days ago. I was so excited I went through all the tutorial builds in a day haha. I'm sure I rushed things just to see how it works, and with this I know I'm missing a lot of knowledge on the programming side.
I'm not a 100% novice to programming, I just dont know C. I do Cisco programming (if you want to call it programming).
So my basic question is how can I get the bot to do 2 things at once. I want it to flash LED's and piezo beep when finding a wall and stopping. I can get it to find the wall, stop and beep OR/THEN flash, but not flash AND beep simultaneously.
I was playing around with the multicore functionality last night trying to have the LED's go to a core and the beeps to another core but for some reason I couldnt get the code to build. Is the multicore approach the best approach to have 2 things happen at the same time?
I'm not a 100% novice to programming, I just dont know C. I do Cisco programming (if you want to call it programming).
So my basic question is how can I get the bot to do 2 things at once. I want it to flash LED's and piezo beep when finding a wall and stopping. I can get it to find the wall, stop and beep OR/THEN flash, but not flash AND beep simultaneously.
I was playing around with the multicore functionality last night trying to have the LED's go to a core and the beeps to another core but for some reason I couldnt get the code to build. Is the multicore approach the best approach to have 2 things happen at the same time?
Comments
You could also have the Ping write to a global var that's monitored by 2 cogs. 1 cog could initiate the leds, and another cog could initiate the beep while both were reading that variable.
Hope this helps!
Addie
Q:...but for some reason I couldnt get the code to build. Show what you did and what you got. That way people can help.
Code is on my laptop at home. I'll paste it when I get back shortly.
Blank Simple Project.c
http://learn.parallax.com/propeller-c-tutorials
*/
#include "simpletools.h" // Include simple tools
#include "abdrive.h"
#include "ping.h"
int turn;
void leds();
int *cog1;
int main() // Main function
{
drive_setRampStep(10);
while(1)
{
drive_ramp(128, 128);
while(ping_cm(10) >= 20) pause(5);
drive_ramp(0, 0);
freqout(0, 200, 1000);
cog1 = cog_run(leds, 128);
turn = rand() % 2;
if (turn == 1)
drive_speed(64, -64);
else
drive_speed(-64, 64);
while(ping_cm(10) < 20);
}
}
void leds() // Blink function for other cog
{
for(int n = 1; n <= 15; n++)
{
high(8);
pause(100);
low(8);
pause(100);
high(9);
pause(100);
low(9);
pause(100);
}
cog_end(cog1);
}
2. I don't see, offhand, why what you have won't build. What are the error messages?
Here are the errors:
UltraBot.c:18:3: warning: implicit declaration of function 'cog_run' [-Wimplicit-function-declaration]
C:\Users\Chad\AppData\Local\Temp\ccE0j86H.o: In function `_main':
(.text+0x98): undefined reference to `_cog_run'
C:\Users\Chad\AppData\Local\Temp\ccE0j86H.o: In function `_main':
(.text+0xa5): undefined reference to `_cog_run'
collect2: ld returned 1 exit status
Done. Build Failed!
Check source for bad function call or global variable name `_cog_run'
C:\Users\Chad\AppData\Local\Temp\ccE0j86H.o: In function `_main':
(.text+0xa5):
For some reason it just does not like the cog_run or cog_end code. I brought up a new project to test cog_runs in a while loop and they work perfect. It's just this code thats having issues. I tried putting the int "cog_leds" under the "if (wall)" and it wont execute. I have an LED there now and that works fine.
One of the things I always disliked most about every "C" compiler I ever met is that the compiler error messages seem to be totally unrelated to the actual problem.
Ray
I've semi abandoned this project out of wasting too much time trying to troubleshoot stupid stuff haha. I've been having fun playing with multi-core functions in other projects.
Sometimes, after editing a project with problems multiple times I would get errors that made no sense. After checking for missing } or ; I would just highlight all the code in the SimpleIDE window, right click on it and click on copy, open a new instance of the IDE, click on new project, highlight all the code that new project enters, and copy the code from the clipboard over the highlighted code in the new project.
Once I do that the program either builds w/o errors or gives me an error that makes sense.
Tom
I'm thinking it was some sort of bug. It was acting like it couldnt understand the cog_run function. I was executing the same type of functions in another project just fine.