Program Help Needed

Hey guys. I have been working on a function for a while now and I cant seem to get it to work correctly. I am trying to get my protobot to drive at “half speed” when the ultrasonic up front reads a certain value or less. It seems like once it gets into the half speed function it wont leave that function. Anyone have any ideas as to what may be wrong? I have tried every possible combination of loops. This is just my latest attempt.

{
		while (SensorValue(ultrasonic) <= 10)
			{
				half_standard_drive();
			}
		while (SensorValue(ultrasonic) > 10)
			{
				standard_drive();
			}
	}

Hard to tell from that small piece of code, obviously the ultrasonic has to become > 10 before the standard drive is resumed so it really depends on what is happening in the half_standard_drive function and the whole context of what you posted. Any chance you just want to post (or PM) me the whole program?

One thing I generally forget is that The sonars sort of read backwards, in a way. Instead of the value increasing as you get closer to the obstacle, the value decreases (because it returns the distance between you and it, so that value would decrease as it becomes closer). Maybe this is the problem?

Otherwise, if you are actually trying to get it to reverse until 10, check that the function you have is making the motors spin in the right direction.

A better understanding on what you are trying to do would be super useful for us, like I personally am stumped on the second part of the code.

Another thought that just popped into my head, there isn’t a loop by any chance in the half_standard_drive() function is there?

~George

Sent you email

I got your email. I have not tried your solution yet but i see why my program is not working. I had 1 more question for you. Am I able to use “inline” functions in RobotC? when I out in inline it turns blue so it seems like it will take it but it gives me an error at compile time.

inline is not supported, the closest thing is to use a macro but you need to be careful. A couple of examples of macros here.

I dont understand why it highlights it but wont support it. I know that RobotC for Mindstorms is starting to support pointers which is nice.

I don’t know the answer, it may just be for compatibility with “standard” code or perhaps they had planned to support inline but did not finish implementation. ROBOTC for cortex supports pointers from version 3.50 onwards. Recursion is also now supported so if you have not upgraded I suggest getting the latest release (3.51 as of Oct 2012). I posted info on pointers and stacks in the programming tips thread also. See posts #119, #120 & #121. What specifically did you want to use inline for? We normally only use that when optimizing for speed but I doubt it would make much difference in ROBOTC due to the existing overhead of using byte code running on a VM.

I just wanted to try it out. we were doing inline in my C class last night and just wanted to try it out

Just wondering have you tried using an if loop instead of a while loop Devin?

Also, RobotC 3.54 was just released on 03-NOV-2012…

Download Page for ROBOTC for CORTEX.