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: MODSERIAL PiSlingers m3pi mbed
Diff: IRBehaviorController.cpp
- Revision:
- 1:ac4eff391f12
- Parent:
- 0:9ac4a91b71fa
- Child:
- 2:b789f31e6d94
--- a/IRBehaviorController.cpp Wed Apr 04 17:07:49 2012 +0000
+++ b/IRBehaviorController.cpp Sat Apr 07 02:22:00 2012 +0000
@@ -1,99 +1,99 @@
-#include "mbed.h"
-
-#include "IRBehaviorController.h"
-
-
-// Public methods
-
-void
-IRBehaviorController::setActiveThreshold(float threshold)
-{
- NVIC_DisableIRQ(TIMER3_IRQn); // Disable Ticker IRQ for atomicity
- activationThreshold = threshold;
- NVIC_EnableIRQ(TIMER3_IRQn); // Enable Ticker IRQ
-}
-
-
-void
-IRBehaviorController::runSeeking(void)
-{
- if (debug != NULL)
- debug->printf("IRController: Seeking Task Start.\r\n");
-
- scanIR();
-
- if (brightness > activationThreshold)
- output = pid->run(centeroid);
- else
- output = 0;
-
- if (debug != NULL)
- debug->printf("IRController: Seeking Task Complete.\r\n");
-}
-
-void
-IRBehaviorController::runAvoidance(void)
-{
- if (debug != NULL)
- debug->printf("IRController: Avoidance Task Start.\r\n");
-
- scanIR();
-
- // Centeroid value needs to be split for avoidance mode.
- if (centeroid < 0)
- centeroid += 3;
- else
- centeroid -=3;
-
- if (brightness > activationThreshold)
- output = pid->run(centeroid);
- else
- output = 0;
-
- if (debug != NULL)
- debug->printf("IRController: Avoidance Task Complete.\r\n");
-}
-
-float
-IRBehaviorController::getPower(void)
-{
- float tmp;
-
- NVIC_DisableIRQ(TIMER3_IRQn); // Disable Ticker IRQ for atomicity
- tmp = output;
- NVIC_EnableIRQ(TIMER3_IRQn); // Enable Ticker IRQ
-
- return tmp;
-}
-
-void
-IRBehaviorController::dumpDebug(Serial *debug)
-{
- if (debug != NULL)
- {
- debug->printf("IRController: Centeroid = %3.2f\r\n", centeroid);
- debug->printf("IRController: Brightness = %3.2f\r\n", brightness);
- debug->printf("IRController: Power = %3.2f\r\n", output);
- }
-}
-
-// Private methods
-
-void
-IRBehaviorController::scanIR(void)
-{
- if (debug != NULL)
- debug->printf("IRController: Scanning IR.\r\n");
-
- ird.scan();
-
- centeroid = ird.get_centeroid();
- brightness = ird.get_weighted_avg_brightness();
-
- if (debug != NULL)
- {
- debug->printf("IRController: Scan complete.\r\n");
- debug->printf("IRController: Centeroid = %3.2f\r\n", centeroid);
- debug->printf("IRController: Brightness = %3.2f\r\n", brightness);
- }
+#include "mbed.h"
+
+#include "IRBehaviorController.h"
+
+
+// Public methods
+
+void
+IRBehaviorController::setActiveThreshold(float threshold)
+{
+ NVIC_DisableIRQ(TIMER3_IRQn); // Disable Ticker IRQ for atomicity
+ activationThreshold = threshold;
+ NVIC_EnableIRQ(TIMER3_IRQn); // Enable Ticker IRQ
+}
+
+
+void
+IRBehaviorController::runSeeking(void)
+{
+ if (debug != NULL)
+ debug->printf("IRController: Seeking Task Start.\r\n");
+
+ scanIR();
+
+ if (brightness > activationThreshold)
+ output = pid->run(centeroid);
+ else
+ output = 0;
+
+ if (debug != NULL)
+ debug->printf("IRController: Seeking Task Complete.\r\n");
+}
+
+void
+IRBehaviorController::runAvoidance(void)
+{
+ if (debug != NULL)
+ debug->printf("IRController: Avoidance Task Start.\r\n");
+
+ scanIR();
+
+ // Centeroid value needs to be split for avoidance mode.
+ if (centeroid < 0)
+ centeroid += 3;
+ else
+ centeroid -=3;
+
+ if (brightness > activationThreshold)
+ output = pid->run(centeroid);
+ else
+ output = 0;
+
+ if (debug != NULL)
+ debug->printf("IRController: Avoidance Task Complete.\r\n");
+}
+
+float
+IRBehaviorController::getPower(void)
+{
+ float tmp;
+
+ NVIC_DisableIRQ(TIMER3_IRQn); // Disable Ticker IRQ for atomicity
+ tmp = output;
+ NVIC_EnableIRQ(TIMER3_IRQn); // Enable Ticker IRQ
+
+ return tmp;
+}
+
+void
+IRBehaviorController::dumpDebug(Serial *debug)
+{
+ if (debug != NULL)
+ {
+ debug->printf("IRController: Centeroid = %3.2f\r\n", centeroid);
+ debug->printf("IRController: Brightness = %3.2f\r\n", brightness);
+ debug->printf("IRController: Power = %3.2f\r\n", output);
+ }
+}
+
+// Private methods
+
+void
+IRBehaviorController::scanIR(void)
+{
+ if (debug != NULL)
+ debug->printf("IRController: Scanning IR.\r\n");
+
+ ird.scan();
+
+ centeroid = ird.get_centeroid();
+ brightness = ird.get_weighted_avg_brightness();
+
+ if (debug != NULL)
+ {
+ debug->printf("IRController: Scan complete.\r\n");
+ debug->printf("IRController: Centeroid = %3.2f\r\n", centeroid);
+ debug->printf("IRController: Brightness = %3.2f\r\n", brightness);
+ }
}
\ No newline at end of file