Library for the CustomExplorerRobot.
Dependents: CustomExplorerRobot_test
Revision 0:ad4667fc5a76, committed 2016-02-27
- Comitter:
- Usuke
- Date:
- Sat Feb 27 09:20:21 2016 +0000
- Child:
- 1:dce53bcd79a4
- Commit message:
- ??
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/BD6212/BD6212.cpp Sat Feb 27 09:20:21 2016 +0000
@@ -0,0 +1,36 @@
+#include "mbed.h"
+#include "BD6212.h"
+
+BD6212::BD6212(PinName fwd, PinName rev) : _fwd(fwd), _rev(rev){
+ _fwd.period_us(20);
+ _rev.period_us(20);
+ _fwd = 0.0f;
+ _rev = 0.0f;
+
+ bspeed = 0.0f;
+}
+
+void BD6212::speed(float speed){
+ _fwd.period_us(20);
+ _rev.period_us(20);
+ if(speed != bspeed){
+ if(speed > 0.0f){
+ _fwd = speed;
+ _rev = 0.0f;
+ }else if(speed < 0.0f){
+ _fwd = 0.0f;
+ _rev = -speed;
+ }else{
+ _fwd = 1.0f;
+ _rev = 1.0f;
+ }
+ bspeed = speed;
+ }
+}
+
+void BD6212::coast(void){
+ _fwd.period_us(20);
+ _rev.period_us(20);
+ _fwd = 0.0f;
+ _rev = 0.0f;
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/BD6212/BD6212.h Sat Feb 27 09:20:21 2016 +0000
@@ -0,0 +1,27 @@
+#ifndef MBED_BD6212_H
+#define MBED_BD6212_H
+
+#include "mbed.h"
+/** BD6212 control with direct PWM class
+ */
+class BD6212{
+ public:
+
+ BD6212(PinName fwd, PinName rev);
+
+ void speed(float speed);
+
+ void coast(void);
+
+ void operator= ( float value )
+ {
+ speed(value);
+ }
+
+ protected:
+ PwmOut _fwd;
+ PwmOut _rev;
+ float bspeed;
+};
+
+#endif
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/CustomExplorerRobot.cpp Sat Feb 27 09:20:21 2016 +0000
@@ -0,0 +1,68 @@
+/* mbed CustomExplorerRobot Library
+ *
+ * CustomExplorerRobot.h
+ *
+ * Copyright (c) 2016 ??????
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+#include "mbed.h"
+#include "CustomExplorerRobot.h"
+
+CustomExplorerRobot::CustomExplorerRobot() : _right(PC_7, PC_6), _left(PC_8, PC_9), _redled(PC_5), _blueled(PA_12), _buzzer(PA_11) {
+ _right = 0.0f;
+ _left = 0.0f;
+ _redled = 1.0f;
+ _blueled = 1.0f;
+ _buzzer = 0.0f;
+}
+
+void CustomExplorerRobot::left_motor(float speed){
+ _left = speed;
+}
+
+void CustomExplorerRobot::right_motor(float speed){
+ _right = speed;
+}
+
+void CustomExplorerRobot::forward(float speed){
+ _left = speed;
+ _right = speed;
+}
+
+void CustomExplorerRobot::backward(float speed){
+ _left = -speed;
+ _right = -speed;
+}
+
+void CustomExplorerRobot::left(float speed){
+ _left = -speed;
+ _right = speed;
+}
+
+void CustomExplorerRobot::right(float speed){
+ _left = speed;
+ _right = -speed;
+}
+
+void CustomExplorerRobot::stop(void){
+ _left = 0.0f;
+ _right = 0.0f;
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/CustomExplorerRobot.h Sat Feb 27 09:20:21 2016 +0000
@@ -0,0 +1,117 @@
+/* mbed CustomExplorerRobot Library
+ *
+ * CustomExplorerRobot.h
+ *
+ * Copyright (c) 2016 ??????
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+#ifndef CUSTOMEXPLORERROBOT_H
+#define CUSTOMEXPLORERROBOT_H
+
+#include "mbed.h"
+#include "BD6212.h"
+
+/** CustomExplorerRobot control class
+ *
+ * Example:
+ * @code
+ * // Drive the CustomExplorerRobot forward, turn left, back, turn right, at half speed for half a second
+
+#include "mbed.h"
+#include "CustomExplorerRobot.h"
+
+CustomExplorerRobot cer;
+
+int main() {
+
+ wait(0.5f);
+ cer.forward(0.5f);
+ wait(0.5f);
+ cer.left(0.5f);
+ wait(0.5f);
+ cer.backward(0.5f);
+ wait(0.5f);
+ cer.right(0.5f);
+ wait(0.5f);
+ cer.stop();
+
+ return 0;
+}
+ * @endcode
+ */
+class CustomExplorerRobot{
+ public:
+ /** Create the CustomExplorerRobot object connected to the default pins
+ */
+ CustomExplorerRobot();
+
+ /** Directly control the speed and direction of the left motor
+ *
+ * @param speed A normalised number -1.0 - 1.0 represents the full range.
+ */
+ void left_motor(float speed);
+
+ /** Directly control the speed and direction of the right motor
+ *
+ * @param speed A normalised number -1.0 - 1.0 represents the full range.
+ */
+ void right_motor(float speed);
+
+ /** Drive both motors forward as the same speed
+ *
+ * @param speed A normalised number 0 - 1.0 represents the full range.
+ */
+ void forward(float speed);
+
+ /** Drive both motors backward as the same speed
+ *
+ * @param speed A normalised number 0 - 1.0 represents the full range.
+ */
+ void backward(float speed);
+
+ /** Drive left motor backwards and right motor forwards at the same speed to turn on the spot
+ *
+ * @param speed A normalised number 0 - 1.0 represents the full range.
+ */
+ void left(float speed);
+
+ /** Drive left motor forward and right motor backwards at the same speed to turn on the spot
+ * @param speed A normalised number 0 - 1.0 represents the full range.
+ */
+ void right(float speed);
+
+ /** Stop both motors
+ *
+ */
+ void stop(void);
+
+ protected:
+ BD6212 _right;
+ BD6212 _left;
+
+ DigitalOut _redled;
+ DigitalOut _blueled;
+
+ PwmOut _buzzer;
+
+};
+
+#endif
Custom Explorer Robot