A package allowing testing of line following code
Project description
Linesim
Line simulation made with pygame for testing a robot's pathfinding abilities.
Intended for testing pathfinding code for Purdue's ENGR 161 Project 3.
Features
- Multiple line sensor support
- Default track with curves, broken lines, and multiple paths.
Installation
Linesim is available on PyPI.
pip install linesim
Usage
First, import the LineSimulation
class.
from linesim import LineSimulation
Initialize the simulation and run sim.add_sensor(offset)
for each sensor to initialize, with positive x values as horizontal offset and positive y vales as vertical offset from the center of the robot.
Note: pygame defines the positive y direction as downwards.
sim = LineSimulation()
robot = sim.robot
sensors = [
sim.add_sensor((20, 10)),
sim.add_sensor((20, -10)),
sim.add_sensor((0, 0))
]
Now, create your loop. Use sim.running
to check if the simulation is still running, and run sim.update()
to update the game after every movement.
while sim.running:
if sensors[0].read_line():
robot.rotate(4) # Turn right
elif sensors[1].read_line():
robot.rotate(-4) # Turn left
else:
robot.move(4) # Go straight
sim.update()
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.