From 82315e8d22ca69cefb1b075da2386e07f817f8e8 Mon Sep 17 00:00:00 2001 From: Eric Galluzzi Date: Mon, 4 Sep 2023 00:43:09 -0400 Subject: [PATCH 01/15] rs422 steering sensor library --- Libraries/STEERING_RS422/STEERING_RS422.h | 36 +++++++++++++ Libraries/STEERING_RS422/STEERING_RS_422.cpp | 57 ++++++++++++++++++++ 2 files changed, 93 insertions(+) create mode 100644 Libraries/STEERING_RS422/STEERING_RS422.h create mode 100644 Libraries/STEERING_RS422/STEERING_RS_422.cpp diff --git a/Libraries/STEERING_RS422/STEERING_RS422.h b/Libraries/STEERING_RS422/STEERING_RS422.h new file mode 100644 index 00000000..48cef828 --- /dev/null +++ b/Libraries/STEERING_RS422/STEERING_RS422.h @@ -0,0 +1,36 @@ +#ifndef __STEERING_RS_422_H__ +#define __STEERING_RS_422_H__ + +#include +#include + + +#define DEFAULT_HARDWARE_SERIAL 5 + +#define MAX_POSITION 8192 + +class STEERING_RS422 { + public: + STEERING_RS422(); + STEERING_RS422(uint8_t serial); + uint16_t read_steering(); + void set_zero_position(uint16_t position) { this->zero_position = position}; + uint16_t get_encoder_position() const { return encoder_position}; + private: + static uint16_t buf; + HardwareSerial* _serial; + uint16_t encoder_position; + bool error; + bool warning; + uint8_t status; + /* + r7 - Warning: limit of lower ride height tolerance. Error: Signal Ampltiude too high. Redhead too close to magentor external magnetic field is interfering. + r6 - Warning: Limit of upper ride height tolerance. Error: Signal Amplitude too low. Distance bewteen redhead and ring is too large. + r5 - Warning: Redhead temp out of range + r4 - Warning: Speed too high + */ + uint16_t zero_position; + int16_t steering_position; +} + +#endif \ No newline at end of file diff --git a/Libraries/STEERING_RS422/STEERING_RS_422.cpp b/Libraries/STEERING_RS422/STEERING_RS_422.cpp new file mode 100644 index 00000000..2edf56bf --- /dev/null +++ b/Libraries/STEERING_RS422/STEERING_RS_422.cpp @@ -0,0 +1,57 @@ +#include "STEERING_RS422.h" + +// Init STEERING_RS422 using default hardware serial port +STEERING_RS422::STEERING_RS422() { + this(DEFAULT_HARDWARE_SERIAL); +} + +//Init STEERING_RS422 using configurable hadware serial port +STEERING_RS422::STEERING_RS422(uint8_t serial) { + switch (serial) { + case 1: + _serial(&Serial1); + case 2: + _serial(&Serial2) + case 3: + _serial(&Serial3) + case 4: + _serial(&Serial4) + case 5: + _serial(&Serial5) + case 6: + _serial(&Serial6) + case 7: + _serial(&Serial7) + case 8: + _serial(&Serial8) + } +} + +uint16_t STEERING_RS422::read_steering() { + uint8_t readByte[3] = {0}; + _serial_>write("d"); + + + //check if _serial is available and the first byte is ascii "d" + + if (serial->available() >= 4 && serial->read() == "d") { + readByte[0] = serial->read() //lower half of steering + readByte[1] = serial->read() //upper half of steering + readByte[2] = serial->read() //error stream + _serial->clear(); + } + + encoder_position = readByte[1] << 6 | readByte[0] >> 2; + error = readByte[0] & 2; //if high, current data is not valid, previous data is sent + warning = readByte[0] & 1; //if high, some operating conditions are close to limits + status = readByte[2]; + if ((MAX_POSITION + (encoder_position - zero_position)) % MAX_POSITION <= (MAX_POSITION / 2)) { + steering_position = -((MAX_POSITION + (encoder_position - zero_position)) % MAX_POSITION); + } else { + steering_position = MAX_POSITION - ((MAX_POSITION + (encoder_position - zero_position)) % MAX_POSITION); + } + + + return steering_position; + +} \ No newline at end of file From 8f991f1231ace5d9b84a43d10e3077e073c2909b Mon Sep 17 00:00:00 2001 From: Eric Galluzzi Date: Mon, 4 Sep 2023 23:01:32 -0400 Subject: [PATCH 02/15] read works --- Libraries/STEERING_RS422/STEERING_RS422.h | 9 +-- Libraries/STEERING_RS422/STEERING_RS_422.cpp | 65 ++++++++++++------- .../steering_rs422_testing.ino | 32 +++++++++ 3 files changed, 77 insertions(+), 29 deletions(-) create mode 100644 Utilities/steering_rs422_testing/steering_rs422_testing.ino diff --git a/Libraries/STEERING_RS422/STEERING_RS422.h b/Libraries/STEERING_RS422/STEERING_RS422.h index 48cef828..e96b2126 100644 --- a/Libraries/STEERING_RS422/STEERING_RS422.h +++ b/Libraries/STEERING_RS422/STEERING_RS422.h @@ -1,6 +1,6 @@ #ifndef __STEERING_RS_422_H__ #define __STEERING_RS_422_H__ - +#include #include #include @@ -13,9 +13,10 @@ class STEERING_RS422 { public: STEERING_RS422(); STEERING_RS422(uint8_t serial); + void init(unsigned long baudrate); uint16_t read_steering(); - void set_zero_position(uint16_t position) { this->zero_position = position}; - uint16_t get_encoder_position() const { return encoder_position}; + void set_zero_position(uint16_t position) { this->zero_position = position;}; + uint16_t get_encoder_position() const { return encoder_position;}; private: static uint16_t buf; HardwareSerial* _serial; @@ -31,6 +32,6 @@ class STEERING_RS422 { */ uint16_t zero_position; int16_t steering_position; -} +}; #endif \ No newline at end of file diff --git a/Libraries/STEERING_RS422/STEERING_RS_422.cpp b/Libraries/STEERING_RS422/STEERING_RS_422.cpp index 2edf56bf..dc717e36 100644 --- a/Libraries/STEERING_RS422/STEERING_RS_422.cpp +++ b/Libraries/STEERING_RS422/STEERING_RS_422.cpp @@ -2,55 +2,70 @@ // Init STEERING_RS422 using default hardware serial port STEERING_RS422::STEERING_RS422() { - this(DEFAULT_HARDWARE_SERIAL); + STEERING_RS422(DEFAULT_HARDWARE_SERIAL); } //Init STEERING_RS422 using configurable hadware serial port STEERING_RS422::STEERING_RS422(uint8_t serial) { + switch (serial) { case 1: - _serial(&Serial1); + _serial = &Serial1; + break; case 2: - _serial(&Serial2) + _serial = &Serial2; + break; case 3: - _serial(&Serial3) + _serial = &Serial3; + break; case 4: - _serial(&Serial4) + _serial = &Serial4; + break; case 5: - _serial(&Serial5) + _serial = &Serial5; + break; case 6: - _serial(&Serial6) + _serial = &Serial6; + break; case 7: - _serial(&Serial7) + _serial = &Serial7; + break; case 8: - _serial(&Serial8) + + //_serial = &Serial8; //not on teensy 4.0 + break; } } +void STEERING_RS422::init(unsigned long baudrate) { + _serial->begin(baudrate); +} uint16_t STEERING_RS422::read_steering() { uint8_t readByte[3] = {0}; - _serial_>write("d"); + _serial->write(0x64); //check if _serial is available and the first byte is ascii "d" - - if (serial->available() >= 4 && serial->read() == "d") { - readByte[0] = serial->read() //lower half of steering - readByte[1] = serial->read() //upper half of steering - readByte[2] = serial->read() //error stream - _serial->clear(); - } - encoder_position = readByte[1] << 6 | readByte[0] >> 2; - error = readByte[0] & 2; //if high, current data is not valid, previous data is sent - warning = readByte[0] & 1; //if high, some operating conditions are close to limits - status = readByte[2]; - if ((MAX_POSITION + (encoder_position - zero_position)) % MAX_POSITION <= (MAX_POSITION / 2)) { - steering_position = -((MAX_POSITION + (encoder_position - zero_position)) % MAX_POSITION); - } else { - steering_position = MAX_POSITION - ((MAX_POSITION + (encoder_position - zero_position)) % MAX_POSITION); + + if (_serial->available() >= 4 && _serial->read() == 0x64) { + + readByte[0] = _serial->read(); //lower half of steering + readByte[1] = _serial->read(); //upper half of steering + readByte[2] = _serial->read(); //error stream + encoder_position = readByte[1] << 6 | readByte[0] >> 2; + error = readByte[0] & 2; //if high, current data is not valid, previous data is sent + warning = readByte[0] & 1; //if high, some operating conditions are close to limits + status = readByte[2]; + if ((MAX_POSITION + (encoder_position - zero_position)) % MAX_POSITION <= (MAX_POSITION / 2)) { + steering_position = -((MAX_POSITION + (encoder_position - zero_position)) % MAX_POSITION); + } else { + steering_position = MAX_POSITION - ((MAX_POSITION + (encoder_position - zero_position)) % MAX_POSITION); + } } + + return steering_position; diff --git a/Utilities/steering_rs422_testing/steering_rs422_testing.ino b/Utilities/steering_rs422_testing/steering_rs422_testing.ino new file mode 100644 index 00000000..373f8e68 --- /dev/null +++ b/Utilities/steering_rs422_testing/steering_rs422_testing.ino @@ -0,0 +1,32 @@ +#include +#include "STEERING_RS422.h" +#include "Metro.h" + +//STEERING_RS422 steering(5); +Metro read_steering_timer(20); +void setup() { + // put your setup code here, to run once: + Serial.begin(9600); + Serial5.begin(115200); + //steering.init(115200); + pinMode(13, OUTPUT); + + +} +bool out; +void loop() { + if (read_steering_timer.check()) { + Serial5.write(0x33); + if (Serial5.available()) { + Serial.println(Serial5.read()); + } + +// //Serial.println(); +// steering.read_steering(); + } + + + + // put your main code here, to run repeatedly: + +} From 9e8ca3c61eea02dc574e3ed3e5f308e063323662 Mon Sep 17 00:00:00 2001 From: CL16gtgh Date: Tue, 5 Sep 2023 20:05:45 -0400 Subject: [PATCH 03/15] jank rs422 testing code bc laptop skill issue --- Utilities/steering_rs422_testing/steering_rs422_testing.ino | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Utilities/steering_rs422_testing/steering_rs422_testing.ino b/Utilities/steering_rs422_testing/steering_rs422_testing.ino index 373f8e68..b5ff76a7 100644 --- a/Utilities/steering_rs422_testing/steering_rs422_testing.ino +++ b/Utilities/steering_rs422_testing/steering_rs422_testing.ino @@ -18,7 +18,11 @@ void loop() { if (read_steering_timer.check()) { Serial5.write(0x33); if (Serial5.available()) { - Serial.println(Serial5.read()); + char position_high = Serial5.read(); + char position_low_and_error_warning = Serial.read(); + uint16_t encoder_position = position_high << 6 | position_low_and_error_warning >> 2; + Serial.println(encoder_position); +// Serial.println(Serial5.read()); } // //Serial.println(); From 142d8cfe7ba96e747154cd60eb430d4628c637d2 Mon Sep 17 00:00:00 2001 From: Eric Galluzzi Date: Sun, 10 Sep 2023 14:13:27 -0400 Subject: [PATCH 04/15] program library --- Libraries/STEERING_RS422/STEERING_RS422.h | 4 +- Libraries/STEERING_RS422/STEERING_RS_422.cpp | 45 ++++++++++++++++---- 2 files changed, 39 insertions(+), 10 deletions(-) diff --git a/Libraries/STEERING_RS422/STEERING_RS422.h b/Libraries/STEERING_RS422/STEERING_RS422.h index e96b2126..5c20d1e9 100644 --- a/Libraries/STEERING_RS422/STEERING_RS422.h +++ b/Libraries/STEERING_RS422/STEERING_RS422.h @@ -8,15 +8,17 @@ #define DEFAULT_HARDWARE_SERIAL 5 #define MAX_POSITION 8192 +#define ZERO_POSITION 8180 class STEERING_RS422 { public: STEERING_RS422(); STEERING_RS422(uint8_t serial); void init(unsigned long baudrate); - uint16_t read_steering(); + int16_t read_steering(); void set_zero_position(uint16_t position) { this->zero_position = position;}; uint16_t get_encoder_position() const { return encoder_position;}; + void calibrate_steering(); private: static uint16_t buf; HardwareSerial* _serial; diff --git a/Libraries/STEERING_RS422/STEERING_RS_422.cpp b/Libraries/STEERING_RS422/STEERING_RS_422.cpp index dc717e36..015bcf28 100644 --- a/Libraries/STEERING_RS422/STEERING_RS_422.cpp +++ b/Libraries/STEERING_RS422/STEERING_RS_422.cpp @@ -39,8 +39,9 @@ STEERING_RS422::STEERING_RS422(uint8_t serial) { void STEERING_RS422::init(unsigned long baudrate) { _serial->begin(baudrate); + this->set_zero_position(ZERO_POSITION); } -uint16_t STEERING_RS422::read_steering() { +int16_t STEERING_RS422::read_steering() { uint8_t readByte[3] = {0}; _serial->write(0x64); @@ -53,15 +54,18 @@ uint16_t STEERING_RS422::read_steering() { readByte[0] = _serial->read(); //lower half of steering readByte[1] = _serial->read(); //upper half of steering readByte[2] = _serial->read(); //error stream - encoder_position = readByte[1] << 6 | readByte[0] >> 2; - error = readByte[0] & 2; //if high, current data is not valid, previous data is sent - warning = readByte[0] & 1; //if high, some operating conditions are close to limits + encoder_position = readByte[0] << 6 | readByte[1] >> 2; + error = readByte[1] & 2; //if high, current data is not valid, previous data is sent + warning = readByte[1] & 1; //if high, some operating conditions are close to limits status = readByte[2]; - if ((MAX_POSITION + (encoder_position - zero_position)) % MAX_POSITION <= (MAX_POSITION / 2)) { - steering_position = -((MAX_POSITION + (encoder_position - zero_position)) % MAX_POSITION); - } else { - steering_position = MAX_POSITION - ((MAX_POSITION + (encoder_position - zero_position)) % MAX_POSITION); - } + Serial.println(encoder_position); + // if ((MAX_POSITION + (encoder_position - zero_position)) % MAX_POSITION <= (MAX_POSITION / 2)) { + // steering_position = -((MAX_POSITION + (encoder_position - zero_position)) % MAX_POSITION); + // } else { + // steering_position = MAX_POSITION - ((MAX_POSITION + (encoder_position - zero_position)) % MAX_POSITION); + // } + steering_position = encoder_position - zero_position ; + //_serial->clear(); } @@ -69,4 +73,27 @@ uint16_t STEERING_RS422::read_steering() { return steering_position; +} + +void STEERING_RS422::calibrate_steering() { + //start programming sequence + delay(1); + _serial->write(0xCD); + delay(1); + _serial->write(0xEF); + delay(1); + _serial->write(0x89); + delay(1); + _serial->write(0xAB); + delay(1); + _serial->write(0x5A); + delay(1); + _serial->write(0x00); + delay(1); + _serial->write(0x00); + delay(1); + _serial->write(0x0E); + delay(1); + _serial->write(0x18); + delay(1); } \ No newline at end of file From 72bb94a02b7d90abd1c7a732998d12c044a0a6ad Mon Sep 17 00:00:00 2001 From: Eric Galluzzi Date: Sun, 7 Jan 2024 15:45:21 -0500 Subject: [PATCH 05/15] finalized --- Libraries/STEERING_RS422/STEERING_RS422.h | 12 +- Libraries/STEERING_RS422/STEERING_RS_422.cpp | 120 ++++++++++++++++--- 2 files changed, 115 insertions(+), 17 deletions(-) diff --git a/Libraries/STEERING_RS422/STEERING_RS422.h b/Libraries/STEERING_RS422/STEERING_RS422.h index 5c20d1e9..c9342b83 100644 --- a/Libraries/STEERING_RS422/STEERING_RS422.h +++ b/Libraries/STEERING_RS422/STEERING_RS422.h @@ -16,9 +16,19 @@ class STEERING_RS422 { STEERING_RS422(uint8_t serial); void init(unsigned long baudrate); int16_t read_steering(); + int16_t read_steering_continous(); + void request_status(); void set_zero_position(uint16_t position) { this->zero_position = position;}; uint16_t get_encoder_position() const { return encoder_position;}; - void calibrate_steering(); + void calibrate_steering(uint32_t pos); + void command_sequence() + void save_parameters(); + void continous_setup(uint16_t period, bool auto_start); + void continous_start(); + void continous_stop(); + void reset_sensor(); + void set_zero_position(uint16_t new_zero_position); + uint8_t self_calibration(); private: static uint16_t buf; HardwareSerial* _serial; diff --git a/Libraries/STEERING_RS422/STEERING_RS_422.cpp b/Libraries/STEERING_RS422/STEERING_RS_422.cpp index 015bcf28..296518a5 100644 --- a/Libraries/STEERING_RS422/STEERING_RS_422.cpp +++ b/Libraries/STEERING_RS422/STEERING_RS_422.cpp @@ -42,13 +42,24 @@ void STEERING_RS422::init(unsigned long baudrate) { this->set_zero_position(ZERO_POSITION); } int16_t STEERING_RS422::read_steering() { - uint8_t readByte[3] = {0}; - _serial->write(0x64); + + request_status(); //check if _serial is available and the first byte is ascii "d" + + return read_steering_continous(); + +} +void STEERING_RS422::request_status() { + _serial->write(0x64); + delay(1); +} +int16_t STEERING_RS422::read_steering_continous() { + uint8_t readByte[3] = {0}; + //check if _serial is available and the first byte is ascii "d" if (_serial->available() >= 4 && _serial->read() == 0x64) { readByte[0] = _serial->read(); //lower half of steering @@ -59,11 +70,7 @@ int16_t STEERING_RS422::read_steering() { warning = readByte[1] & 1; //if high, some operating conditions are close to limits status = readByte[2]; Serial.println(encoder_position); - // if ((MAX_POSITION + (encoder_position - zero_position)) % MAX_POSITION <= (MAX_POSITION / 2)) { - // steering_position = -((MAX_POSITION + (encoder_position - zero_position)) % MAX_POSITION); - // } else { - // steering_position = MAX_POSITION - ((MAX_POSITION + (encoder_position - zero_position)) % MAX_POSITION); - // } + steering_position = encoder_position - zero_position ; //_serial->clear(); } @@ -71,12 +78,28 @@ int16_t STEERING_RS422::read_steering() { - return steering_position; - + return steering_position; } - -void STEERING_RS422::calibrate_steering() { +void STEERING_RS422::set_zero_position(uint16_t new_zero_position) { + zero_position = new_zero_position; +} +void STEERING_RS422::calibrate_steering(uint32_t pos) { //start programming sequence + //this sends data to essentially add a zero offset + //pos = 0x00000E18 + command_sequence(); + _serial->write(0x5A); + delay(1); + _serial->write(pos &0xFF000000); + delay(1); + _serial->write(pos &0xFF0000); + delay(1); + _serial->write(pos &0xFF00); + delay(1); + _serial->write(pos & 0xFF); + delay(1); +} +void STEERING_RS422::command_sequence() { delay(1); _serial->write(0xCD); delay(1); @@ -86,14 +109,79 @@ void STEERING_RS422::calibrate_steering() { delay(1); _serial->write(0xAB); delay(1); - _serial->write(0x5A); + +} + +void STEERING_RS422::continous_setup(uint16_t period, bool auto_start = 0) { + command_sequence(); + _serial->write(0x54); + delay(1); + _serial->write((auto_start) ? 0x01 : 0x00); + delay(1) + _serial->write(0x64); + delay(1); + //in microseconds + _serial(period & 0xFF00); + delay(1); + _serial(period & 0xFF); + +} +void STEERING_RS422::continous_start() { + command_sequence(); + _serial->write(0x53); + delay(1); +} +void STEERING_RS422::continous_stop() { + command_sequence(); + _serial->write(0x50); delay(1); - _serial->write(0x00); +} +void STEERING_RS422::save_parameters() { + command_sequence(); + _serial->write(0x63); delay(1); - _serial->write(0x00); +} +void STEERING_RS422::reset_sensor() { + command_sequence(); + _serial->write(0x72); delay(1); - _serial->write(0x0E); +} + +uint8_t STEERING_RS422::self_calibration() { + //b6 calibration alr performed + //b3 calcualted params out of range + //b2 timeout (no complete rotation) + //b1 counter bit 1 + //b0 counter bit 0 + //check status + uint8_t status_flags = 0; + //check if calubration was already performed + command_sequence(); + _serial->write(0x69); delay(1); - _serial->write(0x18); + if (_serial->available() && _serial->read() == 0x69) { + + status_flags = _serial->read(); + } + if (status_flags & 0b01000000) { + return status_flags; + } + + //self calibrate + command_sequence(); + _serial->write(0x41); + delay(10000); //10 sec delay() + + //check status + command_sequence(); + _serial->write(0x69); delay(1); + if (_serial->available() && _serial->read() == 0x69) { + status_flags = _serial->read(); + } + //check if any errors + if (status_flags & 0b0001100) { + return status_flags; + } + return 1; } \ No newline at end of file From e0bab97d1842480276e3086bba65a1d48e6d2b77 Mon Sep 17 00:00:00 2001 From: rsandhuny Date: Thu, 11 Jan 2024 19:44:20 -0500 Subject: [PATCH 06/15] Syntax Fixes Syntax Fixes and removed multiple declarations of same function --- Libraries/STEERING_RS422/STEERING_RS422.h | 5 ++--- Libraries/STEERING_RS422/STEERING_RS_422.cpp | 9 +++++---- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/Libraries/STEERING_RS422/STEERING_RS422.h b/Libraries/STEERING_RS422/STEERING_RS422.h index c9342b83..5219c5b7 100644 --- a/Libraries/STEERING_RS422/STEERING_RS422.h +++ b/Libraries/STEERING_RS422/STEERING_RS422.h @@ -18,17 +18,16 @@ class STEERING_RS422 { int16_t read_steering(); int16_t read_steering_continous(); void request_status(); - void set_zero_position(uint16_t position) { this->zero_position = position;}; uint16_t get_encoder_position() const { return encoder_position;}; void calibrate_steering(uint32_t pos); - void command_sequence() + void command_sequence(); void save_parameters(); void continous_setup(uint16_t period, bool auto_start); void continous_start(); void continous_stop(); void reset_sensor(); void set_zero_position(uint16_t new_zero_position); - uint8_t self_calibration(); + //uint8_t self_calibration(); private: static uint16_t buf; HardwareSerial* _serial; diff --git a/Libraries/STEERING_RS422/STEERING_RS_422.cpp b/Libraries/STEERING_RS422/STEERING_RS_422.cpp index 296518a5..8f664f9a 100644 --- a/Libraries/STEERING_RS422/STEERING_RS_422.cpp +++ b/Libraries/STEERING_RS422/STEERING_RS_422.cpp @@ -117,13 +117,13 @@ void STEERING_RS422::continous_setup(uint16_t period, bool auto_start = 0) { _serial->write(0x54); delay(1); _serial->write((auto_start) ? 0x01 : 0x00); - delay(1) + delay(1); _serial->write(0x64); delay(1); //in microseconds - _serial(period & 0xFF00); + _serial->write(period & 0xFF00); delay(1); - _serial(period & 0xFF); + _serial->write(period & 0xFF); } void STEERING_RS422::continous_start() { @@ -147,6 +147,7 @@ void STEERING_RS422::reset_sensor() { delay(1); } +/* uint8_t STEERING_RS422::self_calibration() { //b6 calibration alr performed //b3 calcualted params out of range @@ -184,4 +185,4 @@ uint8_t STEERING_RS422::self_calibration() { return status_flags; } return 1; -} \ No newline at end of file +} */ \ No newline at end of file From 96a3ea6750e67809f2c768255e0acf965b95b7d0 Mon Sep 17 00:00:00 2001 From: imix8 <112455598+imix8@users.noreply.github.com> Date: Sun, 14 Jan 2024 19:56:18 -0500 Subject: [PATCH 07/15] RS422 Error Code Implementation --- Libraries/STEERING_RS422/STEERING_RS422.h | 1 + Libraries/STEERING_RS422/STEERING_RS_422.cpp | 28 +++++++++++++++---- .../steering_rs422_testing.ino | 6 ++-- 3 files changed, 28 insertions(+), 7 deletions(-) diff --git a/Libraries/STEERING_RS422/STEERING_RS422.h b/Libraries/STEERING_RS422/STEERING_RS422.h index 5219c5b7..3942eb6d 100644 --- a/Libraries/STEERING_RS422/STEERING_RS422.h +++ b/Libraries/STEERING_RS422/STEERING_RS422.h @@ -23,6 +23,7 @@ class STEERING_RS422 { void command_sequence(); void save_parameters(); void continous_setup(uint16_t period, bool auto_start); + void interpret_error_messages(uint8_t status_byte); void continous_start(); void continous_stop(); void reset_sensor(); diff --git a/Libraries/STEERING_RS422/STEERING_RS_422.cpp b/Libraries/STEERING_RS422/STEERING_RS_422.cpp index 8f664f9a..06ddf201 100644 --- a/Libraries/STEERING_RS422/STEERING_RS_422.cpp +++ b/Libraries/STEERING_RS422/STEERING_RS_422.cpp @@ -71,15 +71,33 @@ int16_t STEERING_RS422::read_steering_continous() { status = readByte[2]; Serial.println(encoder_position); - steering_position = encoder_position - zero_position ; + steering_position = encoder_position - zero_position; + + interpret_error_messages(status); //_serial->clear(); } - - - - return steering_position; } + +void STEERING_RS422::interpret_error_messages(uint8_t status_byte) { + if (status_byte & 0x80) { + Serial.println("Warning: Limit of lower ride height tolerance. Error: Signal amplitude too high."); + } + if (status_byte & 0x40) { + Serial.println("Warning: Limit of upper ride height tolerance. Error: Signal amplitude low."); + } + if (status_byte & 0x20) { + Serial.println("Warning: The readhead temperature is out of specified range."); + } + if (status_byte & 0x10) { + Serial.println("Warning: Speed too high."); + } + if (status_byte & 0x08) { + Serial.println("Error: Multiturn counter error."); + } +} + + void STEERING_RS422::set_zero_position(uint16_t new_zero_position) { zero_position = new_zero_position; } diff --git a/Utilities/steering_rs422_testing/steering_rs422_testing.ino b/Utilities/steering_rs422_testing/steering_rs422_testing.ino index b5ff76a7..fbd32aa1 100644 --- a/Utilities/steering_rs422_testing/steering_rs422_testing.ino +++ b/Utilities/steering_rs422_testing/steering_rs422_testing.ino @@ -2,7 +2,7 @@ #include "STEERING_RS422.h" #include "Metro.h" -//STEERING_RS422 steering(5); +STEERING_RS422 steering(5); Metro read_steering_timer(20); void setup() { // put your setup code here, to run once: @@ -15,7 +15,9 @@ void setup() { } bool out; void loop() { - if (read_steering_timer.check()) { + if (read_steering_timer.check()) { + + steering.read_steering(); Serial5.write(0x33); if (Serial5.available()) { char position_high = Serial5.read(); From 8010120feb68df209c7d5e111aceeddb2a473352 Mon Sep 17 00:00:00 2001 From: imix8 <112455598+imix8@users.noreply.github.com> Date: Tue, 16 Jan 2024 23:24:32 -0500 Subject: [PATCH 08/15] Implemented +/- steering sensor, additional functionality needs to be tested. --- Libraries/STEERING_RS422/STEERING_RS422.h | 8 ++-- Libraries/STEERING_RS422/STEERING_RS_422.cpp | 40 ++++++++++--------- .../steering_rs422_testing.ino | 25 ++---------- 3 files changed, 30 insertions(+), 43 deletions(-) diff --git a/Libraries/STEERING_RS422/STEERING_RS422.h b/Libraries/STEERING_RS422/STEERING_RS422.h index 3942eb6d..8eeb578d 100644 --- a/Libraries/STEERING_RS422/STEERING_RS422.h +++ b/Libraries/STEERING_RS422/STEERING_RS422.h @@ -8,7 +8,7 @@ #define DEFAULT_HARDWARE_SERIAL 5 #define MAX_POSITION 8192 -#define ZERO_POSITION 8180 +#define ZERO_POSITION 0 class STEERING_RS422 { public: @@ -16,9 +16,9 @@ class STEERING_RS422 { STEERING_RS422(uint8_t serial); void init(unsigned long baudrate); int16_t read_steering(); - int16_t read_steering_continous(); + int16_t read_steering_continuous(); void request_status(); - uint16_t get_encoder_position() const { return encoder_position;}; + int16_t get_encoder_position() const { return encoder_position;}; void calibrate_steering(uint32_t pos); void command_sequence(); void save_parameters(); @@ -32,7 +32,7 @@ class STEERING_RS422 { private: static uint16_t buf; HardwareSerial* _serial; - uint16_t encoder_position; + int16_t encoder_position; bool error; bool warning; uint8_t status; diff --git a/Libraries/STEERING_RS422/STEERING_RS_422.cpp b/Libraries/STEERING_RS422/STEERING_RS_422.cpp index 06ddf201..e4b680ad 100644 --- a/Libraries/STEERING_RS422/STEERING_RS_422.cpp +++ b/Libraries/STEERING_RS422/STEERING_RS_422.cpp @@ -5,9 +5,8 @@ STEERING_RS422::STEERING_RS422() { STEERING_RS422(DEFAULT_HARDWARE_SERIAL); } -//Init STEERING_RS422 using configurable hadware serial port +//Init STEERING_RS422 using configurable hardware serial port STEERING_RS422::STEERING_RS422(uint8_t serial) { - switch (serial) { case 1: _serial = &Serial1; @@ -31,7 +30,6 @@ STEERING_RS422::STEERING_RS422(uint8_t serial) { _serial = &Serial7; break; case 8: - //_serial = &Serial8; //not on teensy 4.0 break; } @@ -41,31 +39,33 @@ void STEERING_RS422::init(unsigned long baudrate) { _serial->begin(baudrate); this->set_zero_position(ZERO_POSITION); } + int16_t STEERING_RS422::read_steering() { request_status(); - //check if _serial is available and the first byte is ascii "d" - - return read_steering_continous(); + return read_steering_continuous(); } + void STEERING_RS422::request_status() { _serial->write(0x64); delay(1); } -int16_t STEERING_RS422::read_steering_continous() { - uint8_t readByte[3] = {0}; +int16_t STEERING_RS422::read_steering_continuous() { + uint8_t readByte[3] = {0}; //check if _serial is available and the first byte is ascii "d" if (_serial->available() >= 4 && _serial->read() == 0x64) { - - readByte[0] = _serial->read(); //lower half of steering - readByte[1] = _serial->read(); //upper half of steering - readByte[2] = _serial->read(); //error stream - encoder_position = readByte[0] << 6 | readByte[1] >> 2; + //between 1350 to -32757 to 23500 + //encoder position left aligned, MSB first + readByte[0] = _serial->read(); //encoder position b15-b8 of steering + readByte[1] = _serial->read(); //encoder position b7-b0 of steering + readByte[2] = _serial->read(); //detailed status b7-b0 + encoder_position = (int16_t)(((uint16_t)readByte[0]) << 8) | ((uint16_t)readByte[1]); + encoder_position = encoder_position >> 2; error = readByte[1] & 2; //if high, current data is not valid, previous data is sent warning = readByte[1] & 1; //if high, some operating conditions are close to limits status = readByte[2]; @@ -97,10 +97,10 @@ void STEERING_RS422::interpret_error_messages(uint8_t status_byte) { } } - void STEERING_RS422::set_zero_position(uint16_t new_zero_position) { zero_position = new_zero_position; } + void STEERING_RS422::calibrate_steering(uint32_t pos) { //start programming sequence //this sends data to essentially add a zero offset @@ -108,15 +108,19 @@ void STEERING_RS422::calibrate_steering(uint32_t pos) { command_sequence(); _serial->write(0x5A); delay(1); - _serial->write(pos &0xFF000000); + // _serial->write(pos &0xFF000000); + _serial->write(0); delay(1); - _serial->write(pos &0xFF0000); + // _serial->write(pos &0xFF0000); + _serial->write(0); delay(1); - _serial->write(pos &0xFF00); + // _serial->write(pos &0xFF00); + _serial->write(0x2C); delay(1); - _serial->write(pos & 0xFF); + _serial->write(0xFE); delay(1); } + void STEERING_RS422::command_sequence() { delay(1); _serial->write(0xCD); diff --git a/Utilities/steering_rs422_testing/steering_rs422_testing.ino b/Utilities/steering_rs422_testing/steering_rs422_testing.ino index fbd32aa1..21934fcf 100644 --- a/Utilities/steering_rs422_testing/steering_rs422_testing.ino +++ b/Utilities/steering_rs422_testing/steering_rs422_testing.ino @@ -10,29 +10,12 @@ void setup() { Serial5.begin(115200); //steering.init(115200); pinMode(13, OUTPUT); - - + steering.set_zero_position(0); + steering.calibrate_steering(0); } bool out; void loop() { if (read_steering_timer.check()) { - - steering.read_steering(); - Serial5.write(0x33); - if (Serial5.available()) { - char position_high = Serial5.read(); - char position_low_and_error_warning = Serial.read(); - uint16_t encoder_position = position_high << 6 | position_low_and_error_warning >> 2; - Serial.println(encoder_position); -// Serial.println(Serial5.read()); - } - -// //Serial.println(); -// steering.read_steering(); - } - - - - // put your main code here, to run repeatedly: - + steering.read_steering(); + } } From 2b5e243a1bb2e84272df325598be307e21cb8f77 Mon Sep 17 00:00:00 2001 From: imix8 <112455598+imix8@users.noreply.github.com> Date: Sun, 21 Jan 2024 21:31:22 -0500 Subject: [PATCH 09/15] Fix self calibration --- Libraries/STEERING_RS422/STEERING_RS422.h | 10 +-- Libraries/STEERING_RS422/STEERING_RS_422.cpp | 64 +++++++++++++------ .../steering_rs422_testing.ino | 15 +++-- 3 files changed, 60 insertions(+), 29 deletions(-) diff --git a/Libraries/STEERING_RS422/STEERING_RS422.h b/Libraries/STEERING_RS422/STEERING_RS422.h index 8eeb578d..2bd8d2e2 100644 --- a/Libraries/STEERING_RS422/STEERING_RS422.h +++ b/Libraries/STEERING_RS422/STEERING_RS422.h @@ -8,7 +8,6 @@ #define DEFAULT_HARDWARE_SERIAL 5 #define MAX_POSITION 8192 -#define ZERO_POSITION 0 class STEERING_RS422 { public: @@ -22,12 +21,14 @@ class STEERING_RS422 { void calibrate_steering(uint32_t pos); void command_sequence(); void save_parameters(); - void continous_setup(uint16_t period, bool auto_start); + void continuous_setup(uint16_t period, bool auto_start); void interpret_error_messages(uint8_t status_byte); - void continous_start(); - void continous_stop(); + void continuous_start(); + void continuous_stop(); void reset_sensor(); void set_zero_position(uint16_t new_zero_position); + void calculate_zero_position(); + uint16_t return_zero_position(); //uint8_t self_calibration(); private: static uint16_t buf; @@ -43,7 +44,6 @@ class STEERING_RS422 { r4 - Warning: Speed too high */ uint16_t zero_position; - int16_t steering_position; }; #endif \ No newline at end of file diff --git a/Libraries/STEERING_RS422/STEERING_RS_422.cpp b/Libraries/STEERING_RS422/STEERING_RS_422.cpp index e4b680ad..0dd9a0ee 100644 --- a/Libraries/STEERING_RS422/STEERING_RS_422.cpp +++ b/Libraries/STEERING_RS422/STEERING_RS_422.cpp @@ -37,7 +37,7 @@ STEERING_RS422::STEERING_RS422(uint8_t serial) { void STEERING_RS422::init(unsigned long baudrate) { _serial->begin(baudrate); - this->set_zero_position(ZERO_POSITION); + this->set_zero_position(zero_position); } int16_t STEERING_RS422::read_steering() { @@ -59,24 +59,21 @@ int16_t STEERING_RS422::read_steering_continuous() { uint8_t readByte[3] = {0}; //check if _serial is available and the first byte is ascii "d" if (_serial->available() >= 4 && _serial->read() == 0x64) { - //between 1350 to -32757 to 23500 //encoder position left aligned, MSB first readByte[0] = _serial->read(); //encoder position b15-b8 of steering readByte[1] = _serial->read(); //encoder position b7-b0 of steering readByte[2] = _serial->read(); //detailed status b7-b0 encoder_position = (int16_t)(((uint16_t)readByte[0]) << 8) | ((uint16_t)readByte[1]); - encoder_position = encoder_position >> 2; + encoder_position = encoder_position >> 2; //b1-b0 general status error = readByte[1] & 2; //if high, current data is not valid, previous data is sent warning = readByte[1] & 1; //if high, some operating conditions are close to limits status = readByte[2]; Serial.println(encoder_position); - - steering_position = encoder_position - zero_position; - + interpret_error_messages(status); //_serial->clear(); } - return steering_position; + return encoder_position; } void STEERING_RS422::interpret_error_messages(uint8_t status_byte) { @@ -101,26 +98,48 @@ void STEERING_RS422::set_zero_position(uint16_t new_zero_position) { zero_position = new_zero_position; } +void STEERING_RS422::calculate_zero_position() { + request_status(); + delay(5); + uint8_t readByte[3] = {0}; + //check if _serial is available and the first byte is ascii "d" + if (_serial->available() >= 4 && _serial->read() == 0x64) { + //encoder position left aligned, MSB first + readByte[0] = _serial->read(); //encoder position b15-b8 of steering + readByte[1] = _serial->read(); //encoder position b7-b0 of steering + readByte[2] = _serial->read(); //detailed status b7-b0 + set_zero_position(((readByte[0] << 8) | readByte[1]) >> 2); + Serial.println(((readByte[0] << 8) | readByte[1]) >> 2); + } +} + +uint16_t STEERING_RS422::return_zero_position() { + return zero_position; +} + void STEERING_RS422::calibrate_steering(uint32_t pos) { //start programming sequence //this sends data to essentially add a zero offset - //pos = 0x00000E18 + Serial.println(pos); command_sequence(); + //0x5A is programming command byte for position offset setting _serial->write(0x5A); delay(1); - // _serial->write(pos &0xFF000000); - _serial->write(0); + _serial->write((pos & 0xFF000000) >> 24); + //_serial->write(0); delay(1); - // _serial->write(pos &0xFF0000); - _serial->write(0); + _serial->write((pos & 0xFF0000) >> 16); + //_serial->write(0); delay(1); - // _serial->write(pos &0xFF00); - _serial->write(0x2C); + _serial->write((pos & 0xFF00) >> 8); + //_serial->write(0x2D); delay(1); - _serial->write(0xFE); + _serial->write(pos & 0xFF); + //_serial->write(0x12); delay(1); } +//Unlock sequence for self-calibration, must be followed by programming command byte void STEERING_RS422::command_sequence() { delay(1); _serial->write(0xCD); @@ -134,13 +153,16 @@ void STEERING_RS422::command_sequence() { } -void STEERING_RS422::continous_setup(uint16_t period, bool auto_start = 0) { +void STEERING_RS422::continuous_setup(uint16_t period, bool auto_start = 0) { command_sequence(); + //0x54 is programming command byte for continuous response setting _serial->write(0x54); delay(1); + //1 to enable automatic start after power on of encoder, 0 to disable _serial->write((auto_start) ? 0x01 : 0x00); delay(1); - _serial->write(0x64); + // 0x33 short position request + _serial->write(0x33); delay(1); //in microseconds _serial->write(period & 0xFF00); @@ -148,23 +170,27 @@ void STEERING_RS422::continous_setup(uint16_t period, bool auto_start = 0) { _serial->write(period & 0xFF); } -void STEERING_RS422::continous_start() { +void STEERING_RS422::continuous_start() { command_sequence(); + //0x53 programming command byte for continuous response start _serial->write(0x53); delay(1); } -void STEERING_RS422::continous_stop() { +void STEERING_RS422::continuous_stop() { command_sequence(); + //0x50 programming command byte for continuous response stop _serial->write(0x50); delay(1); } void STEERING_RS422::save_parameters() { command_sequence(); + //0x63 programming command byte for confiuration parameters save _serial->write(0x63); delay(1); } void STEERING_RS422::reset_sensor() { command_sequence(); + //0x72 programming command byte for configuration parameters reset _serial->write(0x72); delay(1); } diff --git a/Utilities/steering_rs422_testing/steering_rs422_testing.ino b/Utilities/steering_rs422_testing/steering_rs422_testing.ino index 21934fcf..997944b5 100644 --- a/Utilities/steering_rs422_testing/steering_rs422_testing.ino +++ b/Utilities/steering_rs422_testing/steering_rs422_testing.ino @@ -10,12 +10,17 @@ void setup() { Serial5.begin(115200); //steering.init(115200); pinMode(13, OUTPUT); + + //Reset zero position to 0 in order to return unaltered reading from read_steering_continous() steering.set_zero_position(0); - steering.calibrate_steering(0); + steering.calculate_zero_position(); + steering.calibrate_steering(steering.return_zero_position()); } -bool out; + +// Uncomment to save current baud rate, position offset, continuous-response settings (period, command, autostart enable command) +// steering.save_parameters(); void loop() { - if (read_steering_timer.check()) { - steering.read_steering(); - } + if (read_steering_timer.check()) { + steering.read_steering(); + } } From 0986ef70f8e0a306301aac3d2559e71fc7a51934 Mon Sep 17 00:00:00 2001 From: imix8 <112455598+imix8@users.noreply.github.com> Date: Tue, 23 Jan 2024 23:02:20 -0500 Subject: [PATCH 10/15] Finished steering sensor library testing .ino code details procedure on how to use the commented code to calibrate steering. --- Libraries/STEERING_RS422/STEERING_RS_422.cpp | 7 ++--- .../steering_rs422_testing.ino | 28 ++++++++++++++----- 2 files changed, 24 insertions(+), 11 deletions(-) diff --git a/Libraries/STEERING_RS422/STEERING_RS_422.cpp b/Libraries/STEERING_RS422/STEERING_RS_422.cpp index 0dd9a0ee..df297f0f 100644 --- a/Libraries/STEERING_RS422/STEERING_RS_422.cpp +++ b/Libraries/STEERING_RS422/STEERING_RS_422.cpp @@ -161,11 +161,10 @@ void STEERING_RS422::continuous_setup(uint16_t period, bool auto_start = 0) { //1 to enable automatic start after power on of encoder, 0 to disable _serial->write((auto_start) ? 0x01 : 0x00); delay(1); - // 0x33 short position request - _serial->write(0x33); + _serial->write(0x64); delay(1); //in microseconds - _serial->write(period & 0xFF00); + _serial->write(period & 0xFF00 >> 8); delay(1); _serial->write(period & 0xFF); @@ -184,7 +183,7 @@ void STEERING_RS422::continuous_stop() { } void STEERING_RS422::save_parameters() { command_sequence(); - //0x63 programming command byte for confiuration parameters save + //0x63 programming command byte for configuration parameters save _serial->write(0x63); delay(1); } diff --git a/Utilities/steering_rs422_testing/steering_rs422_testing.ino b/Utilities/steering_rs422_testing/steering_rs422_testing.ino index 997944b5..33329179 100644 --- a/Utilities/steering_rs422_testing/steering_rs422_testing.ino +++ b/Utilities/steering_rs422_testing/steering_rs422_testing.ino @@ -10,17 +10,31 @@ void setup() { Serial5.begin(115200); //steering.init(115200); pinMode(13, OUTPUT); - + + //Comment everything out below reset and reset the sensor. Then comment reset and uncomment everything in + //Block 1. Then comment Block 1 and uncomment everything after Block 2. This should be on three separate + //loads to the steering sensor. + //steering.reset_sensor(); + + + //Block 1 //Reset zero position to 0 in order to return unaltered reading from read_steering_continous() - steering.set_zero_position(0); - steering.calculate_zero_position(); - steering.calibrate_steering(steering.return_zero_position()); + //Uncomment next three lines to set wheel starting position to 0 on every power cycle, must put wheel as straight as possible + //steering.set_zero_position(0); + //steering.calculate_zero_position(); + //steering.calibrate_steering(steering.return_zero_position()); + //steering.continuous_setup(32767, 0); + //Uncomment to save current baud rate, position offset, continuous-response settings (period, command, autostart enable command) + //steering.save_parameters(); + + + //Block 2 + steering.continuous_start(); } -// Uncomment to save current baud rate, position offset, continuous-response settings (period, command, autostart enable command) -// steering.save_parameters(); void loop() { if (read_steering_timer.check()) { - steering.read_steering(); + steering.read_steering_continuous(); + //steering.read_steering(); } } From 91e4f7673f4a7f3a12eac4c75af0fd67e0078d2c Mon Sep 17 00:00:00 2001 From: Eric Galluzzi Date: Wed, 21 Feb 2024 14:20:26 -0500 Subject: [PATCH 11/15] some awful calibration test code --- Libraries/STEERING_RS422/STEERING_RS422.h | 3 +- Libraries/STEERING_RS422/STEERING_RS_422.cpp | 45 ++++++++++--------- .../steering_rs422_testing.ino | 25 +++++++---- 3 files changed, 44 insertions(+), 29 deletions(-) diff --git a/Libraries/STEERING_RS422/STEERING_RS422.h b/Libraries/STEERING_RS422/STEERING_RS422.h index 2bd8d2e2..ed5632a0 100644 --- a/Libraries/STEERING_RS422/STEERING_RS422.h +++ b/Libraries/STEERING_RS422/STEERING_RS422.h @@ -29,7 +29,8 @@ class STEERING_RS422 { void set_zero_position(uint16_t new_zero_position); void calculate_zero_position(); uint16_t return_zero_position(); - //uint8_t self_calibration(); + void self_calibration(); + uint8_t check_calibration_status(); private: static uint16_t buf; HardwareSerial* _serial; diff --git a/Libraries/STEERING_RS422/STEERING_RS_422.cpp b/Libraries/STEERING_RS422/STEERING_RS_422.cpp index df297f0f..e87437ca 100644 --- a/Libraries/STEERING_RS422/STEERING_RS_422.cpp +++ b/Libraries/STEERING_RS422/STEERING_RS_422.cpp @@ -194,42 +194,47 @@ void STEERING_RS422::reset_sensor() { delay(1); } -/* -uint8_t STEERING_RS422::self_calibration() { + +void STEERING_RS422::self_calibration() { + //b6 calibration alr performed //b3 calcualted params out of range //b2 timeout (no complete rotation) //b1 counter bit 1 //b0 counter bit 0 //check status - uint8_t status_flags = 0; //check if calubration was already performed - command_sequence(); - _serial->write(0x69); - delay(1); - if (_serial->available() && _serial->read() == 0x69) { - - status_flags = _serial->read(); - } - if (status_flags & 0b01000000) { - return status_flags; - } - + //command_sequence(); //self calibrate + Serial.println("calibrating"); command_sequence(); _serial->write(0x41); delay(10000); //10 sec delay() + Serial.println("calibration complete"); - //check status - command_sequence(); +} + +uint8_t STEERING_RS422::check_calibration_status() { + uint8_t status_flags = 0; _serial->write(0x69); delay(1); if (_serial->available() && _serial->read() == 0x69) { status_flags = _serial->read(); + } else { + return -1; + } + + if (status_flags & 0b01000000) { + Serial.println("already calibrated"); + + } + if (status_flags & 0b00001000) { + Serial.println("bad tolerance"); + } - //check if any errors if (status_flags & 0b0001100) { - return status_flags; + Serial.println("errors"); } - return 1; -} */ \ No newline at end of file + return status_flags; + +} \ No newline at end of file diff --git a/Utilities/steering_rs422_testing/steering_rs422_testing.ino b/Utilities/steering_rs422_testing/steering_rs422_testing.ino index 33329179..e345e732 100644 --- a/Utilities/steering_rs422_testing/steering_rs422_testing.ino +++ b/Utilities/steering_rs422_testing/steering_rs422_testing.ino @@ -4,12 +4,13 @@ STEERING_RS422 steering(5); Metro read_steering_timer(20); +uint8_t valid = -1; void setup() { // put your setup code here, to run once: - Serial.begin(9600); - Serial5.begin(115200); - //steering.init(115200); - pinMode(13, OUTPUT); + Serial.begin(115200); + //Serial5.begin(115200); + steering.init(115200); + //pinMode(13, OUTPUT); //Comment everything out below reset and reset the sensor. Then comment reset and uncomment everything in //Block 1. Then comment Block 1 and uncomment everything after Block 2. This should be on three separate @@ -22,19 +23,27 @@ void setup() { //Uncomment next three lines to set wheel starting position to 0 on every power cycle, must put wheel as straight as possible //steering.set_zero_position(0); //steering.calculate_zero_position(); - //steering.calibrate_steering(steering.return_zero_position()); + //steering.calibrate_ + //steering(steering.return_zero_position()); //steering.continuous_setup(32767, 0); //Uncomment to save current baud rate, position offset, continuous-response settings (period, command, autostart enable command) //steering.save_parameters(); + //steering.read //Block 2 - steering.continuous_start(); + //steering.continuous_start(); + Serial.println("get ready.."); + delay(500); + steering.save_parameters(); + //steering.self_calibration(); } void loop() { if (read_steering_timer.check()) { - steering.read_steering_continuous(); - //steering.read_steering(); + //steering.read_steering_continuous(); + Serial.println(steering.check_calibration_status(),BIN); + steering.read_steering(); + } } From 5b50e3d2d197c34211f8b205903b7787bfe2246a Mon Sep 17 00:00:00 2001 From: CL16gtgh Date: Fri, 22 Mar 2024 20:53:05 -0400 Subject: [PATCH 12/15] calibrate on HT08 --- Utilities/steering_rs422_testing/steering_rs422_testing.ino | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Utilities/steering_rs422_testing/steering_rs422_testing.ino b/Utilities/steering_rs422_testing/steering_rs422_testing.ino index e345e732..2143cbce 100644 --- a/Utilities/steering_rs422_testing/steering_rs422_testing.ino +++ b/Utilities/steering_rs422_testing/steering_rs422_testing.ino @@ -35,8 +35,11 @@ void setup() { //steering.continuous_start(); Serial.println("get ready.."); delay(500); + + steering.calibrate_steering(3933); steering.save_parameters(); - //steering.self_calibration(); + +// steering.self_calibration(); } void loop() { From c7b3b5c75f0e39cc8580cf565846235207ba2196 Mon Sep 17 00:00:00 2001 From: CL16gtgh Date: Wed, 15 May 2024 17:12:46 -0400 Subject: [PATCH 13/15] Weird calibration. Can't speak Orbis --- Libraries/STEERING_RS422/STEERING_RS_422.cpp | 5 +++++ .../steering_rs422_testing/steering_rs422_testing.ino | 9 +++++++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/Libraries/STEERING_RS422/STEERING_RS_422.cpp b/Libraries/STEERING_RS422/STEERING_RS_422.cpp index e87437ca..535fda56 100644 --- a/Libraries/STEERING_RS422/STEERING_RS_422.cpp +++ b/Libraries/STEERING_RS422/STEERING_RS_422.cpp @@ -65,10 +65,15 @@ int16_t STEERING_RS422::read_steering_continuous() { readByte[2] = _serial->read(); //detailed status b7-b0 encoder_position = (int16_t)(((uint16_t)readByte[0]) << 8) | ((uint16_t)readByte[1]); encoder_position = encoder_position >> 2; //b1-b0 general status + uint16_t encoder_position_raw = (((uint16_t)readByte[0]) << 8) | ((uint16_t)readByte[1]); + encoder_position_raw = encoder_position_raw >> 2; //b1-b0 general status error = readByte[1] & 2; //if high, current data is not valid, previous data is sent warning = readByte[1] & 1; //if high, some operating conditions are close to limits status = readByte[2]; + Serial.print("Signed interpretation: "); Serial.println(encoder_position); + Serial.print("Encoder raw reading: "); + Serial.println(encoder_position_raw); interpret_error_messages(status); //_serial->clear(); diff --git a/Utilities/steering_rs422_testing/steering_rs422_testing.ino b/Utilities/steering_rs422_testing/steering_rs422_testing.ino index 2143cbce..ed4b6a4a 100644 --- a/Utilities/steering_rs422_testing/steering_rs422_testing.ino +++ b/Utilities/steering_rs422_testing/steering_rs422_testing.ino @@ -34,10 +34,13 @@ void setup() { //Block 2 //steering.continuous_start(); Serial.println("get ready.."); + Serial.println(); delay(500); - steering.calibrate_steering(3933); - steering.save_parameters(); +// Serial.print("Calibrate offset position to: "); +// steering.calibrate_steering(11072); +// Serial.println("Saving parameter..."); +// steering.save_parameters(); // steering.self_calibration(); } @@ -45,8 +48,10 @@ void setup() { void loop() { if (read_steering_timer.check()) { //steering.read_steering_continuous(); + Serial.print("Check self-calibration status (idk why this is here tbh but): "); Serial.println(steering.check_calibration_status(),BIN); steering.read_steering(); + Serial.println(); } } From fe02db97a8b644a5f35c1f8010b0681732180dbc Mon Sep 17 00:00:00 2001 From: CL16gtgh Date: Wed, 5 Jun 2024 20:29:19 -0400 Subject: [PATCH 14/15] bruh. orbis is altism. --- Utilities/steering_rs422_testing/steering_rs422_testing.ino | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Utilities/steering_rs422_testing/steering_rs422_testing.ino b/Utilities/steering_rs422_testing/steering_rs422_testing.ino index ed4b6a4a..731f72b9 100644 --- a/Utilities/steering_rs422_testing/steering_rs422_testing.ino +++ b/Utilities/steering_rs422_testing/steering_rs422_testing.ino @@ -38,7 +38,7 @@ void setup() { delay(500); // Serial.print("Calibrate offset position to: "); -// steering.calibrate_steering(11072); +// steering.calibrate_steering(128); // Serial.println("Saving parameter..."); // steering.save_parameters(); From d71bdbd2025371a215178129f3517fd432da0af8 Mon Sep 17 00:00:00 2001 From: CL16gtgh Date: Thu, 6 Jun 2024 20:13:18 -0400 Subject: [PATCH 15/15] orbis cracked: set calibrate value to 0 first, read raw value when neutral steer, then set calibrate value to that raw reading --- Utilities/steering_rs422_testing/steering_rs422_testing.ino | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Utilities/steering_rs422_testing/steering_rs422_testing.ino b/Utilities/steering_rs422_testing/steering_rs422_testing.ino index 731f72b9..277b911c 100644 --- a/Utilities/steering_rs422_testing/steering_rs422_testing.ino +++ b/Utilities/steering_rs422_testing/steering_rs422_testing.ino @@ -36,9 +36,9 @@ void setup() { Serial.println("get ready.."); Serial.println(); delay(500); - +// // Serial.print("Calibrate offset position to: "); -// steering.calibrate_steering(128); +// steering.calibrate_steering(317); // Serial.println("Saving parameter..."); // steering.save_parameters();