0

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.

partII

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:

partII

This is my understanding:

  1. Robot and Hare are placed in the same position 0
  2. Robot starts reversing, while hare travels forward at constant velocity (error is negative)
  3. Robot fires a sonar
  4. Sonar reading tells the distance is 30 (error is 0)
  5. Robot stops (error is 0)
  6. Hare travels constant distance during this adjustment
  7. Robot fires sonar (error is positive)
  8. Robot increases its speed to setVelocity(error)
  9. Hare travels constant distance during this adjustment
  10. Robot changes its speed based on "old" sonar reading, as during the speed change, hare will travel further
  11. Therefore, robot will always be at least a little bit too far from desired distance

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.

Question: I think in best case the robot will oscillate between 30 and 30+ distance, but how would you change the program to make it travel at constant 30cm distance? I also find it suspicious that k is 1 in part i, is that alright?

Jonas
  • 121,568
  • 97
  • 310
  • 388
LucasSeveryn
  • 5,984
  • 8
  • 38
  • 65

2 Answers2

2

With proportionate gain, the robot's forward velocity will be proportionate to its distance from the robot - 30 cm. When we reach a steady state, the robot will be matching the hare's forward velocity, at some distance such that (d - 30) * k == the hare's speed. I.e. at some constant distance > 30 cm.

As for how to modify the program, you might want to set the robot's speed not only proportionate to the error, but taking into account the rate of change of the error as well.

Recommended reading:

Alternatively you could probably hack it to remember the speed when the distance ceases changing, and use that as a new base speed, with regular proportionate gain to keep the distance constant, but using PD control would be more robust :-).

  • 2
    " As for how to modify the program, you might want to set the robot's speed not only proportionate to the error, but taking into account the rate of change of the error as well." This is it, basically. It will oscillate if you don't match your acceleration to the derivative of the distance to the hare. – tykel Apr 27 '13 at 17:11
  • 1
    would it not settle at some distance where you match its speed exactly? – Daniel Woffinden Apr 27 '13 at 18:29
  • Thanks for help! But I still don't know how to modify the program using only methods outlined in the question text. How can we measure rate of change of error without notion of time? Also, what do you think about my first answer? I find it suspicious that k=1. – LucasSeveryn Apr 27 '13 at 19:47
  • 1
    Where does it say you can only use those methods? Options: 1) assume each iteration of the loop is a constant time unit (risky) 2) assume you can use a sleep method, I don't think they'd object. As for k, it's probably important to have a k, which is the tuning constant, but as this is hypothetical it's actual value doesn't matter, so can just be 1. It doesn't change any results, merely how quickly they happen. – Daniel Woffinden Apr 27 '13 at 22:06
0

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)
}
LucasSeveryn
  • 5,984
  • 8
  • 38
  • 65