chapter 5 activity 3 'backward' function

In chapter 5 and the start of Activity 3, it introduces the 'backward' function. The problem is, is that no where before Activity 3 does it identify the ' backward' function. so when we go type it all in and are about to up-load it to your bot it doesn't work because it is undefined. Our question is, what do we do? Just skip it or is there a way to fix it?
(we are freshman in high school and don't know much, not even our teacher knows what to do)

nicbarry:
In chapter 5

Of what?

its in a book that we were assigned its called, "ROBOTICS with the BOE Shield-Bot for Arduino" its by: Andy Lindsay

I doubt that you can rely on anyone here having that. Obviously someone might have it, but just because it's about Arduino it doesn't follow that it would be well-known here.

You should approach the author maybe?

okay thank you, if you do somehow find out or if you can somehow ask around and let us know that would be great but thanks.

nicbarry:
if you can somehow ask around

Well i'm just a visitor here same as you, and apart from two ham radio friends and my daughter, I've never actually met an Arduinite, so nobody to ask around to, I'm afraid.

The one mentioned and downloadable from here? Robotics with the Board of Education Shield for Arduino | LEARN.PARALLAX.COM

"backward()" is talked about in chapter 4 under the "Put Maneuvers into functions", at least in the pdf...

Ok I see what the issue is. If you write the entire code out the function backward() is at the very end outside the main loop where functions exists.

this is what I'm referring to:

 void backward(int time) // Backward function
{
servoLeft.writeMicroseconds(1300); // Left wheel clockwise
servoRight.writeMicroseconds(1700); // Right wheel counterclockwise
delay(time); // Maneuver for time ms
}

It's not really backwards, it kind of reverses and turns.. lol

Please post your full sketch. If possible, you should always post code directly in the forum thread as text using code tags (</> button on the toolbar). This will make it easy for anyone to look at it, which will increase the likelihood of you getting help. If the sketch is longer than the forum will allow then it's OK to add it as an attachment. After clicking the "Reply" button, you will see an "Attachments and other settings" link.

pert:
If the sketch is longer than the forum will allow then it's OK to add it as an attachment.

But still preferably not - stripped down to the minimal sketch that still demonstrates the problem (something that is, by the way, very likely to help you find the problem by yourself in the first place).

If you write the entire code out the function backward() is at the very end outside the main loop where functions exists.

Yes. This is known as a "forward reference" and is allowed, or even encouraged (see "top-down program design") In most modern languages, you would have to "declare" the function before using it, but the Arduino IDE will generate those declarations for you automaticallly.

westfw:
the Arduino IDE will generate those declarations for you automaticallly.

Usually.
Not always.
I've ran into that twice now :frowning: Took me a long time to realise what's going on the first time! Manually doing a forward declaration for that one specific function (out of what must be dozens of functions in that code not counting included libraries) made it compile again.

Not always.

Yes. It also fails if the function arguments are complex types, because the declarations end up being inserted before the type definitions.

That was indeed a function that takes a custom struct type as one of its parameters. Or it returns that struct, I forgot. It's indeed related to such a complex type.

The confusing part was that for long time it compiled just fine, but later stopped compiling. I strongly suspect an "upgrade" of the IDE is responsible for that one, not sure as it's code that wasn't touched for a while.

There was a big change in the way prototype generation was done in Arduino IDE 1.6.6 that ended up causing a lot of prototype generation failures in that version and the few that came after. Eventually, they got the bugs worked out and it actually was a significant improvement over the system used in Arduino IDE 1.6.5 and earlier. There are still some cases where prototype generation fails. This turns out to be a very difficult thing to do correctly all the time. It's to the point now where when they fix one issue it may cause new ones. There was such a regression starting with Arduino IDE 1.8.6, which has been fixed but there has not been a production IDE release since then.

However, I would be extremely surprised if the simple code nicbarry is working with has this issue. We'll know for sure once we have the code.

It was I think the 1.6.something that worked; the 1.8.something broke. Using "setup" in a function name is also causing problems in seemingly unrelated parts of the code... and you don't need to have complex code to run into that one! Just having a function called setupSensors() or setupMotor() is enough.

OK guys here are the links...

Robotics PDF book - 11 MB

the entire code for the project at 158-159
Hopefully I copy pasted ok... it's not as easy using pdf.

It's pretty straightforward. I'm sure the issue is with functions. I've had similar issues before and had to incorporate the functions into the main loop. Annoying... and then other functions work fine... go figure.

// Robotics with the BOE Shield - RoamingWithWhiskers
// Go forward. Back up and turn if whiskers indicate BOE Shield-Bot bumped
// into something.
#include <Servo.h> // Include servo library
Servo servoLeft; // Declare left and right servos
Servo servoRight;
void setup() // Built-in initialization block
{
pinMode(7, INPUT); // Set right whisker pin to input
pinMode(5, INPUT); // Set left whisker pin to input
tone(4, 3000, 1000); // Play tone for 1 second
delay(1000); // Delay to finish tone
servoLeft.attach(13); // Attach left signal to pin 13
servoRight.attach(12); // Attach right signal to pin 12
}
void loop() // Main loop auto-repeats
{
byte wLeft = digitalRead(5); // Copy left result to wLeft
byte wRight = digitalRead(7); // Copy right result to wRight
if((wLeft == 0) && (wRight == 0)) // If both whiskers contact

{
backward(1000); // Back up 1 second
turnLeft(800); // Turn left about 120 degrees
}
else if(wLeft == 0) // If only left whisker contact
{
backward(1000); // Back up 1 second
turnRight(400); // Turn right about 60 degrees
}
else if(wRight == 0) // If only right whisker contact
{
backward(1000); // Back up 1 second
turnLeft(400); // Turn left about 60 degrees
}
else // Otherwise, no whisker contact
{
forward(20); // Forward 1/50 of a second
}
}
void forward(int time) // Forward function
{
servoLeft.writeMicroseconds(1700); // Left wheel counterclockwise
servoRight.writeMicroseconds(1300); // Right wheel clockwise
delay(time); // Maneuver for time ms
}
void turnLeft(int time) // Left turn function
{
servoLeft.writeMicroseconds(1300); // Left wheel clockwise
servoRight.writeMicroseconds(1300); // Right wheel clockwise
delay(time); // Maneuver for time ms
}
void turnRight(int time) // Right turn function
{
servoLeft.writeMicroseconds(1700); // Left wheel counterclockwise
servoRight.writeMicroseconds(1700); // Right wheel counterclockwise
delay(time); // Maneuver for time ms
}
void backward(int time) // Backward function
{
servoLeft.writeMicroseconds(1300); // Left wheel clockwise
servoRight.writeMicroseconds(1700); // Right wheel counterclockwise
delay(time); // Maneuver for time ms
}

wolframore:
the entire code for the project at 158-159
Hopefully I copy pasted ok... it's not as easy using pdf.

You can also just download all the sketches right here:

No need to do any copy/paste.

wolframore:
I'm sure the issue is with functions. I've had similar issues before and had to incorporate the functions into the main loop. Annoying... and then other functions work fine... go figure.

Did you compile the code? It works fine as is. But here's the problem: we have absolutely no guarantee that the code you just posted is the code that nicbarry is using (and, in fact, the evidence is to the contrary). Until nicbarry makes the effort to post their code as I requested, any further investigation is a waste of time.