More Proportional Control

Introduction

Now, instead of adjusting just one wheel, we can make a quicker correction by adjusting both motor speeds. We increase power to one motor, while simultaneously decreasing power to the other.

The basic formula is:

  • Determine how far off from our target we are.
  • Multiply that value by the Kp value
  • Add/subtract the new value to/from both motors, depending on whether the robot is too close/far from the wall.

Adjusting Both Wheels

Here we are now adjusting both wheel using the given formula.

Here is an excerpt from our code

void followWallBeta() {
  leftMotorSpeed=leftMotorDefaultSpeed;
  rightMotorSpeed=rightMotorDefaultSpeed;
  long error;
  while (digitalRead(LineSensor)==HIGH) {                 //this loop will end as soon as a black line is detected
    long pingTime = ping();
    if (pingTime!=0) {
      currentPingDistance = microsecondsToCentimeters(pingTime);   //distance 
      error = wallDistance-currentPingDistance;            //error
      rightMotorSpeed=rightMotorDefaultSpeed+(Kp*error);  //right motor correction
      leftMotorSpeed=leftMotorDefaultSpeed-(Kp*error);    //left motor correction; notice the - sign
    } if (pingTime==0) {
      rightMotorSpeed=0;                                  //this stops the right motor if the wall is lost (>~300cm)
    }                                                     //as a result, the robot will swing toward the wall, hopefully.
    Forward(0);
    if (useSave) saveData(useSave);
  }
  Stop();
  currentMenu = draw;                                     //returns to main menu
  
}


Results

Below are a collection of graphs and videos of a few trails that we did.

Note: In some cases, we removed the data after our robot lost the wall, so that all charts were the same scale, and to show it was performing before it lost the wall.

VID_20170214_190101.mp4
Kp value of 2 point 7.mp4
VID_20170214_185749.mp4
VID_20170214_174602.mp4

A closer look at the above data before it went off course

VID_20170214_190019.mp4
VID_20170214_185624.mp4

A closer look at before the robot went off course.

VID_20170214_185505.mp4

Video unavailable.

A closer look at the above data

After some further experiments, we decided on trying some lower Kp values. These values seemed to work better in a sense that they followed the wall for a greater amount of time. However, they tended to wander in a much wider range.

As the Kp value gets lower, the robot wanders more.

Conclusion

From above, we found that the robot performed best with a Kp value of about 3. This was expected; because both motors are now adjusting, the robot corrects twice as fast. Therefore, the Kp value should be about half of what it was from the one wheel experiment.