I'm going through Robotics past papers as a revision before the exam, and I found one problem which seems very confusing. My department does not provide answers to past papers, so I can't check if I'm right.
public class Question4i{
public static main(){
float d = 30;
float k = 1; //If it's equal to 1, why do we need it at all?
while(true){
error= GetSonarDepth() - d;
if(error>100) error=100;
setVelocity(k * error)
}
}
}
Then second part is where things are getting interesting:
This is my understanding:
Also I came to a conclusion that if hare speed is higher than that of robot, distance will be constantly increasing. There will be NO STEADY STATE - where steady refers to kept distance.
With the standard control rule, the robot will always be a bit too far from the hare at steady state --- because it if was 30cm away it would set its speed to zero and the hare would get further away, so in the end it will settle down at a distance a bit more than 30cm.
The solution is to introduce a variable for speed; in the main loop, on every iteration set the robot speed to the variable value. Then look at the difference between the current distance to the hare and 30cm, and make an adjustment to the speed which is proportional to that difference. This will in the end bring a steady state where the robot matches its speed to the hare at a fixed distance of 30cm.
public class Question4ii{
public static main(){
float d = 30;
float speed = 0;
float k = 1; //If it's equal to 1, why do we need it at all?
while(true){
change = k * (GetSonarDepth() - d);
speed += change
if(speed>100) speed=100;
if(speed<-100) speed=-100;
setVelocity(speed)
}