Sonar/IR raytracing WIP#29
Conversation
louiseadennis
left a comment
There was a problem hiding this comment.
I've had a go at running this and, as you mentioned in the issue discussion, it's pretty resource intensive. There is no need to be constantly updating the sonar - you can link it to calls to getDistance() used by the user/programmer. This is how the actual robots work as well so it makes sense in several ways.
| ymap = int(ray.y / self.sensor_map.resolution) | ||
| # Check if ray is out of bounds, it should bounce. | ||
| if xmap < 0 or xmap >= self.sensor_map.width or ymap < 0 or ymap >= self.sensor_map.height: | ||
| print(f"Ray {ray_num} (out of bounds) bounced at: ({x1},{y1})!") |
There was a problem hiding this comment.
Can we put some kind of if statement around this so it only prints when in debug or developer mode (or similar). It will be distracting for a child if they happen to be looking at the terminal to see this printed out.
| self.beams = beams | ||
| self.current_range = -1.0 | ||
|
|
||
| def update_sonar(self, x, y, theta): |
There was a problem hiding this comment.
Can we link this to the getDistance() method in the API for the two robots? That way it is only called when getDistance() is explicitly invoked by the user/programmer. This will make everything much more efficient and prevent other functions being held up because update_sonar is constantly executing.
There was a problem hiding this comment.
Just leaving a note to remind myself and inform others - that this doesn't work in the simulator. The getDistance method is on the "python program" with no direct link to the simulated robot. The robot's overall state on the python program side is updated by reading from a socket link that the simulated robot publishes to regularly. We would need to rework the entire communication pattern to have distance only calculated on request.
|
I did some performance analysis and it takes around 200-300ms to update the sensors. If I want to further improve the accuracy of the simulation, I want to get this delay down. I looked at the ray tracing library (https://pypi.org/project/raytracing/) which could allow me to do multithreading/utilize GPU acceleration but this is hardware specific. This library also has some nice integration with Matplotlib which will be really useful for debugging and showing the kids how the sonar blind spots occur. I also feel like the code should be refactored first (I could create a UML diagram for the new structure), but I'll make a draft using this new library in the near future when I finally have time! |
This is my ray tracing implementation for the sonar sensor. I have constructed a wave tracing model which simulated the movement of waves and the absorptive properties of waves: see
sonar.py,ray.pyandmaterial_constants.pyTo view this, just run
examples/SonarAvoider.pyand then runpysim.pyas normal.This solution mostly works but there is still stuff TODO:
np.random.normal()?)material_constants.pyare accurate (could do this experimentally in real life?)