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 PID MMA8451Q
Revision 9:9e0d0ba5b6b1, committed 2013-06-09
- Comitter:
- gabdo
- Date:
- Sun Jun 09 23:56:44 2013 +0000
- Parent:
- 8:72791d8c36b7
- Child:
- 10:a80e854955dc
- Child:
- 13:af3be8c6aad7
- Commit message:
- Minor mods
Changed in this revision
--- a/quadCommand/quadCommand.cpp Sun Jun 09 23:36:31 2013 +0000
+++ b/quadCommand/quadCommand.cpp Sun Jun 09 23:56:44 2013 +0000
@@ -22,6 +22,10 @@
rxYaw = 0;
}
+/******************************* run() ***********************************/
+/* */
+/*************************************************************************/
+
void quadCommand::run()
{
while(1)
@@ -31,23 +35,31 @@
}
}
+/***************************** rxInput() *********************************/
+/* */
+/*************************************************************************/
+
void quadCommand::rxInput()
{
short * command = myCom->read();
if( command[0] == 1 ) // Throttle command.
- rxThrottle = command[1];
+ targetThrottle = command[1];
if( command[0] == 2 ) // Pitch command.
- rxPitch = command[1];
+ targetPitch = command[1];
if( command[0] == 3 ) // Roll command.
- rxRoll = command[1];
+ targetRoll = command[1];
if( command[0] == 4 ) // Yaw command.
- rxYaw = command[1];
+ targetYaw = command[1];
}
+/*************************** updateMotors() ******************************/
+/* */
+/*************************************************************************/
+
void quadCommand::updateMotors() {
myMotors[ 0 ]->setSpeed( rxThrottle + rxPitch - rxRoll - rxYaw); // Motor 1
myMotors[ 1 ]->setSpeed( rxThrottle + rxPitch + rxRoll + rxYaw); // Motor 2
--- a/quadCommand/quadCommand.h Sun Jun 09 23:36:31 2013 +0000
+++ b/quadCommand/quadCommand.h Sun Jun 09 23:56:44 2013 +0000
@@ -10,15 +10,23 @@
#include "com.h"
#include "sensors.h"
+// Motor constants.
const PinName MOTOR1 = PTD4; // Pin used for motor 1.
const PinName MOTOR2 = PTA12; // Pin used for motor 2.
const PinName MOTOR3 = PTA4; // Pin used for motor 3.
const PinName MOTOR4 = PTA5; // Pin used for motor 4.
+// Xbee constants.
const PinName TXPIN = PTD3; // Pin used for xbee TX.
const PinName RXPIN = PTD2; // Pin used for xbee RX.
-#define DEFAULT_WINDUP_GUARD 20.0f
+// Sensor constants.
+#define MMA8451_I2C_ADDRESS (0x1d<<1) // Address of I2C accelerometer.
+const PinName ACCSDA = PTE25; // Pin for accelerometer SDA line.
+const PinName ACCSCL = PTE24; // Pin for accelerometer SCL line.
+
+// PID constants.
+#define DEFAULT_WINDUP_GUARD 20.0f
class quadCommand
{
--- a/quadCommand/sensorS/sensors.cpp Sun Jun 09 23:36:31 2013 +0000
+++ b/quadCommand/sensorS/sensors.cpp Sun Jun 09 23:56:44 2013 +0000
@@ -4,17 +4,31 @@
#include "sensors.h"
+/***************************** sensors() *********************************/
+/* */
+/*************************************************************************/
+
sensors::sensors()
{
acc = new MMA8451Q( ACCSDA, ACCSCL, MMA8451_I2C_ADDRESS);
}
+/************************** getAbsoluteX() *******************************/
+/* Returns a float from -1 to 1 for the value off level in the x */
+/*directoin. 0 = level. */
+/*************************************************************************/
+
float sensors::getAbsoluteX()
{
- return (acc->getAccX();
+ return acc->getAccX();
}
+/************************** getAbsoluteY() *******************************/
+/* Returns a float from -1 to 1 for the value off level in the Y */
+/*directoin. 0 = level. */
+/*************************************************************************/
+
float sensors::getAbsoluteY()
{
- return (acc->getAccY();
+ return acc->getAccY();
}
\ No newline at end of file
--- a/quadCommand/sensorS/sensors.h Sun Jun 09 23:36:31 2013 +0000
+++ b/quadCommand/sensorS/sensors.h Sun Jun 09 23:56:44 2013 +0000
@@ -7,18 +7,14 @@
#ifndef SENSORS_H
#define SENSORS_H
-#define MMA8451_I2C_ADDRESS (0x1d<<1)
-const PinName ACCSDA = PTE25;
-const PinName ACCSCL = PTE24;
-
class sensors
{
public:
sensors();
- float getAbsoluteX();
- float getAbsoluteY();
+ float getAbsoluteX(); // Get the value off level in the X directoin.
+ float getAbsoluteY(); // Get the value off level in the Y directoin.
private:
- MMA8451Q *acc;
+ MMA8451Q *acc; // Pointer to the acceleromi
};
#endif
\ No newline at end of file
