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)
while (SensorValue(ultrasonic) > 10)
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?
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.
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.