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 ESC SR04 TSI
Revision 33:6b25a5721a20, committed 2013-06-09
- Comitter:
- gabdo
- Date:
- Sun Jun 09 18:06:04 2013 +0000
- Parent:
- 30:17297295ce0c
- Commit message:
- none
;
Changed in this revision
--- a/com/com.cpp Sun Jun 09 04:14:21 2013 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,106 +0,0 @@
-/****************************** com.cpp **********************************/
-/* Version: 1.0 */
-/* Last Updated: June 1, 2013 */
-/*************************************************************************/
-
-#include "mbed.h"
-#include "com.h"
-
-/*********************** com( PinName, PinName ) *************************/
-/* */
-/*************************************************************************/
-
-com::com( PinName tx, PinName rx ) : xbee( tx, rx)
-{
- bLength = 0;
- xbee.attach( this, &com::callback );
- readBuffer = new queue();
-}
-
-/************************* bool isData() ********************************/
-/* */
-/*************************************************************************/
-
-bool com::isData()
-{
- if( readBuffer->isEmpty() )
- return false;
-
- return true;
-}
-
-/************************ void write( char ) *****************************/
-/* */
-/*************************************************************************/
-
-void com::write( char value )
-{
-
-}
-
-/*************************** char read() ********************************/
-/* */
-/*************************************************************************/
-
-char * com::read()
-{
- // Are there commands in the readBuffer queue?
- if( !readBuffer->isEmpty())
- return readBuffer->pop();
-
- return NULL;
-}
-
-/********************** void eventHandler() ******************************/
-/* */
-/*************************************************************************/
-
-void com::callback()
-{
- while( xbee.readable() )
- {
- char data = xbee.getc();
-
- if( bLength++ < 15 )
- buffer[bLength] = data;
-
- if( data == 255 )
- packetBuilder();
- }
-}
-
-/********************** void eventHandler() ******************************/
-/* */
-/*************************************************************************/
-
-void com::packetBuilder()
-{
- // As long as there is data in the buffer, we need to read it.
- while( bLength > 0 )
- {
- // If the buffer has at least 3 chars and the 3rd one is 2555
- //then we have a complete string, we must read it.
- if( bLength > 2 && buffer[bLength] == 255 )
- {
- char * commandData = new char[2];
- commandData[1] = buffer[--bLength];
- commandData[0] = buffer[--bLength];
- readBuffer->add( commandData );
- --bLength;
- }
- // There must have been a read error, just flush the buffer.
- else
- bLength--;
- }
-}
-
-
-
-
-
-
-
-
-
-
-
--- a/com/com.h Sun Jun 09 04:14:21 2013 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,30 +0,0 @@
-/******************************* com.h ***********************************/
-/* Version: 1.0 */
-/* Last Updated: June 1, 2013 */
-/*************************************************************************/
-
-#ifndef COM_H
-#define COM_H
-
-#include "mbed.h"
-#include "queue.h"
-
-class com
-{
- public:
- com( PinName, PinName ); // Setup the com serial port. (tx, rx)
- bool isData(); // Is there data to be read?
- void write( char ); // Write to the port.
- char * read(); // Read from the queue.
-
- private:
- void callback(); // Handle the interrupts.
- void packetBuilder(); // Called by callback to place commandes into the queue.
-
- char buffer[50]; // Buffer for holding serial data.
- int bLength; // Location in the buffer to place next data.
- Serial xbee; // tx - DIN, rx - DOUT
- queue *readBuffer; // queue of commands ready to be read.
-};
-
-#endif
\ No newline at end of file
--- a/com/queue/queue.cpp Sun Jun 09 04:14:21 2013 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,130 +0,0 @@
-/*************************** queue.cpp ***************************************/
-/* */
-/* Authers: Oanh Tran, Ling Lei, Sihao Xie, Greg Abdo. */
-/* Date: February 23, 2013 */
-/* Version: 1.0 */
-/* */
-/* The queue is used to stack StructureItem in order with a FILO */
-/*arrangement. */
-/*****************************************************************************/
-
-#include "queue.h"
-
-/***************************** constructor ***********************************/
-/* Description: */
-/*****************************************************************************/
-
-queue::queue()
-{
- front = NULL; // Set front to NULL at the start.
-}
-
-/******************************* distructor **********************************/
-/* Description: */
-/*****************************************************************************/
-
-queue::~queue()
-{
- clear(); // Clear the entire queue.
-}
-
-/*****************************************************************************/
-/* Description: */
-/* Accepts: */
-/* Returns: */
-/*****************************************************************************/
-
-bool queue::isEmpty()
-{
- // Is the queue empty?
- if( front == NULL ) // Check the front pointer.
- return true; // Queue is empty, return true.
-
- return false; // There is atleast one item, not empty.
-}
-
-/*****************************************************************************/
-/* Description: */
-/* Accepts: */
-/* Returns: */
-/*****************************************************************************/
-
-void queue::clear()
-{
- // Is the list already empty?
- if( isEmpty() ) // Check for an empty list.
- return; // List is empty, don't need to do anything.
-
- queueNode * current = front; // Create node to help step through list.
- queueNode * placeHold = front; // Create node to keep place of delete.
-
- // As long as were not at the end, keep stepping to the next node.
- while( current != NULL)
- {
- placeHold = current->next; // Hold where we have to go.
- delete current; // Delete the node.
- current = placeHold; // Set current to the next node.
- }
-
- front = NULL; // Reset the front to NULL;
-}
-
-/*****************************************************************************/
-/* Description: */
-/* Accepts: */
-/* Returns: */
-/*****************************************************************************/
-
-void queue::add( char * item )
-{
- // Were we passed an invalid object somehow?
- if( item == NULL ) // Check for NULL
- return; // If so, return.
-
- queueNode * newNode = new queueNode( item ); // Create the new node.
-
- if( isEmpty() )
- front = newNode; // Set front to the new node.
-
- else
- {
- queueNode *temp = front;
- while( temp->next != NULL )
- temp = temp->next;
-
- temp->next = newNode;
- }
-}
-
-/*****************************************************************************/
-/* Description: */
-/* Accepts: */
-/* Returns: */
-/*****************************************************************************/
-
-char * queue::pop()
-{
- // Is the list already empty?
- if( isEmpty() ) // Check for an empty list.
- return NULL; // List is empty, don't need to do anything.
-
- char* placeHold = front->data;
- // Keep track of what were returning.
- delete front; // Delete the front node.
- front = front->next; // Set front to next object.
- return placeHold; // return the stuctureItem.
-}
-
-/*****************************************************************************/
-/* Description: */
-/* Accepts: */
-/* Returns: */
-/*****************************************************************************/
-
-char * queue::peek()
-{
- if( front != NULL )
- return front->data;
-
- return NULL;
-}
--- a/com/queue/queue.h Sun Jun 09 04:14:21 2013 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,49 +0,0 @@
-/**************************** queue.h ****************************************/
-/* */
-/* Authers: Greg Abdo. */
-/* Date: February 23, 2013 */
-/* Version: 1.0 */
-/* */
-/* The queue is used to stack StructureItem in order with a FILO arrangement.*/
-/*****************************************************************************/
-
-#ifndef QUEUE_H
-#define QUEUE_H
-
-#include "mbed.h"
-
-using namespace std;
-
-class queue
-{
-public:
- queue(); // Queue constructor
- ~queue(); // Queue destructor
-
- bool isEmpty(); // Check for an empty queue.
- void clear(); // Clears the entire queue.
- void add( char* ); // Push commandData into the queue.
- char* peek(); // Look at the last item in the queue.
- char* pop(); // Pop the top item off the queue.
- void printAll(); // Print the entire queue.
-
-private:
- struct queueNode // Node object for the queue.
- {
- queueNode( char* array )
- {
- data = array;
- next = NULL;
- }
-
- ~queueNode()
- {}
-
- char* data; // Pointer to the StructureItem object.
- queueNode * next; // Next node in the queue.
- };
-
- queueNode * front; // Root of the queue.
-};
-
-#endif
--- a/motor/motor.cpp Sun Jun 09 04:14:21 2013 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,74 +0,0 @@
-/****************************** motor.cpp ********************************/
-/* Version: 1.0 */
-/* Last Updated: June 1, 2013 */
-/* */
-/* The motor class is used for motor control using a PWM ECS. When a */
-/*a motor object is created you must pass the PWM pin as the only */
-/*argument. */
-/*************************************************************************/
-
-#include "motor.h"
-
-/************************** motor( PinName ) *****************************/
-/* The motor constructor takes the pin to be used as for PWM and sets it */
-/*to default safe valuse. */
-/*************************************************************************/
-
-motor::motor( PinName pin ) : _pwm(pin)
-{
- _pwm.period( 0.020 ); // Set the period to 20ms.
- setPulseMin( 0.001150 ); // Set default min pulse.
- setPulseMax( 0.002 ); // Set default max pulse.
- setSpeed( 0 ); // Set motor to stopped.
-}
-
-/************************** setSpeed( int ) ******************************/
-/* Set speed takes an int value between 0 and 100 and sets the speed of */
-/*the motor based on passed in percent value of speed. */
-/*************************************************************************/
-
-void motor::setSpeed( int value )
-{
- // Is the value to small?
- if( value < 0 ) // Yup, just set to 0.
- currentSpeed = 0;
-
- // Is the value to large?
- else if( value > 100 ) // Yup, just set to 100.
- currentSpeed = 100;
-
- // Value must be in the correct range.
- else
- currentSpeed = value; // Set the new value.
-
- // Calculate the value based on pulseMin, pulseMax and currentSpeed.
- pulse = ((pulseMax - pulseMin ) / 100 * currentSpeed ) + pulseMin;
- _pwm.pulsewidth( pulse ); // Write the pulse to the pin.
-}
-
-/************************** setPulseMin( float ) *************************/
-/* */
-/*************************************************************************/
-
-void motor::setPulseMin( float value )
-{
- pulseMin = value;
-}
-
-/************************** setPulseMax( float ) *************************/
-/* */
-/*************************************************************************/
-
-void motor::setPulseMax( float value )
-{
- pulseMax = value;
-}
-
-/*************************** float getPulse( ) ***************************/
-/* Get the current pulse value. */
-/*************************************************************************/
-
-float motor::getPulse( void )
-{
- return pulse;
-}
\ No newline at end of file
--- a/motor/motor.h Sun Jun 09 04:14:21 2013 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,41 +0,0 @@
-/******************************* motor.h *********************************/
-/* Version: 1.0 */
-/* Last Updated: June 1, 2013 */
-/* */
-/* The motor class is used for motor control using a PWM ECS. When a */
-/*a motor object is created you must pass the PWM pin as the only */
-/*argument. */
-/* */
-/* Wiring diagrams */
-/* _______ _______ */
-/* CW ----| | CCW ---\/ --| | */
-/* ----| Motor | ---/\---| Motor | */
-/* ----|_______| --/ \--|_______| */
-/* Straight through Switch wire 1 and 3 */
-/* */
-/*************************************************************************/
-
-
-#ifndef MOTOR_H
-#define MOTOR_H
-
-#include "mbed.h"
-
-class motor
-{
- public:
- motor( PinName ); // motor object constructor.
- void setSpeed( int ); // Set the speed for the motor 0-100
- void setPulseMin( float ); // Set smallest pulse.
- void setPulseMax( float ); // Set largest pulse.
- float getPulse( void );
-
- private:
- PwmOut _pwm; // Pin used for PWM.
- int currentSpeed; // Speed of the motor.
- float pulse;
- float pulseMin; // Shortest value for the pulse
- float pulseMax; // Largest value for the pulse..
-};
-
-#endif
\ No newline at end of file
