Revision 02df64f0

View differences:

arduino/RCbuggyMega/RCbuggyMega.ino
1 1
/*
2
  Makes Arduino receive input from xbee and parse data.
3
 
4
 The circuit:
5
 * RX is digital pin 2 (connect to TX of XBee)
6
 * TX is digital pin 3 (connect to RX of XBee)
7
 
2
 * @file RCbuggyMega
3
 * @brief Receives data from XBee, and uses this data to control the buggy. 
4
 *
5
 * Pinout circuit:
6
 *   Serial1: Used for XBee
7
 *     RX is digital pin 2 (connect to TX of XBee)
8
 *     TX is digital pin 3 (connect to RX of XBee)
9
 *
10
 *   Serial: Used for Programming/Debugging
11
 *     Connect for debugging. 
12
 *  
8 13
 */
9

  
10
//#include <SoftwareSerial.h>
11 14
#include <Servo.h> 
12

  
13 15
Servo myservo;  // create servo object to control a servo 
14 16

  
15
//SoftwareSerial xbee(2, 3); // RX, TX
17
#define XBEE_BAUD 9600
18
#define DEBUG_BAUD 9600
19
#define PIN_LED_XBEE_INDICATOR 4
20
#define PIN_LED_BRAKE_DEPLOYED 5
21
// comes on after two seconds of lost connection
22
#define PIN_LED_LOSS_CONNECTION 12 
23

  
24
#define PIN_BRAKE_DEPLOY_OUT 8
25

  
26
#define PIN_SERVO_OUT 9
27

  
28
// Default value for the wheel. 
29
#define SERVO_WHEEL_DEFAULT 133
30

  
31
#define PIN_HALL_EFFECT_IN 10
32

  
33
// Packet-sending variables
16 34
unsigned long timer = 0L;
17 35
char data;
18 36
String message;
19 37
char intbuf[32];
38

  
39
// Buggy variables
20 40
int brake = 0;
21 41
int steeringAngle = 135;
22 42
int pingPong = 1;
43

  
44
// String parsing variables
23 45
int startfound = 0;
24 46
int midfound = 0;
25 47
int endfound = 1;
26 48

  
27 49
void setup()  {
28
  Serial.begin(9600);
29
  //Serial.println( "Arduino started sending bytes via XBee" );
30
  Serial1.begin(9600);
31

  
32
  pinMode(4, OUTPUT);
33
  pinMode(5, OUTPUT);
34
  pinMode(8, OUTPUT);
35
  myservo.attach(9);  // attaches the servo on pin 9 to the servo object 
50
  // Initialize debug serial and xbee serial. 
51
  Serial.begin(DEBUG_BAUD);
52
  Serial1.begin(XBEE_BAUD);
53

  
54
  pinMode(PIN_LED_XBEE_INDICATOR, OUTPUT);
55
  pinMode(PIN_LED_BRAKE_DEPLOYED, OUTPUT);
56
  pinMode(PIN_BRAKE_DEPLOY_OUT, OUTPUT);
57
  myservo.attach(PIN_SERVO_OUT);  // attaches the servo on pin 9 to the servo object 
36 58
  myservo.write(133);
37 59
}
38 60

  
joystick/joystick.py
55 55
brake = 1
56 56

  
57 57
# Open serial port
58
ser = serial.Serial('COM8', 9600, timeout=5)
58
ser = serial.Serial('COM12', 9600, timeout=5)
59 59

  
60 60

  
61 61
# -------- Main Program Loop -----------
......
143 143
    pygame.display.flip()
144 144

  
145 145
    sAngle = (-1.0*(steeringAngle - 1))/2.0
146
    sAngle = (sAngle*60)+102
146
    sAngle = (sAngle*60)+95
147 147
    # sAngle = (sAngle*range of motion)+minimum value
148 148
    sAngle = int(sAngle)
149 149
    if sAngle > 180:

Also available in: Unified diff