3pi errors in AVR studio

Have you looked at how our sample code works?

I understand some of the functions in the program and then there is some that I need an explanation. Even with a basic C programming book, with out a complete explanation of how the code works I am at a stand still. I am still in the infancy stage of learning C and the 3pi has been a great tool for getting me started. Here is an example of the PID code:

int proportional = ((int)position) - 2000;

Why is the there double brackets for ((int)postion)?

These are the small details that needs explanation. So, my overall understanding of how the program works is okay but I can really use a tutor or mentor. So back to my original question, thats why I asked of how to restart the loop.

The outer set of parentheses are not actually necessary, since casting has a higher precedence than subtraction. However, they help you understand what is going on. In general, if you type a complicated expression, you should probably put parentheses in so that people know exactly what you mean.

Thanks, these are the small details that I need to grasp. At the end of the maze is there a function call to restart the loop?

I don’t think function calls can “restart loops” in C, so I don’t really know what you mean. Since the code for re-running the maze is in an infinite loop, it will run over and over, as long as you keep pressing the B button.

So, after the maze has been solve, just press the B button and the it will start over again? I tried this and the robot lost its position, what would cause this?

Did you put it back at the beginning before pressing B?

No, I did not put it back at the beginning. I would like to press the button, make turn around, and find the beginning of the maze? Is this possible?

Sure, it’s possible. Once you understand what the existing program is doing, it’s probably just going to take a very simple modification to make it do that, since the path is already stored in its memory.

Do you know which file that simple modification would be made in? Thanks.

The maze-solving logic is all in the appropriately-named maze-solve.c. Currently, there is one loop for solving the maze and then a loop within a loop for repeating the solution over and over. Do you understand how this part of the code works? Does it work for you?

Yes, all of the code works and my robot solves the maze and then finds the shortest path. I am still in the infancy stage with C programming and even though there is very good documented comments before the function calls or control logic which gives me a basic understanding, I do not have a trained eye to quiet understand all of the code and loops. Can you explain the loop within the loop?

Hello.

Based on statements such as:

I think you’re not understanding or directly facing how much you need to learn, and as a result, you’re looking for a shortcut that doesn’t exist. It’s kind of like trying to do a division problem without understanding addition, subtraction, or multiplication.

This is like asking for a more simple worked division problem. That’s not necessarily wrong if you understand the other, simpler operations, but if you can’t multiply yet, a simpler division problem is not really going to help.

This is kind of like starting with an example of 336/7=48 and then asking what digits to change to solve 336/8. If you know how to divide, it is simple to recalculate for another set of numbers; if you just get told to change the 48 to a 42, you still don’t know how to divide, and it won’t make sense to you until you know how to multiply.

Asking, “Can you explain the loop within the loop?”, as if that were a detail, is like asking about the remainder when you hear the answer to 336/9. The remainder is not your problem, just like this particular loop within a loop is not your problem. You need to learn the basic stuff first, which means going to simpler problems, and actually working them: writing simple programs yourself, from scratch, and building up, not skimming thousands of lines of other people’s code and expecting that all of that complexity can get reduced to an explanation of a few lines here or there.

The point of this post is not to discourage you from learning to program; rather, I want to give you a more realistic picture of what lies ahead of you. There are many books and web sites available to you, and given that others spent years studying and practicing, you shouldn’t expect others to explain that knowledge on a forum thread. If you have a specific question, like the one about the extra parentheses around the cast, that’s completely appropriate and easily answerable in a few sentences; if you want to change the behavior of sample code without understanding how it works, you’re unlikely to get a useful answer.

- Jan

Jan, thanks for the advice! This is not the place ask these types of questions.

My point is not just about this forum. In general, you need to do some simpler projects first, and we’re happy to help with that. If you don’t know how to multiply, you’re wasting your own time trying to divide instead of first learning the more basic operations.

- Jan

Hi, I began programming with my Pololu 328P robot, and I have problems when creating my own code. Everything is installed correctly, because it all runs fine if I use an example project. When I create my own projects(following the instructions on the Pololu USB AVR Programmer guide), everything goes well until I try to use a function in the library. A sample of what I want it to do is this:

#include<pololu/3pi.h>
int main(){
print(“Hello”);
}

When this runs, I get an unreferenced object on the print function. The code compiles fine, but I can not build it into the hex file required by the robot. Any suggestions on how to get the robot to function correctly?

Hello,

I think you may not have added the Pololu library to your project. Please take a look at Pololu AVR C/C++ Library User’s Guide section 7. Using the Pololu AVR Library for your own projects.

- Ryan

Hi,
I recently experienced a simlar symptom, when I opened fresh projects.

[ AVR Studio 4 v4.17, WinAVR-20090313, 3Pi w/368p ]

This may also be an AVR Studio 4 configuration, if you are using that IDE. Press the ‘Configuration’ button, or select it at the bottom of the ‘Project’ pulldown.

On the Project Options pop-up, choose “Libraries” at left. Make sure “libpololu_atmega328p.a” appears in the bottom right window. If it does not, select it at left and use ‘Add Library’ to add it.

UMMV, but that solved it for me.
Burt