Library for use with the RenBuggy with 2 wheels that travels for an amount of time specified by the user.
Dependencies: mbed
Dependents: RenBuggy_Timed_Programme RenBuggy_Figure_Of_Eight
Revision 0:a413eedb9896, committed 2014-03-31
- Comitter:
- Markatron
- Date:
- Mon Mar 31 10:18:38 2014 +0000
- Commit message:
- Created a library for use with the RenBuggy with 2 wheels that travels for an amount of time specified by the user.
Changed in this revision
diff -r 000000000000 -r a413eedb9896 RenBuggyTimed.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/RenBuggyTimed.cpp Mon Mar 31 10:18:38 2014 +0000 @@ -0,0 +1,70 @@ +/******************************************************************************* +* Used to drive RenBuggy with 2 wheels for a specified amount of time. * +* Copyright (c) 2014 Mark Jones * +* * +* 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. * +* * +* RenBuggyTimed.cpp * +* * +* V1.0 31/03/2014 Mark Jones * +*******************************************************************************/ + +#ifndef RENBUGGYTIMED_C +#define RENBUGGYTIMED_C + +#include "RenBuggyTimed.h" + +RenBuggy::RenBuggy(PinName leftMotor, PinName rightMotor, + PinName leftBrake, PinName rightBrake) : + m_motorL(leftMotor), m_motorR(rightMotor), + m_brakeL(leftBrake), m_brakeR(rightBrake) { + + +} + +RenBuggy::~RenBuggy() { +} + +void RenBuggy::forward(float time) { + + m_motorL = m_motorR = 1.0; + wait(time); +} + +void RenBuggy::left(float time) { + + m_motorL = 0.2; + m_motorR = 1.0; + wait(time); +} + +void RenBuggy::right(float time) { + + m_motorL = 1.0; + m_motorR = 0.2; + wait(time); +} + +void RenBuggy::stop() { + + m_motorL = m_motorR = 0; + m_brakeL = m_brakeR = 1.0; +} + +#endif // RENBUGGYTIMED_C \ No newline at end of file
diff -r 000000000000 -r a413eedb9896 RenBuggyTimed.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/RenBuggyTimed.h Mon Mar 31 10:18:38 2014 +0000 @@ -0,0 +1,100 @@ +/******************************************************************************* +* Used to drive RenBuggy with 2 wheels for a specified amount of time. * +* Copyright (c) 2014 Mark Jones * +* * +* 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. * +* * +* RenBuggyTimed.h * +* * +* V1.0 31/03/2014 Mark Jones * +*******************************************************************************/ + +#ifndef RENBUGGYTIMED_H +#define RENBUGGYTIMED_H + +#include "mbed.h" + +/** +* RenBuggyTimed example: +* @code + +#include "RenBuggyTimed.h" + +RenBuggy myBuggy(p5, p6, p8, p7); + +int main() { + + myBuggy.forward(4); + myBuggy.left(3); + myBuggy.forward(4); + myBuggy.right(3); + + return 0; +} +@endcode +*/ + +/** +* The class used to control a timed version +* of the RenBuggy with 2 wheels. +*/ +class RenBuggy { + + private: + PwmOut m_motorL; + PwmOut m_motorR; + + DigitalOut m_brakeL; + DigitalOut m_brakeR; + + public: + /** + * Constructs the class with the pins for the pwm outputs + * and the digital outputs, to move and stop. + */ + RenBuggy(PinName leftMotor, PinName rightMotor, + PinName leftBrake, PinName rightBrake); + /** + * Deconstructs the buggy. + */ + ~RenBuggy(); + + /** + * Moves the buggy forward for a specified amount of time. + */ + void forward(float time); + + /** + * Turns the buggy forward and left for a specified amount of time. + */ + void left(float time); + + /** + * Turns the buggy forward and right for a specified amount of time. + */ + void right(float time); + + /** + * Applies the brakes. + */ + void stop(); + +}; + +#endif // RENBUGGYTIMED_H \ No newline at end of file
diff -r 000000000000 -r a413eedb9896 mbed.bld --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Mon Mar 31 10:18:38 2014 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/7d30d6019079 \ No newline at end of file