How does this project build on or extend previous projects:
The final project I did was building on and combining ‘Project 3 Hardware’ and the ‘follow me’ projects. During ‘Project 3 Hardware’ it was pretty simple to set up the code to have the ultrasonic sensors to output the distance from all three sensors.
Issues I had with implementing the code:
The main issue I had when trying to integrate the three ultrasonic sensors into the follow-me project, the code would stall or crash. I did catch that if the distance gets too close, then the sensors would bug out and output a different distance. For instance, the distance could be 10-15cm, but if any slight movement closer to the sensor, then the distance would output ~1500+cm.
// Define GPIO/wiringPi pins
#define TRIG 4
#define ECHO1 5
#define ECHO2 2
#define ECHO3 6
// get distance from ultrasonic sensors getCM() function
int distance1 = getCM(TRIG, ECHO1);
int distance2 = getCM(TRIG, ECHO2);
int distance3 = getCM(TRIG, ECHO3)
// Get closest distance among the three sensors
int ClosestDistance = findMinDist({distance1, distance2, distance3});
My control logic for the ultrasonic sensors:
if (ClosestDistance > setpoint + margin) {robot.drive(-velx, -vely, 0);}
else if (ClosestDistance < setpoint - margin) {robot.drive(velx, vely, 0);}
else {robot.drive(0, 0, 0);}
What this section of the code was supposed to do 'theoretically' was after finding the Closest Distance, it would go onto the control logic and adjust the robot's positions/movement based on the distance from the wall.
During working on this project, I had a lot of errors beginning with:
- not having enough space/memory to compile the code.
- Lidar data being put first or overpowering the ultrasonic sensors.
- wiringPi library and ultrasonic sensors crashing the code/system.