Permalink
Browse files

fixed transmit initialization

  • Loading branch information...
1 parent 9f628c9 commit 1b1d471a5c8e57e590d2ab0cf4621e14493be68f Ted Hansen committed May 8, 2012
Showing with 54 additions and 10 deletions.
  1. +8 −6 code/keyboard_ctrl/keyboard_ctrl.py
  2. +38 −2 code/rc_bot/rc_bot.ino
  3. +8 −2 code/rkf_xmit/rkf_xmit.ino
@@ -1,12 +1,14 @@
import sys
import serial
+import time
port_name = sys.argv[1]
baud_str = sys.argv[2]
port = serial.Serial(port_name, int(baud_str))
-port.write('start 500 2400\n')
+time.sleep(3)
+port.write("start 500 2400\n")
def keypress():
@@ -27,19 +29,19 @@ def keypress():
def go_forward():
- return "DATA 2 180 180"
+ return "data 2 180 180"
def go_backward():
- return "DATA 2 0 0"
+ return "data 2 0 0"
def turn_left():
- return "DATA 2 0 180"
+ return "data 2 0 180"
def turn_right():
- return "DATA 2 180 0"
+ return "data 2 180 0"
def stop():
- return "DATA 2 90 90"
+ return "data 2 90 90"
def quit():
exit()
View
@@ -5,30 +5,64 @@
ServoTimer2 LeftDrive, RightDrive;
+#define LEFT_FWD 1000
+#define LEFT_REV 2000
+#define LEFT_STOP ((LEFT_FWD + LEFT_REV)/2)
+
+#define RIGHT_FWD 1000
+#define RIGHT_REV 2000
+#define RIGHT_STOP ((RIGHT_FWD + RIGHT_REV)/2)
+
RKF_Radio radio;
void setup(){
LeftDrive.attach(LEFT_DRIVE_PIN);
RightDrive.attach(RIGHT_DRIVE_PIN);
pinMode(BUMP_SWITCH_RIGHT_PIN, INPUT);
pinMode(BUMP_SWITCH_LEFT_PIN, INPUT);
+ pinMode(DEFAULT_RX_PIN, INPUT);
pinMode(STATUS_LED_PIN, OUTPUT);
Serial.begin(57600);
+ LeftDrive.write(LEFT_STOP);
+ RightDrive.write(RIGHT_STOP);
radio.start();
+
+ Serial.println("Reset");
}
void loop()
{
+ int speed_L, speed_R;
+ int idx;
+
if(radio.recv())
{
+ Serial.print("rx:");
+ for(idx=0; idx<8; idx++)
+ {
+ Serial.print(" ");
+ Serial.print(radio.packet.data[idx], HEX);
+ }
+ Serial.println("");
+ Serial.println(radio.packet.message, HEX);
+
switch(radio.packet.message)
{
case 7:
- LeftDrive.write(radio.packet.data[1]);
- RightDrive.write(radio.packet.data[2]);
+ speed_L = map(radio.packet.data[1],
+ 0, 255, LEFT_REV, LEFT_FWD);
+
+ speed_R = map(radio.packet.data[2],
+ 0, 255, LEFT_REV, LEFT_FWD);
+
+ Serial.print("speed_L = ");
+ Serial.println(speed_L);
+ Serial.print("speed_R = ");
+ Serial.println(speed_R);
+
break;
case 0:
@@ -38,6 +72,8 @@ void loop()
}
}
+ LeftDrive.write(speed_L);
+ RightDrive.write(speed_R);
}
View
@@ -51,9 +51,12 @@ void loop()
// transmit the packet
vw_wait_tx();
vw_send((uint8_t*) &send_pkt_buffer, send_data_len);
+ // transmit the packet
+ vw_wait_tx();
+ vw_send((uint8_t*) &send_pkt_buffer, send_data_len);
- Serial.print("tx ");
- Serial.println(tx_msg_count++);
+ //Serial.print("tx ");
+ //Serial.println(tx_msg_count++);
}
digitalWrite(LED_PIN, vx_tx_active() ? HIGH : LOW);
@@ -102,6 +105,8 @@ void send_raw_data()
if(arg == NULL) break;
*ptr = byte(atoi(arg));
+ ptr++;
+
send_data_len++;
}
@@ -128,6 +133,7 @@ void start_tx()
vw_set_tx_pin(TX_PIN);
vw_setup(baud_rate);
+ send_data_len = sizeof(send_pkt_buffer);
tx_enabled_flag = 1;
Serial.print("start xmit: period=");

0 comments on commit 1b1d471

Please sign in to comment.