I am having issue with the “Forward Until Near” program. The link for the program is: ...
After I downloaded the program into the robot, the robot never start. I got a brand new super kit recently and all sensors and brains have been updated to the current firmware. And I double checked all ports and make sure I did not use wrong ports. I followed the curriculum and all programs for other sensors run pretty well. I suspect the distance sensor may be bad. But should the program at least run the first line, which will make robots start? In addition, I noticed that the command for the distance sensor is slightly different in the new released version of RobotC program. But since there is only one command to use for distance sensor, I cannot make it wrong. In the “setmultiplemotors” command, I also tried both -50 and 50 speed. Neither of them will let robot run. Can anyone offer me some possible solutions?
You can try few things to investigate your problem:
- On the brain, go to the Device Info screen, select the port the distance sensor is connected to and observe the values. What is the idle value, how does it change when you present an obstacle.
- In your program, you can add some waits to be able to observe the program actions. Like, wait 0.5s after the first line and wait(10s) at the end of the program.
Without the waits, you won’t see the robot running in case the distance sensor reads less than your threshold value all the time - start and stop would be too quick to even start moving. With a wait, the robot would at least have a chance to start moving before evaluating the distance for the first time. - Of course there is the debugger. Instead of waits, you can step through the program and see easily whether the motor started moving and whether the condition triggered too early.
I posted my program in the attached picture. By adding “wait 2 seconds”, the robot can run 2 seconds. After deleting this sentence, the robot never start. I also tried different values of distance, such as 500, 100, but it does not help.
When checking the device info, it seems like the distance sensor can detect the objects and shows “no object”, “485 mm”, “152mm” and so on. The detected distance values are generally correct.
Can anybody tell what is the problem?
Let me first clarify one thing: “After deleting this sentence, the robot never start.” - It actually does start. It starts the motors, evaluates the distance, likely passes the condition so moves to the next line, stops the motors and the program ends.
I suspect your distance sensor just sees something less than 500mm away, try reducing the limit to 50mm for the starters. You can also use the displaySensorValues function to see what the sensor actually reported in the curse of the program. I teach the kids to replace waitUntil(…) with repeatUntil(…) { displaySensorValue(…); } so they know what the robot thinks during the wait. In your case you may need to first print the initial value (before entering the loop, of which you may get zero iterations) on one line, then print the ongoing input on another line from inside the loop.
And don’t forget to add 10s+ wait at the end of the program so you’ll get time to read the values in case the program still marches through.
Something I noticed a long time ago (so a fair few firmware revisions ago) was that when the program first runs, for a few milliseconds the sensors can show an artificial value as they “initialise” but this happens just after the main program starts running. If the first command in your program is to evaluate the condition of a sensor straight away, it may get an incorrect reading. By adding a wait for 100 milliseconds at the start of the program, we overcame this.
I haven’t tested this on any recent firmware releases to see if it was different.