Another C Question
ajward
Posts: 1,130
Hi All...
Working on some code for my Prop BoeBot and trying to use functions (probably not necessary for this small program, but hey). I'm getting an error, but I don't quite understand why.
This is the error message... test_bob (1).c:35:5: error: expected expression before 'while'. What "expression" is expected before while?
Scratching my head!
Amanda
Edit: There are some other issues, but I'll ask after I get this sorted out. :-)
Working on some code for my Prop BoeBot and trying to use functions (probably not necessary for this small program, but hey). I'm getting an error, but I don't quite understand why.
This is the error message... test_bob (1).c:35:5: error: expected expression before 'while'. What "expression" is expected before while?
Scratching my head!
Amanda
Edit: There are some other issues, but I'll ask after I get this sorted out. :-)
/* Test_Bob.c: From: Detect and Turn Project.c Modified from: http://learn.parallax.com/propeller-c-tutorials Amanda Ward - 30 Dec 2014 */ #include "simpletools.h" // Include simple tools #include "servodiffdrive.h" // Include servodiffdrive tools #include "servo.h" // Include servo Tools #include "ping.h" // Include ping tools void straight_on(void); // Call straight_on int main() // Main function { // Add startup code here. freqout(4, 1000, 3000); // (pin, duration, frequency) drive_pins(14, 15); // Define servo ports drive_setramp(10, 10); // Set servo ramping values drive_speeds(100, 100); // Set initial servo speeds servo_set(18, 1450); // Aim Ping forward straight_on(); drive_speeds(100, -100); // Rotate right pause(500); // Pause 0.5 seconds drive_sleep(); // Stop servos } void straight_on(void) [ while(ping_cm(19) >= 25) pause(15); // Continue till Ping range is less than 25cm drive_sleep(); // Stop Servos pause(1500); // Pause 1.5 seconds ]
Comments
AAUGH!!!!!! (My usual reaction to C.)
Thanks David!!! :-)
Other things to sort out, but this really helps.
Amanda
You might to comment those curly braces to make your code more readable.
-Tor
Good idea. I usually comment the dickens out out of my code, but this is the 5th or 6th iteration of this and I'm getting a little lazy! :-)
Amanda
Thanks Tor! That was just an "Oops" on my part. I've been tinkering with this section of the program, on and off, for two days and I just got a bit sloppy/lazy.
Actually, that bit might end up in another file (or not). I have several functions to accomplish various tasks for my BoeBot and they should reside in at least two cogs. Just trying to sort out how best to load everything into the BOE and get them to play well together.
Thanks again!
Amanda
Of course, I can always position the servo by hand, but at some point I want to have the drive and Ping servos working simultaneously.
Any advice will be appreciiated!
Amanda
pin#'s in your program to match my Activitybot. Using servo_angle I was not able to get it to work. So I tried servo_set(pin, 1500);
instead in "straight_on" and your code came to life.
Edit: Here is my modified code for my Activitybot.
You should put a pause between rotating the Ping servo and checking the Ping distance.
The servo needs time to move and it might already see something in the direction it's pointed.
While not necessary, putting the pause after that while statement and enclosing it in braces will make it easier to understand..
In addition it's good practice to document what a function does and what the inputs or outputs are.
I've sorted things out a bit. I had the drive servos starting before trying to center the Ping. Running in just one cog, this wasn't an ideal situation. I swapped the two statements so the Ping centers before the 'bot starts to roll. Right now the Ping overshoots the center position 2 or 3 times before coming to a stop, but I can live with that. It's just a few seconds delay and it makes him look just a tiny bit less machine like.
The goal is to have him wander around, constantly scanning from side to side for any obstacle within a predetermined distance. Then stop, find the direction that is the most open, turn that direction and race off again. Kind of like roaming with Ping and IR, but without the IR. I have all the standalone routines to accomplish this, but have yet to put them all together. ACK!
Time for sleep.
Amanda