Kristian Lauszus
/
BalancingRobotPS3
Code for my balancing robot, controlled with a PS3 controller via bluetooth
Revision 5:fc6c7a059759, committed 2012-03-04
- Comitter:
- Lauszus
- Date:
- Sun Mar 04 02:11:58 2012 +0000
- Parent:
- 4:0b4c320bc948
- Child:
- 6:defe36ce2346
- Commit message:
Changed in this revision
BalancingRobot.cpp | Show annotated file Show diff for this revision Revisions of this file |
BalancingRobot.h | Show annotated file Show diff for this revision Revisions of this file |
--- a/BalancingRobot.cpp Fri Mar 02 09:06:47 2012 +0000 +++ b/BalancingRobot.cpp Sun Mar 04 02:11:58 2012 +0000 @@ -87,7 +87,7 @@ if (loopCounter == 100) { loopCounter = 0; // Reset loop counter double analogVoltage = batteryVoltage.read()/1*3.3; // Convert to voltage - analogVoltage *= 6.6 // The analog pin is connected to a 56k-10k voltage divider + analogVoltage *= 6.6; // The analog pin is connected to a 56k-10k voltage divider xbee.printf("analogVoltage: %f - timer: %i\n",analogVoltage,t.read_ms()); if (analogVoltage < 7.92 && pitch > 60 && pitch < 120) // Set buzzer on, if voltage gets critical low buzzer = 1; // The mbed resets at aproximatly 1V
--- a/BalancingRobot.h Fri Mar 02 09:06:47 2012 +0000 +++ b/BalancingRobot.h Sun Mar 04 02:11:58 2012 +0000 @@ -45,9 +45,9 @@ double pitch; /* PID variables */ -double Kp = 11; -double Ki = 2; -double Kd = 12; +double Kp = 8; //11 - 7 +double Ki = 2; //2 +double Kd = 9; //12 double targetAngle = 90; double lastError; @@ -91,13 +91,13 @@ long lastWheelPosition; long wheelVelocity; long targetPosition; -int zoneA = 2000; -int zoneB = 1000; +int zoneA = 4000; // 2000 +int zoneB = 2000; // 1000 double positionScaleA = 250; // one resolution is 464 pulses double positionScaleB = 500; double positionScaleC = 1000; double velocityScaleMove = 40; -double velocityScaleStop = 40;//30 +double velocityScaleStop = 30;//30 - 40 - 60 void calibrateSensors(); void PID(double restAngle, double offset);