git.haldean.org droidcopter / e0ec8ce
Updated firmware and added better bandwidth testing Will Brown 11 years ago
3 changed file(s) with 36 addition(s) and 7 deletion(s). Raw diff Collapse all Expand all
0 #define ARM_BUTTON_PIN 12
01 #define BAD_REQUEST "BADREQUEST"
12 #define HEARTBEAT_PULSE "PULSE"
23 #define MESSAGE_TIMEOUT_CYCLES 100
1718
1819 unsigned int led_cycles = 0;
1920 MeetAndroid bt;
21 bool enable_motors = true;
2022
2123 struct motor {
2224 unsigned char pin;
3537 */
3638 void write_speeds(void) {
3739 for (int i = 0; i < MOTOR_COUNT; i++) {
38 motors[i].current_speed = motors[i].next_speed;
39 motors[i].ctrl.write(motors[i].current_speed);
40 if (enable_motors) {
41 motors[i].current_speed = motors[i].next_speed;
42 motors[i].ctrl.write(motors[i].current_speed);
43 } else {
44 motors[i].ctrl.write(MOTOR_OFF_COMMAND);
45 }
4046 }
4147 }
4248
4551 */
4652 void print_speeds(void) {
4753 for (int i = 0; i < MOTOR_COUNT; i++) {
48 bt.send(motors[i].current_speed);
54 Serial.print(motors[i].current_speed);
55 Serial.print(" ");
4956 }
57 Serial.print("\n");
5058 }
5159
5260 /**
104112 motors[i].next_speed = MOTOR_OFF_COMMAND;
105113 }
106114
107 write_speeds();
108 print_speeds();
115 //print_speeds();
116 Serial.println("done");
109117 led_cycles = 0;
110118 }
111119
113121 * Wait for serial information to come in.
114122 */
115123 void loop(void) {
124 enable_motors = digitalRead(ARM_BUTTON_PIN) == HIGH;
116125 bt.receive();
117126
118 led_cycles++;
119 if (led_cycles >= STATUS_LED_CYCLES) {
127 write_speeds();
128
129 if (enable_motors) {
130 digitalWrite(STATUS_LED, HIGH);
131 } else {
120132 digitalWrite(STATUS_LED, LOW);
121133 }
122134
0 #!/usr/bin/env python
1
2 import random, serial, time
3
4 def test(flags, msgs, port='/dev/ttyUSB0'):
5 s = serial.Serial(port)
6
7 def send_speeds():
8 for f in flags:
9 msg = "%s%d\x13" % (f, random.randint(0,100))
10 s.write(msg)
11
12 t = time.time()
13 [send_speeds() for i in range(msgs)]
14 t = time.time() - t
15 print "%f seconds for %d messages (average: %f)" % (t, msgs, t/msgs)
16