/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: Tim Marston
  • Date: 2014-01-15 22:18:56 UTC
  • Revision ID: tim@ed.am-20140115221856-lcqttlborwi7ot7k
rc-interface: mostly completed it (untested, but rx and tx code should work)

Show diffs side-by-side

added added

removed removed

24
24
//            ___    |    |    |    |    |    |    |    |     ___
25
25
//    GND ---|___|---+----+----+----+    +----+----+----+----|___|--- GND
26
26
//             R                    |    |                     R
27
 
//         ________________________ | __ | _____________________
28
 
//         ARDUINO                  |    |
 
27
//             ____________________ | __ | _____________________
 
28
//                                  |    |
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 arrive alternately
38
 
// between the two interrupts and adjust the channel order in config.h.
 
37
// wire up the channels in an order whereby the pulses alternatively alternately
 
38
// between the two interrupts and adjust the channel order below.
39
39
//
40
40
// Motor control
41
41
// -------------
42
42
//
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.
 
43
// 
 
44
 
60
45
 
61
46
#include "config.h"
62
47
#include "receiver.h"
63
48
#include "motors.h"
64
 
#include "comms.h"
 
49
#include "testing.h"
65
50
 
66
51
 
67
52
void setup()
68
53
{
69
54
        Receiver::setup();
70
55
        Motors::setup();
71
 
        Comms::setup();
72
 
 
73
 
        // led
74
 
        pinMode( LED_PIN, OUTPUT );
75
 
        digitalWrite( LED_PIN, LOW );
76
 
}
77
 
 
78
 
 
79
 
void flash_led()
80
 
{
81
 
        static bool on = false;
82
 
        on = !on;
83
 
        digitalWrite( LED_PIN, on? HIGH : LOW );
 
56
 
 
57
        Testing::setup();
84
58
}
85
59
 
86
60
 
87
61
void loop()
88
62
{
89
 
        int channel_values[ NUM_CHANNELS ];
 
63
        unsigned long channel_values[ NUM_CHANNELS ];
90
64
 
91
65
        while( true )
92
66
        {
93
 
                // have we read a whole set of channel values?
94
67
                if( Receiver::read_channels( channel_values ) )
95
68
                {
96
 
                        // update motors
97
 
                        Motors::update();
98
 
 
99
 
                        // yes, flash led!
100
 
                        flash_led();
101
 
 
102
 
                        // send channel values to main board
103
 
                        Comms::write_channels( channel_values );
104
 
 
105
 
                        // set motor speeds
106
 
                        Motors::set_values( channel_values );
 
69
                        Testing::draw_receiver_channels( channel_values );
107
70
                }
108
 
 
109
 
                // update motors
110
 
                Motors::update();
 
71
//              Motors::update_channels( channel_values );
111
72
        }
112
73
}