Activity bot Sensors Question
GoBears
Posts: 4
Does anyone know if I can use more than one sensor on the activity bot at the same time? I am trying to use the whiskers as well as the ultrasound at the same time but they have conflicting pins. I moved the ultrasound to a new pin but I am unsure of how to specify that in the simple IDE code. All help is appreciated.
Comments
The Propeller in the ActivityBot can do up to 8 things at a time. It takes time for the Bot to get the distance info from the Ping and that slows down other processing done in the same cog (like deciding what to do). By moving the Ping timing to another cog, you may free up a lot of processing time to the cog running the main program.
forums.parallax.com/discussion/161769/activitybot-sirc-control-whiskers
Hope this helps,
Tom
So I'm using propeller C to program. Right now I'm just trying to get the bot to go down the hallway without hitting things. I looked at twm's code and figured out how to use different cores to run multiple functions at the same time.
When my bot sees an obstacle it turns way more than it should, sometimes all the way around, but I'm still tweaking the code as I go. Right now its a struggle trying to make sure the different functions running of each of the cores don't conflict with each other. Sometimes I also feel like the bot gets stuck in if loops and I don't know why. I wish there was an easier way to debug in propeller C. I'm still going to keep messing with it as I go. I've posted my code below. Any further help would also be appreciated. Thanks again!
/*
Roam W/ Ultrasound & IR
*/
#include "simpletools.h" // Include simple tools
#include "abdrive.h"
#include "ping.h" // Include ping header
void ultrasound();
void infrared();
int flag;
int main() // Main function
{
flag = 0;
cog_run(ultrasound, 128);
cog_run(infrared, 128);
}
void ultrasound() {
int turn; // Navigation variable
while (1) {
drive_speed(100, 100); // Forward
// While disatance greater than or equal
// to 10 cm, wait 5 ms & recheck.
while (ping_cm(8) >= 10) pause(5); // Wait until object in range
if (flag == 0)
drive_speed(0, 0); // Then stop
if (flag == 0)
drive_speed(0, 0); // Then stop
// Turn in a random direction
turn = rand() % 2; // Random val, odd = 1, even = 0
if (turn == 1) // If turn is odd
drive_speed(64, -64); // rotate right
else // else (if turn is even)
drive_speed(-64, 64); // rotate left
// Keep turning while object is in view
while (ping_cm(8) < 10); // Turn till object leaves view
if (flag == 0)
drive_speed(0, 0); // Stop & let program end
}
}
void infrared() {
int irLeft, irRight; // IR variables
low(26); // D/A0 & D/A1 to 0 V
low(27);
while (1) {
freqout(11, 1, 38000); // Check left & right objects
irLeft = input(10);
freqout(1, 1, 38000);
irRight = input(2);
if (irRight == 0) // Just right obstacle?
{
flag = 1;
drive_speed(-50, 50); // ...rotate left
} else if (irLeft == 0) // Just left obstacle?
{
flag = 1;
drive_speed(50, -50); // ...rotate right
}
flag = 0;
}
}
Tom
/*
Roam W/ Ultrasound & IR
*/
#include "simpletools.h" // Include simple tools
#include "abdrive.h"
#include "ping.h" // Include ping header
void ultrasound();
void infrared();
int flag; // 0 = ultrasound controlling, 1 = IR controlling
int main() // Main function
{
flag = 0;
cog_run(ultrasound, 128);
cog_run(infrared, 128);
}
void ultrasound() {
int turn; // Navigation variable
while (1) {
drive_speed(100, 100); // Forward
// While disatance greater than or equal
// to 10 cm, wait 5 ms & recheck.
while (ping_cm(8) >= 10) pause(5); // Wait until object in range
// *************** why is flag == 0 and stopping done 2x’s?
if (flag == 0)
drive_speed(0, 0); // Then stop
if (flag == 0)
drive_speed(0, 0); // Then stop
// Turn in a random direction
turn = rand() % 2; // Random val, odd = 1, even = 0
if (turn == 1) // If turn is odd
drive_speed(64, -64); // rotate right
else // else (if turn is even)
drive_speed(-64, 64); // rotate left
/* I suggest that you set a new flag = 1 when doing this rotation
So that if flag == 1 from the ir cog you can still stop the rotation
*/
// Keep turning while object is in view
while (ping_cm(8) < 10); // Turn till object leaves view
if (flag == 0) // change this to the new flag
drive_speed(0, 0); // Stop & let program end
}
}
void infrared() {
int irLeft, irRight; // IR variables
low(26); // D/A0 & D/A1 to 0 V
low(27);
while (1) {
freqout(11, 1, 38000); // Check left & right objects
irLeft = input(10);
freqout(1, 1, 38000);
irRight = input(2);
if (irRight == 0) // Just right obstacle?
{
flag = 1;
drive_speed(-50, 50); // ...rotate left
} else if (irLeft == 0) // Just left obstacle?
{
flag = 1;
drive_speed(50, -50); // ...rotate right
}
flag = 0;
/* I’m not sure how you are stopping the rotation.
Maybe ultrasound cog stops it? I recommend that you complete
the movement command in the cog that starts it. Then set or reset the flag that passes control to the other cog. That way you can limit or eliminate
undesired cog interactions.
Also, use pause() after you start a rotation to control the number of degrees rotated. Then take a new reading and rotate again. It is probably better to stop the rotation & then take the reading so you don't have to be concerned with the timing of the reading affecting the amount of rotation. If you were programming in PASM you can arrange the program to synchronize the actions taken by the cogs. But in C you can't tell how long it takes to execute each command so one cog may execute its main loop many times while the other is plodding along. So you should rely on your program controlling when things happen.
You may want to use smaller drive speed commands to slow things down.
Once you get the program working, then you can try speeding things up.
*/
}
}