Documentation:¶
This section shows a rich detailed documentation about every class and method of the code.
Bicycle¶
-
class
bicycle.Bicycle(L=1, alpha_max=90)¶ Implementation of the famous bibycle “model”
Inicialize the model, getting L = distance between the wheels and alpha_max = maximun steer angle
The distances must be ALLWAYS in meters
-
clear()¶ Clear the list of poses
-
getPose()¶ Return que actual pose of the model. The pose is in (x,y,theta) form
-
run(v, alpha)¶ Calculate the next pose of the model getting the speed (distance travaled in this step time) and the steer angle
-
setPose(x, y, theta)¶ Define a new pose to the model
-
show(legend='Path')¶ Plot the path of the model
-
sim_Path(v, alpha)¶ Simulate the path of the model using a list of speeds and angles, this lists should have the same length
-
sim_RandomPath(v, steps)¶ Simulate the model running with const speed (v in meters per step) and random steer angle for a number of steps
-
update(x, y, theta)¶ Change the pose of the model adding the parameters to the actual pose
-
Vehicle¶
-
class
vehicle.Vehicle(L=1, alpha_max=90)¶ The Vehicle is based on the Bicycle class, the diferece is the it has sensors em methods for odometry
-
Odometry(v, alpha)¶ Make the read of the sensors if the odometry is set
-
clear()¶ Clear both the poses of the model and the sensors reads
-
readOdometry()¶ Return the list of sensors reads of the encoder and the steer angles
-
readSensors(v, alpha)¶ Append to the list the reads of the sensors (encoder and steer angle measurement)
-
run(v, alpha)¶ Calculate the next pose of the model and read the sensors
-
setOdometry(state)¶ Turn on or off the odometry, the odometry reads the speed of the model and adds a gaussian noise to it, the standard deviantion of this noise must be set
-
setOdometryVariance(variance)¶ Set the valor of the standard deviantion of the odometry It must be a list of two values [encoder,steer]
-
Map¶
-
class
mapping.Map(file)¶ This class create a representation of the robot environmet receving an image of its map, the image is converted to a black and white image and then represented as a numpy array
-
getMap()¶ Return the numpy array thats represent the map
-
read(x, y)¶ Read the value of the pixel in the desired position
-
show()¶ Plot the image as a b&w plot
-
Line Camera¶
-
class
camera.Camera(H, cam_angle, L=60)¶ Simulate a line scan camera used to read the map
L is length of the camera image in pixels
-
findLine(pose, visualize=False)¶ Finds the center of a black line in the image read by the models pose and return the diference from it to the center of the camera in a range from -1 to 1
- If no line is found its return the last error
- Find de centroid of the black points in the image, this is the center of the line by definition, and compare with the center of the camera length
-
loadMap(map)¶ Load a Map object into the camera
-
readLine(pose, visualize=False)¶ Reads a line of the map based on the pose of the robot
-
Robot¶
-
class
robot.Robot(map_file, cam_length=128, L=0.2, alpha_max=20, pxlpermeter=370, H=0.2, cam_angle=30)¶ This class take all the previous classes and create a robot model, it can see the map over the camera and move based on it
To Inicialize a robot it is need:
- A image file thats represents the envoriment(map_file)
- A relation of pixels per meter to scale the image (pxlpermeter)
- The length of the camera in pixels (cam_length)
-
pidControl(Kp=2, Ki=0, Kd=0, v=1, debug=True)¶ Aplly the PID control to the model
-
run(v, value)¶ Sobrepose the run method applying the pixels per meter paramater to the speed and scalling the angle as a value from -1 to 1, because the camera reads return a error in this range
-
show(legend='Path')¶ Show the image of the map and the poses of the robot
-
sim_LineFollower(Kp=2, Ki=0, Kd=0, v=5, Steps=500, debug=False)¶ Simulate the robot autonomously running througth the map using a PID control system for a number of steps
Parameters:
- Kp = Proportional Gain.
- Ki = Integral Gain.
- Kd = Derivative Gain.
- v = speed in meters to step time.