car won't drive around the track

14 posts / 0 new
Last post
doug
car won't drive around the track

I have been having trouble getting the car to behave on the simulator. For example, I replaced Race.py with BetterLap.py and ran simulationFull but the car just wanders around and stops, as shown in the attached image. Apparently I must be doing something wrong, but I don't know what.
I am running SimulationFull.py on a RaspberryPi3 and am running the simulation.bat on a Windows7 64-bit Laptop. Any suggestions?
-Doug

Images: 
Arron Churchill
Arron Churchill's picture
No wall collision

I think the robot may have done what was programmed, but it drove through the wall :)

The simulator does not have any collision detection, allowing you to drive through walls and other robots. It has been left out as modelling what happens when a YetiBorg or MonsterBorg hits something is quite difficult and might not provide realistic results. In particular they often flip over!

I would first try the code with the AI robots turned off. Based on the path shown it looks like the code is trying to overtake the inside robot on the left, causing it to "hit" the wall.

It is worth bearing in mind that running too close to the inside of the track can make collisions with the wall more likely. Our examples like BetterLap.py are mostly for demonstration and may actually be worse than the standard Race.py example.

The reason the robot keeps spinning in the middle is that once past the wall all it can see from the camera feed is grey. The constant image trips the "I'm stuck" detection, which tries to reverse slightly and spin left or right to free itself from whatever it is stuck on. Since this does not reverse far enough to get back to the track it will just keep repeating itself.

doug
Car drives off track in simulator

Thanks, Arron. I wasn't aware of this switch on the Simulation UI. So now I have run it with the other cars off, this time with the original version of Race.py and the car seems to behave pretty well (for a while.) See screenshot. Sometimes it is able to complete more than one lap before driving off. But at some point, it just decides to turn the wrong way and drive off the track. Is this something that can be fixed?

Comment Images: 
Arron Churchill
Arron Churchill's picture
Script problem

That final bit looks rather strange, like the script got very confused in some way.

What does the output from the Python side say?
in particular:

  1. Any !!! BAD IMAGE !!! lines in the output?
  2. Any Failed to send motor values to simulation! lines in the output?
  3. What is the FPS value shown and does it seem to change when the robot goes wrong?
  4. Any other messages around when it goes strange?

I have attached what the output usually looks like for the Monster code around the start line for reference. The Grand Pi (YetiBorg) code is similar, but aims for 5 FPS instead of 30 FPS.

Comment Images: 
doug
Output from Python

I have been running the script from Idle. When the car crashes, the output goes by so fast that I can't read it. And CTRL+C doesn't make it stop. There is a user log saved, but no processing log.

Arron Churchill
Arron Churchill's picture
Dump from IDLE

Since you are using IDLE you can save the output to a file quite easily :)
From the Python Shell window select File > Save

I would save the output as a .txt file, you should then be able to attach it to a forum post.

doug
output from script

Looks like the connection to the simulator was lost...
"Simulation stream lost..."

Comment Attachments: 
Arron Churchill
Arron Churchill's picture
Connection lost

It does look that way, the result being the same as the CTRL+C issue (runs for 10 minutes anyway).

Are you running both halves of the simulation on the same computer or different computers?

doug
Connection lost

I've done it both ways: Simulation.bat always runs on Windows 7 64-bit laptop.
Python script either on Raspi or on same Windows laptop.

Arron Churchill
Arron Churchill's picture
Connection lost on same machine

That is really strange, the connection should never really be lost on the same machine.

In SimulationFull.py look for these two lines:

request = urllib2.urlopen(url, timeout=1)
...
request = urllib2.urlopen(imageUrl, timeout=1)

and increase the timeouts to 10:

request = urllib2.urlopen(url, timeout=10)
...
request = urllib2.urlopen(imageUrl, timeout=10)

If that fixes the problem then something is causing the simulator to briefly get "stuck" for a second or so. If it does not fix it something is going wrong with the connection between the two parts of the simulation code.

doug
new try with 10 sec timeout (different machines)

OK, I increased the timeout to 10 sec and ran the simulation again (python script running on second machine). Still crashed. Right away (in the first turn).

Comment Images: 
Comment Attachments: 
Arron Churchill
Arron Churchill's picture
CTRL+C does not terminate the script

I have had a quick look at why the script does not finish when you press CTRL+C. The culprit is in the Race.py script.

Basically the script will run for the full ten minutes regardless because of this line:

while time.time() < endTime:

As a side effect this causes a huge amount of output as it logs the constant calls to WaitForWaypoint which immediately return since the main code has stopped racing.

This can be fixed by adding a check to see if another part of the code has decided to stop running early:

while (time.time() < endTime) and Globals.running:

This will cause the code in Race.py to leave the loop and end normally as though the race was over.

doug
new try with 10 sec timeout (same machine)

Increased timeout to 10 sec and ran the python script and Simulation.bat on the same machine. Ran twice with no problems. Each run was set to last 5 minutes and completed 8 laps.
I wonder if the connection problems I was having when running the python script on the Raspi3 had anything to do with the new integrated wifi functionality on the Raspi3.
I might try using an older Raspi with a wifi dongle.

Arron Churchill
Arron Churchill's picture
WiFi connections

WiFi could explain drop-outs, especially if the connection is weak or noisy.

If you have an Ethernet cable you could try using a direct connection to the Raspberry Pi from your laptop. This guide should help if you want to try: https://pihw.wordpress.com/guides/direct-network-connection/

Add new comment

Filtered HTML

  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <blockquote> <code> <ul> <ol> <li> <dl> <dt> <dd> <pre>
  • Syntax highlight code surrounded by the <pre class="brush: lang">...</pre> tags, where lang is one of the following language brushes: bash, cpp, perl, python.
  • Lines and paragraphs break automatically.

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
Comment Images
Files must be less than 10 MB.
Allowed file types: png gif jpg jpeg.
Comment Attachments
Files must be less than 10 MB.
Allowed file types: txt pdf nfo doc docx rtf jpg png gif bmp zip tar gz csv xls.
CAPTCHA
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.