From 47d461e0638a6ecdd08faa3bda371de4d79aebfa Mon Sep 17 00:00:00 2001 From: Benjamin Shockley Date: Wed, 20 May 2015 12:55:53 -0700 Subject: [PATCH 1/4] Update DCCHardware.c Fixed typo in line 13; The end_bit for the DCC packet is a "1" --- DCCHardware.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DCCHardware.c b/DCCHardware.c index ea832ca..a386478 100644 --- a/DCCHardware.c +++ b/DCCHardware.c @@ -10,7 +10,7 @@ *dos_send_premable: A packet has been made available, and so we should broadcast the preamble: 14 '1's in a row *dos_send_bstart: Each data uint8_t is preceded by a '0' *dos_send_uint8_t: Sending the current data uint8_t - *dos_end_bit: After the final uint8_t is sent, send a '0'. + *dos_end_bit: After the final uint8_t is sent, send a '1'. */ typedef enum { dos_idle, From 60aee46a05eb326fa0ff26c335a9f329d874552a Mon Sep 17 00:00:00 2001 From: Benjamin Shockley Date: Fri, 3 Jul 2015 19:00:57 -0700 Subject: [PATCH 2/4] Update speed_byte to map analog values The original operation would often give me "-1" near the top value of speed_byte instead of 127. --- examples/CmdrArduino_minimum/CmdrArduino_minimum.ino | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/CmdrArduino_minimum/CmdrArduino_minimum.ino b/examples/CmdrArduino_minimum/CmdrArduino_minimum.ino index 00b5392..bb954ab 100644 --- a/examples/CmdrArduino_minimum/CmdrArduino_minimum.ino +++ b/examples/CmdrArduino_minimum/CmdrArduino_minimum.ino @@ -42,7 +42,7 @@ void loop() { //handle reading throttle analog_value = analogRead(0); - speed_byte = (analog_value >> 2)-127 ; //divide by four to take a 0-1023 range number and make it 1-126 range. + speed_byte = map(analog_value, 0, 1023, -127, 127); //Remap the analog input from [0 to 1023] into [-127 to 127] if(speed_byte != old_speed) { if(speed_byte == 0) //this would be treated as an e-stop! From 8f3c9f9bb04b6ceb175d908f2dca09d5a72a506d Mon Sep 17 00:00:00 2001 From: Benjamin Shockley Date: Mon, 25 Apr 2016 21:49:01 -0700 Subject: [PATCH 3/4] Update Throttle Reading Updated the dead_zone to span the middle 10 values (as written 506 - 516) and map them to -127 to -2 and 2 to 127. --- .../CmdrArduino_minimum.ino | 23 +++++++++++++------ 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/examples/CmdrArduino_minimum/CmdrArduino_minimum.ino b/examples/CmdrArduino_minimum/CmdrArduino_minimum.ino index bb954ab..0272543 100644 --- a/examples/CmdrArduino_minimum/CmdrArduino_minimum.ino +++ b/examples/CmdrArduino_minimum/CmdrArduino_minimum.ino @@ -42,14 +42,23 @@ void loop() { //handle reading throttle analog_value = analogRead(0); - speed_byte = map(analog_value, 0, 1023, -127, 127); //Remap the analog input from [0 to 1023] into [-127 to 127] + const uint16_t dead_zone_width = 10; + if(analog_value <= (511-dead_zone_width)) + { + speed_byte = map(analog_value, 0, 511-(.5*dead_zone_width), -127, -2) + } + else if(analog_value >= (512+dead_zone_width)) + { + speed_byte = map(analog_value, 511+(.5*dead_zone_width), 1023, 2, 127) + } + else + { + if(old_speed > 0) speed_byte = 1; + else speed_byte = -1; + } + if(speed_byte != old_speed) { - if(speed_byte == 0) //this would be treated as an e-stop! - { - if(old_speed > 0) speed_byte = 1; - else speed_byte = -1; - } Serial.print("analog = "); Serial.println(analog_value, DEC); Serial.print("digital = "); @@ -58,6 +67,6 @@ void loop() { old_speed = speed_byte; } dps.update(); - + ++count; } From 3a85911bd34a2da7d23ebf6e4c548d7113381ccc Mon Sep 17 00:00:00 2001 From: Benjamin Shockley Date: Mon, 25 Apr 2016 22:03:52 -0700 Subject: [PATCH 4/4] Update to Conditional Statements Updated conditional statements to match mapping code. --- examples/CmdrArduino_minimum/CmdrArduino_minimum.ino | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/CmdrArduino_minimum/CmdrArduino_minimum.ino b/examples/CmdrArduino_minimum/CmdrArduino_minimum.ino index 0272543..94dd5bc 100644 --- a/examples/CmdrArduino_minimum/CmdrArduino_minimum.ino +++ b/examples/CmdrArduino_minimum/CmdrArduino_minimum.ino @@ -43,11 +43,11 @@ void loop() { //handle reading throttle analog_value = analogRead(0); const uint16_t dead_zone_width = 10; - if(analog_value <= (511-dead_zone_width)) + if(analog_value <= (511-(.5*dead_zone_width))) { speed_byte = map(analog_value, 0, 511-(.5*dead_zone_width), -127, -2) } - else if(analog_value >= (512+dead_zone_width)) + else if(analog_value >= (511+(.5*dead_zone_width))) { speed_byte = map(analog_value, 511+(.5*dead_zone_width), 1023, 2, 127) }