Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed wallbot_lineTrace
Revision 2:ac78fd710c2c, committed 2014-12-16
- Comitter:
- sig9867
- Date:
- Tue Dec 16 13:06:29 2014 +0000
- Parent:
- 1:56f8789e6779
- Commit message:
- Update and bug-fix
Changed in this revision
--- a/lineTrace.cpp Mon Dec 15 14:40:23 2014 +0000
+++ b/lineTrace.cpp Tue Dec 16 13:06:29 2014 +0000
@@ -8,8 +8,8 @@
//-------------------------------------------------------//
void LineTrace::Servo()
{
- const float Kp = 2.0;
- const float Kd = -0.7;
+ const float Kp = 3.0;
+ const float Kd = -2.0;
const int N = 10;
@@ -18,44 +18,18 @@
differential = current - integral;
if (!s.Available()) {
- L.Speed = 0.0;
- R.Speed = 0.0;
+ L.Move(0.0);
+ R.Move(0.0);
return;
}
float cv = Kp * current + Kd * differential;
- //////////////////////////
if (cv < 0.0) {
- R.Speed = 1.0;
- R.Move(FORWARD);
- }
- else {
- L.Speed = 1.0;
- L.Move(FORWARD);
- }
- ///////////////////////////
- if (cv < -2.0) {
- L.Speed = 1.0;
- L.Move(REVERSE);
- } else if (cv < -1.0) { // -2.0 ... -1.0
- L.Speed = 2.0 + cv;
- L.Move(REVERSE);
+ R.Move(1.0);
+ L.Move(1.0 + cv);
+ } else {
+ L.Move(1.0);
+ R.Move(1.0 - cv);
}
- else if (cv < 0.0) { // -1.0 ... 0.0
- L.Speed = 1.0 + cv;
- L.Move(FORWARD);
- }
- else if (cv < 1.0) { // 00 ... 1.0
- R.Speed = 1.0 - cv;
- R.Move(FORWARD);
- }
- else if (cv < 2.0) { // 1.0 ... 2.0
- R.Speed = 2.0 - cv;
- R.Move(REVERSE);
- }
- else {
- R.Speed = 1.0;
- R.Move(REVERSE);
- }
-}
+ }
\ No newline at end of file
--- a/motor.cpp Mon Dec 15 14:40:23 2014 +0000
+++ b/motor.cpp Tue Dec 16 13:06:29 2014 +0000
@@ -3,23 +3,24 @@
Motor::Motor(PinName pwm, PinName in1, PinName in2)
- : FIn1(in1), FIn2(in2), Speed(pwm)
+ : FIn1(in1), FIn2(in2), FSpeed(pwm)
{
+ FSpeed = 0.0;
}
-void Motor::Move(TDirection dir)
+void Motor::Move(float speed)
{
- if (dir == FORWARD) {
+ if (speed > 0) {
FIn1 = 1;
FIn2 = 0;
+ FSpeed = speed;
}
- else if (dir == REVERSE) {
+ else {
FIn1 = 0;
FIn2 = 1;
- }
- else {
- FIn1 = 1;
- FIn2 = 1;
+ FSpeed = -speed;
}
}
+
+
\ No newline at end of file
--- a/motor.h Mon Dec 15 14:40:23 2014 +0000
+++ b/motor.h Tue Dec 16 13:06:29 2014 +0000
@@ -7,10 +7,10 @@
class Motor {
DigitalOut FIn1, FIn2;
- public:
+ PwmOut FSpeed;
+public:
Motor(PinName pwm, PinName in1, PinName in2);
- PwmOut Speed;
- void Move(TDirection dir);
-};
+ void Move(float spd);
+};
#endif
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/wallbot_lineTrace.lib Tue Dec 16 13:06:29 2014 +0000 @@ -0,0 +1,1 @@ +http://developer.mbed.org/users/sig9867/code/wallbot_lineTrace/#56f8789e6779