I have put together a small program that:
Drives forward until:
a. it comes within a specified distance to an obstacle.
b. It strikes an “invisible” (not visible to the distance sensor), obstacle with its bumper.
If it comes within a specified distance to the obstacle, it:
a. If it is further away than “X” distance, it moves forward.
b. If it is closer than “Y” distance, it moves backward.
c. If it is between distance X and Y, it stops and stands still.
d. If the obstacle moves, either closer or further away, it reacts accordingly.
If it strikes something with its bumper, it:
a. Backs away for two seconds.
b. Calculates a random degree of rotation from 10 to 270 degrees
c. Calculates a random binary value, zero or one, which determines the direction of rotation, either left or right.
d. Executes the move in the desired direction for the desired angular degree of rotation.
e. Continues moving forward after the turn is completed.
The “calculates a random binary value” and “executes the move” are implemented as:
IsTrue_ = random.randint(0, 1) if IsTrue_: gpg.turn_degrees(-1*RotateDegrees, blocking=True) else: gpg.turn_degrees(1*RotateDegrees, blocking=True)
in Python, (cut and pasted from Bloxter). This little construction is probably the source of my problem.
The big issue is that no matter how I try to execute it, either in Jupyter Lab (as a page), in Python, (by cutting-and-pasting the python from Bloxter - and I’m probably doing it wrong), or in Bloxter itself, the program fails silently providing absolutely no help whatsoever to the errant programmer.
I have tried this in both Chrome and Firefox, on both my laptop and a tablet, and there is never any error returned. It simply starts, pauses for a brief moment, and stops. (i.e. the program (in Bloxter), goes into the “working” state for a second or two, then returns to the “stopped” state.)
The Musical Question(s) are:
- Why does this happen? (i.e. what is the actual error here?)
- (More important IMHO) - Why is there no error reported? Are programming errors supposed to be reported in Bloxter? I cannot even get one in cut-and-paste into “programming in Python”.
Distance_Random_Direction.py (2.1 KB)