Skip to content

Commit 20d4759

Browse files
committed
upload safe
1 parent f3636e2 commit 20d4759

File tree

3 files changed

+64
-61
lines changed

3 files changed

+64
-61
lines changed

controller-attiny85/controller-attiny85.ino

100644100755
Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@
99
//=============== Connections ================
1010
// See included schematic
1111
// Inputs:
12-
// Pin 2 -> Receiver CH1
13-
// Pin 3 -> Receiver CH2
14-
// Pin 4 -> Receiver CH3
12+
// Pin 0 -> Receiver CH1
13+
// Pin 1 -> Receiver CH2
14+
// Pin 2 -> Receiver CH3
1515
// Outputs:
16-
// Pin 0 -> Left wing servo
17-
// Pin 1 -> Right wing servo
16+
// Pin 3 -> Left wing servo
17+
// Pin 4 -> Right wing servo
1818

1919
//=================== Code ===================
2020
#include <Servo_ATTinyCore.h>
@@ -25,7 +25,7 @@ Servo servo[2];
2525
volatile uint16_t pwm_input[3] = {0};
2626

2727
//----- Input signals
28-
// PORTB = {0 .. 5} -> using pins {2 .. 4} = B00011100
28+
// PORTB = {0 .. 5} -> using pins {0 .. 2} = B00000111
2929

3030
/* port change interrupt to read PWM inputs from receiver */
3131
ISR( PCINT0_vect ) {
@@ -39,7 +39,7 @@ ISR( PCINT0_vect ) {
3939

4040
// find changing pins
4141
for( uint8_t index = 0; index < 3; index += 1) {
42-
uint8_t mask = B00000100 << index; // Start at PCINT2
42+
uint8_t mask = B00000001 << index; // Start at PCINT0
4343
if( port_rise & mask ) {
4444
initial_time[index] = current_time;
4545
} else if ( port_fall & mask ) {
@@ -53,13 +53,13 @@ void setupISR() {
5353
// enable pin change interrupts
5454
GIMSK |= (1 << PCIE);
5555
// set pins as PCINT
56-
PCMSK |= (1 << PCINT2);
57-
PCMSK |= (1 << PCINT3);
58-
PCMSK |= (1 << PCINT4);
56+
PCMSK |= (1 << PCINT0);
57+
PCMSK |= (1 << PCINT1);
58+
PCMSK |= (1 << PCINT2);
5959
// set as input
60-
pinMode(PB2, INPUT_PULLUP);
60+
pinMode(PB1, INPUT_PULLUP);
61+
pinMode(PB2, INPUT_PULLUP);
6162
pinMode(PB3, INPUT_PULLUP);
62-
pinMode(PB4, INPUT_PULLUP);
6363
}
6464

6565
//----- Input filter
@@ -87,10 +87,10 @@ float positive(float input) {
8787
//----- Servos
8888

8989
void setupServos() {
90-
pinMode(PB0, OUTPUT);
91-
pinMode(PB1, OUTPUT);
92-
servo[0].attach(PB0);
93-
servo[1].attach(PB1);
90+
pinMode(PB3, OUTPUT);
91+
pinMode(PB4, OUTPUT);
92+
servo[0].attach(PB3);
93+
servo[1].attach(PB4);
9494
}
9595

9696
//---- Waveform

controller-attiny85/parameters.cpp

100644100755
Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,28 @@
1+
/* CONSTANT | VALUE | UNIT | DESCRIPTION */
2+
/*=========================================================*/
13
// 1. Flapping waveform
2-
#define FREQ 2.8 // Wingbeat frequency [hz]. Use lowest frequency that achieves flight
3-
#define GAIN_WAVE 12.0 /* Triangle wave to square wave gain (truncation).
4-
A larger gain makes the waveform become more square-like with more throttle */
5-
4+
#define FREQ 2.8 // hz // Wingbeat frequency [hz]. Use lowest frequency that achieves flight
5+
#define GAIN_WAVE 12.0 /* Triangle wave to square wave gain (truncation).
6+
A larger gain makes the waveform become more square-like with more throttle */
67
// 2. Control inputs [negate to reverse direction]
78
// I. Base inputs:
8-
#define GAIN_THRT 0.8 // Flapping amplitude. Increases with more throttle
9-
#define GAIN_YAW 0.2 // Differential amplitude. Controlled by rudder
9+
#define GAIN_THRT 0.8 // Flapping amplitude. Increases with more throttle
10+
#define GAIN_YAW 0.4 // Differential amplitude. Controlled by rudder
1011
// II. Differential dihedral:
11-
#define GAIN_PITCH_DH 0.5 // Pitch: symmetric dihedral
12-
#define GAIN_ROLL_DH 0.5 // Roll: asymmetric dihedral
12+
#define GAIN_PITCH_DH 0.5 // Pitch: symmetric dihedral
13+
#define GAIN_ROLL_DH 0.5 // Roll: asymmetric dihedral
1314
// III. Frequency modulation:
14-
#define GAIN_PITCH_FM 0.0 // Pitch: wings fall at the same speed
15-
#define GAIN_ROLL_FM 0.0 // Roll: One wing falls faster than the other
15+
#define GAIN_PITCH_FM 0.0 // Pitch: wings fall at the same speed
16+
#define GAIN_ROLL_FM 0.0 // Roll: One wing falls faster than the other
1617

17-
// 3. Servo trims [ms]
18-
#define TRIM_LEFT 0 // left wing
19-
#define TRIM_RIGHT 0 // right wing
18+
// 3. Servo trims
19+
#define TRIM_LEFT 0 // us // left wing
20+
#define TRIM_RIGHT -60 // us // right wing
2021

2122
// 6. Output PWM signal
22-
#define PWM_MID 1500 // Center/middle servo position
23-
#define PWM_MIN 1100 // Minimum servo position
24-
#define PWM_MAX 1900 // Maximum servo position
23+
#define PWM_MID 1500 // us // Center/middle servo position
24+
#define PWM_MIN 1100 // us // Minimum servo position
25+
#define PWM_MAX 1900 // us // Maximum servo position
2526

26-
// 7. Input deadband filter [ms]
27-
#define INPUT_CHANGE 12 // Change in PWM signal needed to update receiver inputs
27+
// 7. Input deadband filter
28+
#define INPUT_CHANGE 12 // us // Change in PWM signal needed to update receiver inputs

controller-nano/parameters.cpp

100644100755
Lines changed: 29 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,42 @@
1+
/* CONSTANT | VALUE | UNIT | DESCRIPTION */
2+
/*=========================================================*/
13
// 1. Flapping waveform
2-
#define FREQ 2.8 // Wingbeat frequency [hz]. Use lowest frequency that achieves flight
3-
#define GAIN_WAVE 12.0 // Triangle wave to square wave gain (truncation). A larger gain makes the waveform become more square-like with more throttle
4-
4+
#define FREQ 2.8 // hz // Wingbeat frequency [hz]. Use lowest frequency that achieves flight
5+
#define GAIN_WAVE 12.0 /* Triangle wave to square wave gain (truncation).
6+
A larger gain makes the waveform become more square-like with more throttle */
57
// 2. Control inputs [negate to reverse direction]
68
// I. Base inputs:
7-
#define GAIN_PITCH 1.0 // Tail elevator
8-
#define GAIN_ROLL 1.0 // Tail aileron
9-
#define GAIN_THRT 0.8 // Flapping amplitude. Increases with more throttle
10-
#define GAIN_YAW 0.4 // Differential amplitude. Controlled by rudder
9+
#define GAIN_PITCH 1.0 // Tail elevator
10+
#define GAIN_ROLL 1.0 // Tail aileron
11+
#define GAIN_THRT 0.8 // Flapping amplitude. Increases with more throttle
12+
#define GAIN_YAW 0.4 // Differential amplitude. Controlled by rudder
1113
// II. Differential dihedral:
12-
#define GAIN_PITCH_DH 0.0 // Pitch: symmetric dihedral
13-
#define GAIN_ROLL_DH 0.0 // Roll: asymmetric dihedral
14+
#define GAIN_PITCH_DH 0.0 // Pitch: symmetric dihedral
15+
#define GAIN_ROLL_DH 0.0 // Roll: asymmetric dihedral
1416
// III. Frequency modulation:
15-
#define GAIN_PITCH_FM 0.0 // Pitch: wings fall at the same speed
16-
#define GAIN_ROLL_FM 0.0 // Roll: One wing falls faster than the other
17+
#define GAIN_PITCH_FM 0.0 // Pitch: wings fall at the same speed
18+
#define GAIN_ROLL_FM 0.0 // Roll: One wing falls faster than the other
1719

18-
// 3. Servo trims [ms]
19-
#define TRIM_LEFT 0 // left wing
20-
#define TRIM_RIGHT -60 // right wing
21-
#define TRIM_TLEFT 0 // left tail
22-
#define TRIM_TRIGHT 50 // right tail
20+
// 3. Servo trims
21+
#define TRIM_LEFT 0 // us // left wing
22+
#define TRIM_RIGHT -60 // us // right wing
23+
#define TRIM_TLEFT 0 // us // left tail
24+
#define TRIM_TRIGHT 50 // us // right tail
2325

24-
// 4. Pitching moment correction [ms]
25-
#define PITCH_TRIM_X 200 // Throttle PWM when trim reaches maximum value
26-
#define PITCH_TRIM_Y -350 // Maximum pitch trim. Negate to reverse deflection
26+
// 4. Pitching moment correction
27+
#define PITCH_TRIM_X 200 // us // Throttle PWM when trim reaches maximum value
28+
#define PITCH_TRIM_Y -350 // us // Maximum pitch trim. Negate to reverse deflection
2729

2830
// 5. Low voltage cutoff [voltage divider]
29-
#define RESISTOR_1 67000 // Resistor from ground -> middle [ohms]
30-
#define RESISTOR_2 118000 // Resistor from middle -> voltage [ohms]
31-
#define VOLT_CUT 6.0 // cutoff voltage
32-
#define VOLT_MAX 8.4 // fully charged voltage
31+
#define RESISTOR_1 67000 // ohm // Resistor from ground -> middle
32+
#define RESISTOR_2 118000 // ohm // Resistor from middle -> voltage
33+
#define VOLT_CUT 6.0 // volt // cutoff voltage
34+
#define VOLT_MAX 8.4 // volt // fully charged voltage
3335

3436
// 6. Output PWM signal [all servos]
35-
#define PWM_MID 1500 // Center/middle servo position
36-
#define PWM_MIN 1100 // Minimum servo position
37-
#define PWM_MAX 1900 // Maximum servo position
37+
#define PWM_MID 1500 // us // Center/middle servo position
38+
#define PWM_MIN 1100 // us // Minimum servo position
39+
#define PWM_MAX 1900 // us // Maximum servo position
3840

3941
// 7. Other
40-
#define USE_TAIL_SERVOS // Comment line to dissable tail servo output (only control wings)
42+
#define USE_TAIL_SERVOS // Comment line to dissable tail servo output (only control wings)

0 commit comments

Comments
 (0)