Variables hanging?

Hey y’all,

If you search these forums frequently, you’ll notice my last post was about a kiwi drive system. We are adding a Frisbee shooter to the top of it (for those that must know, it will be an inline shooter(using 6 inch wheels(direct driven by a CIM and a Mini-CIM))). I created speed selector for it using the D-Pad (code shown below)

void Shooter::SpeedChanger(int dir){
	switch(dir){
	case 0:
		if (change == false){
			if (sped < 2){
				sped = sped + 1;
				printf("Speed up 
");
				change = true;
			}
		}
		break;
	case 180:
		if(change == false){
			if(sped > 0){
				sped = sped - 1;
				printf("Speed Down 
");
				change = true;
			}
		}

		break;
	default:
		printf("Nothing
");
		change = false;
		break;
	}
	printf("%d", sped);
	printf("
");

}

If I get crazy with button pressing, or just wait a while, the code will just hang. The only way to get it out of this hanging state, is to disable it, then re-enable it. I have a video of it when working. When it hangs, it will only stay on the one variable, that it last was on. The code for driving on the other hand, will not hang.

What might help is if you add printfs to every variable in the code segment and go through the logs. This helps track down the problem. If you could post them, other people would be able to help a lot more.

I can get an output of the riolog later, as I am currently at an FLL competition, there are printfs in the code.

John

Alright. I’l look through them when you post them.

This sounds like an excellent time to use a debugger. Get it stuck, then stick a breakpoint at the top of your SpeedChanger method and step through, looking at the variable values. This is the best way to see why the code is not doing what you think it should.

http://wpilib.screenstepslive.com/s/4485/m/13810/l/145321-debugging-a-robot-program

Jreneew2,
I cannot get to posting a riolog. Eclipse will crash if I try to enter the riolog, when it hangs. Everything but the Frisbee shooter will run when it hangs. I find it odd, I’ll limit my code to only the one subsystem, and try to see if that will work.

Moving it to only the one method in the subsystems seemed to work. I couldn’t do anything to get it to hang. I will try to implement everything else in a different way, but for now it seems to work.