Skip to content

Commit

Permalink
New file: imu-interface.cpp/.h. It's still empty... Also, added an es…
Browse files Browse the repository at this point in the history
…c_init function and moved some lines from main.cpp to there. cmd_servo_sweep allows you to control the throttle of the rotors with j and k (down/up) and z zero's the rate
  • Loading branch information
0xjairo committed Dec 31, 2011
1 parent c359975 commit 9f335a8
Show file tree
Hide file tree
Showing 7 changed files with 109 additions and 25 deletions.
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ PRODUCT_ID := 0003
SRCS= main.cpp \
utils.cpp \
esc-control.cpp \
ppm-decode.cpp
ppm-decode.cpp \
imu-interface.cpp

INCLUDES=${SRCS:.cpp=.h}
OBJS=$(addprefix $(APP_OBJ_PATH)/, $(SRCS:.cpp=.o))
Expand Down
53 changes: 45 additions & 8 deletions esc-control.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,21 @@ const char* dummy_data = ("qwertyuiopasdfghjklzxcvbnmmmmmm,./1234567890-="
"qwertyuiopasdfghjklzxcvbnm,./1234567890");


HardwareTimer timer1(1);

void esc_init()
{
// Setup timer1 for PWM
timer1.setMode(TIMER_CH1, TIMER_PWM);
timer1.setPrescaleFactor(21);

// Set throttle to minimum
for(int i=0;i<3;i++)
{
set_rotor_throttle(i+1, 0);
}

}

void ppm_decode(void){
SerialUSB.println("Decoding DIY Drones PPM encoder on pin D27");
Expand Down Expand Up @@ -120,7 +135,7 @@ void set_rotor_throttle(int rotor, float rate)
// 2.00ms = 6800counts = 100% (180deg)
int duty = SERVO_MIN + (float)(SERVO_MAX-SERVO_MIN)*rate;

#ifdef DEBUG
#ifdef COPTER_DEBUG
SerialUSB.print("Rotor:D");
SerialUSB.print(pin);
SerialUSB.print("\tRate:");
Expand All @@ -134,27 +149,49 @@ void set_rotor_throttle(int rotor, float rate)
}

void cmd_servo_sweep(void) {
SerialUSB.println("Testing D15 and D16 PWM header with a servo sweep. "
SerialUSB.println("Testing rotors. Sweeping from 0 to 50%"
"Press any key to stop.");
SerialUSB.println();

disable_usarts();

uint8 input;
float rate1 = 0;
float rate2 = 0;
while (!SerialUSB.available()) {
rate1 += 0.0005;
rate2 += 0.001;
if (rate1 > 1.0) rate1 = 0.0;
if (rate2 > 1.0) rate2 = 0.0;
while (1) {

input = SerialUSB.read();
if (input == 'j')
{
rate1 -= 0.01;
}
else if(input == 'k')
{
rate1 += 0.01;
}
else if(input == 'z')
{
rate1 = 0;

}else{
break;
}


if (rate1 > 1.0) rate1 = 1.0;

SerialUSB.println(rate1);

set_rotor_throttle(1, rate1);
set_rotor_throttle(2, rate2);
set_rotor_throttle(2, rate1);
set_rotor_throttle(3, rate1);
delay(20);
}

set_rotor_throttle(1, 0.0);
set_rotor_throttle(2, 0.0);
set_rotor_throttle(3, 0.0);



// for (uint32 i = 0; i < BOARD_NR_PWM_PINS; i++) {
Expand Down
2 changes: 1 addition & 1 deletion esc-control.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "wirish.h"

// Commands
void esc_init();
void cmd_servo_sweep(void);
void ppm_decode(void);
void set_servo_angle(float angle);
Expand Down
20 changes: 20 additions & 0 deletions imu-interface.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* imu-interface.cpp
*
* Created on: Dec 30, 2011
* Author: jairo
*/
#include "wirish.h"
#include "imu-interface.h"


void imu_print_data()
{
while(!SerialUSB.available())
{
SerialUSB.print(Serial3.read());
SerialUSB.print(":");
delay(20);

}
}
14 changes: 14 additions & 0 deletions imu-interface.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/*
* imu-interface.h
*
* Created on: Dec 30, 2011
* Author: jairo
*/

#ifndef IMU_INTERFACE_H_
#define IMU_INTERFACE_H_

void imu_print_data();


#endif /* IMU_INTERFACE_H_ */
35 changes: 20 additions & 15 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,36 +6,36 @@
#include "utils.h"
#include "esc-control.h"
#include "ppm-decode.h"
#include "imu-interface.h"


// ASCII escape character
#define ESC ((uint8)27)

// Globals
HardwareTimer timer1(1);

// -- setup() and loop() ------------------------------------------------------

void setup() {
disable_usarts();

// Set up the LED to blink
pinMode(BOARD_LED_PIN, OUTPUT);

// Setup timer1 for PWM
timer1.setMode(TIMER_CH1, TIMER_PWM);
timer1.setPrescaleFactor(21);
pinMode(ROTOR1_PIN, PWM);
pinMode(ROTOR2_PIN, PWM);
pinMode(ROTOR3_PIN, PWM);
//using timer4, channel1, maps to pin d16 (maple mini) according to maple master pin map.
// Set up ESC pins
pinMode(ROTOR1_PIN, PWM);
pinMode(ROTOR2_PIN, PWM);
pinMode(ROTOR3_PIN, PWM);
// Set up PPM pin
pinMode(PPM_PIN, INPUT_PULLUP);

// init motor controllers
esc_init();


// ppm decode setup
// init timer1 and dma
// ppm decode setup
init_ppm_timer_and_dma();
ppm_decode_go();

// init imu rx
Serial3.begin(28800);

// initialize usb
SerialUSB.begin();
while(!isConnected()); //wait till console attaches.
Expand All @@ -55,7 +55,7 @@ int main(void) {

while (1) {
toggleLED();
delay(250);
delay(20);

while (SerialUSB.available()) {
uint8 input = SerialUSB.read();
Expand All @@ -77,6 +77,11 @@ int main(void) {
print_ppm_data();
break;

case 'i':
/// imu data
imu_print_data();
break;

case 'h':
cmd_print_help();
break;
Expand Down
7 changes: 7 additions & 0 deletions main.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,19 @@
*
*/

#define COPTER_DEBUG

/* Timer 1, Ch 1 */
#define ROTOR1_PIN 27
/* Timer 1, Ch 2 */
#define ROTOR2_PIN 26
/* Timer 1, Ch 3 */
#define ROTOR3_PIN 25
/* Mounted on rotor 3 */
#define YAW_SERVO_PIN 24

/* Timer 4, Ch 1 */
#define PPM_PIN 16

/* 3_RX */
#define IMU_RX_PIN 0

0 comments on commit 9f335a8

Please sign in to comment.