/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

9
9
// main board (and software running on it) of the task of interfacing with any
10
10
// of the RC system.
11
11
//
 
12
// Receiver
 
13
// --------
 
14
//
12
15
// The 8 channels (from the RC receiver) need to be combined and fed to two
13
16
// interrupts on the Arduino.  They need to be combined in such a way as to
14
17
// alternate pulses between the two interrupts (which are alternately used to
33
36
// If this turns out to be the case, you will need to arrange for the pulses to
34
37
// wire up the channels in an order whereby the pulses alternatively alternately
35
38
// between the two interrupts and adjust the channel order below.
 
39
//
 
40
// Motor control
 
41
// -------------
 
42
//
 
43
// 
36
44
 
37
45
 
38
46
#include "config.h"
39
47
#include "receiver.h"
40
 
 
41
 
 
42
 
// the width of the display of a single channel (in chars)
43
 
#define GRAPH_SIZE 7
44
 
 
45
 
// the channel's expected range for use in drawing (should be similar to
46
 
// {MAX,MIN}_PULSE_WIDTH values)
47
 
#define GRAPH_MIN 1000
48
 
#define GRAPH_MAX 2000
 
48
#include "motors.h"
 
49
#include "testing.h"
49
50
 
50
51
 
51
52
void setup()
52
53
{
53
54
        Receiver::setup();
54
 
        
55
 
        Serial.begin( 9600 );
56
 
}
57
 
 
58
 
 
59
 
void draw_graph( unsigned long channel_values[] )
60
 
{
61
 
        // init graph
62
 
        static char graph[ GRAPH_SIZE + 2 ];
63
 
        static char inited_graph = false;
64
 
        if( !inited_graph ) {
65
 
                for( int a = 1; a < GRAPH_SIZE + 1; a++ )
66
 
                        graph[ a ] = '_';
67
 
                graph[ 0 ] = '|';
68
 
                graph[ GRAPH_SIZE + 1 ] = 0;
69
 
                inited_graph = true;
70
 
        }
71
 
 
72
 
        // draw channels
73
 
        for( int a = 0; a < NUM_CHANNELS; a++ ) {
74
 
                unsigned long value = max( 0,
75
 
                        min( channel_values[ a ], GRAPH_MAX ) - GRAPH_MIN );
76
 
                int pos = ( GRAPH_SIZE ) * value / ( GRAPH_MAX - GRAPH_MIN );
77
 
                graph[ pos + 1 ] = '^';
78
 
                Serial.print( graph );
79
 
                graph[ pos + 1 ] = '_';
80
 
        }
81
 
        Serial.println( "|" );
 
55
        Motors::setup();
 
56
 
 
57
        Testing::setup();
82
58
}
83
59
 
84
60
 
89
65
        while( true )
90
66
        {
91
67
                if( Receiver::read_channels( channel_values ) )
92
 
                        draw_graph( channel_values );
 
68
                {
 
69
                        Testing::draw_receiver_channels( channel_values );
 
70
                }
 
71
//              Motors::update_channels( channel_values );
93
72
        }
94
73
}