/elec/quadcopter

To get this branch, use:
bzr branch http://bzr.ed.am/elec/quadcopter

« back to all changes in this revision

Viewing changes to src/rc-interface/main.ino

  • Committer: dan
  • Date: 2014-04-15 02:30:19 UTC
  • Revision ID: dan-20140415023019-u1qz3nxv08vpxb4s
First attempt at connecting up all the components on the circuit. Almost finnished but not managed to connect scl, sda, tx0 & rx0. Gonna pass over to Tim to see if he can find a solution.

Show diffs side-by-side

added added

removed removed

24
24
//            ___    |    |    |    |    |    |    |    |     ___
25
25
//    GND ---|___|---+----+----+----+    +----+----+----+----|___|--- GND
26
26
//             R                    |    |                     R
27
 
//             ____________________ | __ | _____________________
28
 
//                                  |    |
 
27
//         ________________________ | __ | _____________________
 
28
//         ARDUINO                  |    |
29
29
//                           pin 2  o    o  pin 3
30
30
//                    (interrupt 0)        (interrupt 1)
31
31
//
34
34
//
35
35
// Note that your receiver may not send pulses sequentially, in "channel order".
36
36
// If this turns out to be the case, you will need to arrange for the pulses to
37
 
// wire up the channels in an order whereby the pulses alternatively alternately
38
 
// between the two interrupts and adjust the channel order below.
 
37
// wire up the channels in an order whereby the pulses arrive alternately
 
38
// between the two interrupts and adjust the channel order in config.h.
39
39
//
40
40
// Motor control
41
41
// -------------
42
42
//
43
 
// 
44
 
 
 
43
// The four motor control outputs should be fed directly to the ESCs.
 
44
//
 
45
//                            ESC  ESC  ESC  ESC
 
46
//                             o    o    o    o
 
47
//                             |    |    |    |
 
48
//         ___________________ | __ | __ | __ | _____
 
49
//         ARDUINO             |    |    |    |
 
50
//                      pin 4  o    o    o    o  pin 7
 
51
//
 
52
// SERIAL INTERFACE
 
53
// ----------------
 
54
//
 
55
// The serial interface (pins 0 and 1) talk a very simple protocol.  When a
 
56
// complete set of 8 channel values have been read, it writes 0xffff followed by
 
57
// the 8, 16-bit unsigned channel values.  It expects to recieve 0xffff,
 
58
// followed by 4, 16-bit unsigned channel values.  All channel values are in the
 
59
// range specified in config.h.
45
60
 
46
61
#include "config.h"
47
62
#include "receiver.h"
49
64
#include "comms.h"
50
65
 
51
66
 
 
67
void flash_led()
 
68
{
 
69
        static bool on = false;
 
70
        on = !on;
 
71
        digitalWrite( LED_PIN, on? HIGH : LOW );
 
72
}
 
73
 
 
74
 
52
75
void setup()
53
76
{
 
77
        // init subsystems
54
78
        Receiver::setup();
55
79
        Motors::setup();
56
80
        Comms::setup();
60
84
        digitalWrite( LED_PIN, LOW );
61
85
}
62
86
 
63
 
 
64
 
void flash_led()
65
 
{
66
 
        static bool on = false;
67
 
        on = !on;
68
 
        digitalWrite( LED_PIN, on? HIGH : LOW );
69
 
}
70
 
 
71
 
 
72
87
void loop()
73
88
{
 
89
        int motor_values[ NUM_MOTORS ];
74
90
        int channel_values[ NUM_CHANNELS ];
75
91
 
 
92
        // reset the motor values
 
93
        for( int a = 0; a < NUM_MOTORS; a++ )
 
94
                motor_values[ a ] = 0;
 
95
 
76
96
        while( true )
77
97
        {
78
98
                // have we read a whole set of channel values?
83
103
 
84
104
                        // send channel values to main board
85
105
                        Comms::write_channels( channel_values );
86
 
 
 
106
                }
 
107
 
 
108
                // update motors
 
109
                Motors::update();
 
110
 
 
111
                // read channel values from main board
 
112
                if( Comms::read_channels( motor_values ) )
 
113
                {
87
114
                        // set motor speeds
88
 
                        Motors::set_values( channel_values );
 
115
                        Motors::set_values( motor_values );
89
116
                }
90
117
 
91
118
                // update motors