Log in

View Full Version : Odd counter problems


Catastrophy
16-02-2004, 13:23
Ok well, I'm trying to run through a loop where it does

armcounter++;

Armcounter is defined at the top of user_routines_fast.c. I try a print_f to print out armcounter but it gives [null] on the ifi_loader. My motors just keep running for ever because it doesn't ever have armcount equal to the number I supply. Any clues????? :confused::ahh:

Joe Ross
16-02-2004, 13:25
you need to declare armcounter as a static int. Otherwise, it gets created and destroyed on the stack each time you enter and leave the function.

Ryan M.
16-02-2004, 13:28
Ok well, I'm trying to run through a loop where it does

armcounter++;

Armcounter is defined at the top of user_routines_fast.c. I try a print_f to print out armcounter but it gives [null] on the ifi_loader. My motors just keep running for ever because it doesn't ever have armcount equal to the number I supply. Any clues????? :confused::ahh:You'd have to show me how you have the printf setup, but you probably got it wrong. This should be similar to what your printf should be:

printf("\nArm counter: %i\n", (int)armcounter);

Ryan M.
16-02-2004, 13:29
you need to declare armcounter as a static int. Otherwise, it gets created and destroyed on the stack each time you enter and leave the function.He says at the top of user_routines_fast.c. I assume that means he made it a global.

PS What type is armcounter?

Catastrophy
16-02-2004, 13:56
its a short.

Ryan M.
16-02-2004, 14:02
its a short.Try the printf I showed earlier. It should work. Just copy and paste it over your old one.

Catastrophy
16-02-2004, 14:28
ok I did and now theres nothing there, its not printing anything.

Ryan M.
16-02-2004, 14:33
ok I did and now theres nothing there, its not printing anything.Hum, well, try just using the following line. It's guarranteed to print and if it doesn't, it means that it is never getting called and you'll have to look at your code.


printf("Test");



--EDIT--
If it doesn't work then post your code and people can look at it.

Catastrophy
16-02-2004, 14:44
It printed test but here it is. I'm using a basic auto right now so i can debug everything first.

Ryan M.
16-02-2004, 14:54
It printed test but here it is. I'm using a basic auto right now so i can debug everything first.What exactly is the output say? Does the 'arm value of armcounter' print anything? What does it print?

--EDIT--
Try changing the %i in the printf to %d.

rbayer
16-02-2004, 14:57
A few things I saw after glancing at it:

if (armcounter = 15) //will raise arm.
pwm06=0;
else
armcounter++;
pwm06=255;

sould be

if (armcounter == 15) //will raise arm.
pwm06=0;
else {
armcounter++;
pwm06=255;
}


It is VERY rare that you'll actually want to use a single = in an if, so watch out for that, and also be careful with your curly braces.

That said, I believe the code in its original form should have printf'd 15 over and over and over. Was it doing that, or just not printing anything?

Ryan M.
16-02-2004, 15:03
A few things I saw after glancing at it:

if (armcounter = 15) //will raise arm.
pwm06=0;
else
armcounter++;
pwm06=255;

sould be

if (armcounter == 15) //will raise arm.
pwm06=0;
else {
armcounter++;
pwm06=255;
}


It is VERY rare that you'll actually want to use a single = in an if, so watch out for that, and also be careful with your curly braces.

That said, I believe the code in its original form should have printf'd 15 over and over and over. Was it doing that, or just not printing anything?
Missing a = is an easy thing to do. It's one of those powerful, useful things that C/C++ lets you do, but isn't what you want most of the time. :)

Catastrophy
16-02-2004, 15:08
Well the = was something i accidently did when moving it i had it in the code i was using. and btw its just not printing anything.

Ryan M.
16-02-2004, 15:09
Well the = was something i accidently did when moving it i had it in the code i was using. and btw its just not printing anything.So, the "test" prints, but the other thing doesn't?

steven114
16-02-2004, 15:09
Hum, well, try just using the following line. It's guarranteed to print and if it doesn't, it means that it is never getting called and you'll have to look at your code.


printf("Test");



--EDIT--
If it doesn't work then post your code and people can look at it.

Try
printf("Test\n");
instead. If it works anything like printf on any other system, it won't flush the buffer until it gets a newline...

Ryan M.
16-02-2004, 15:12
Try
printf("Test\n");
instead. If it works anything like printf on any other system, it won't flush the buffer until it gets a newline...Yeah, that is true, but it did print for him. The wierd thing is, at least from what he has said, the line that is right below it doesn't say print anything, even though it should. :confused:

Catastrophy
16-02-2004, 15:23
Well for the variable, it print Arm and then nothing after it.

Ryan M.
16-02-2004, 15:24
Could you paste the output from the code here?

Ryan M.
16-02-2004, 15:26
Well, I can't figure it out. It should work. Any suggestions, The Lucas?

--EDIT--
I know you're watching. :)

Ryan M.
16-02-2004, 15:32
Obviously not. Try:

printf("Arm: %d", armcounter);


--EDIT--
If that doesn't work, I don't know what to do. Sorry. :(

Catastrophy
16-02-2004, 15:33
Here is a screenshot.

Ryan M.
16-02-2004, 15:34
I edited my last post. Take a look at it. Sorry I can't be of any more help. :(

--EDIT--
Someone else will come along and figure it out I'm sure. :)

Catastrophy
16-02-2004, 15:38
Ok now nothing is being printed Texan from what you said to put in.

-EDIT-
its saying TestAmr, 15TestArm, 15TestArm over and over now

Ryan M.
16-02-2004, 15:40
Ok now nothing is being printed Texan from what you said to put in.I don't know what is going on. Try resetting the RC. Sorry, got to go. Hope you figure it out. :confused:

Catastrophy
16-02-2004, 15:45
Well its counting now.

Joe Ross
16-02-2004, 15:50
Try changing the %i in the printf to %d.

Remeber that IFI implemented printf and that it isn't a "standard" implementation. Only the %s, %lx, %d, %x, %u, %X directives are parsed.

Catastrophy, is your problem fixed now that it is counting, or do you have more problems?

Ryan M.
16-02-2004, 15:58
Remeber that IFI implemented printf and that it isn't a "standard" implementation. Only the %s, %lx, %d, %x, %u, %X directives are parsed.

Catastrophy, is your problem fixed now that it is counting, or do you have more problems?Oh, didn't know those limitations. Thanks

Catastrophy
16-02-2004, 16:14
well the motors still arnt stopping.

Joe Ross
16-02-2004, 16:40
well the motors still arnt stopping.

Please post the code that you are using currently.

If you are using the corrections that Rob posted, pwm06 will go forward for about 1/3 a second and then go in reverse forever. You also have a similar behavior for pwm07 (assuming you corrected the errors)

deltacoder1020
16-02-2004, 17:10
A few things I saw after glancing at it:

if (armcounter = 15) //will raise arm.
pwm06=0;
else
armcounter++;
pwm06=255;

sould be

if (armcounter == 15) //will raise arm.
pwm06=0;
else {
armcounter++;
pwm06=255;
}


It is VERY rare that you'll actually want to use a single = in an if, so watch out for that, and also be careful with your curly braces.

That said, I believe the code in its original form should have printf'd 15 over and over and over. Was it doing that, or just not printing anything?

remember that you need to add the curly braces, not just change the equals sign to a double-equals. w/o the braces, the code is equivalent to this:


if (armcounter == 15) //will raise arm.
pwm06=0;
else {
armcounter++;
}

pwm06=255;


note how pwm06 will always end up as 255, no matter what the value is.

you said that the "motors weren't stopping" - of course they aren't: 0 is full reverse, 255 is full forward. if you want a motor to stop, set the PWM to 127.

Catastrophy
16-02-2004, 23:41
Well i got it working i was messign with the code when i posted it so i accidently left stuff out. Thanks Tex helped a lot.