From 379799864a8d088947aba298a2fe57a3ddde9fec Mon Sep 17 00:00:00 2001 From: DuSack1220 Date: Sat, 4 Feb 2023 17:03:31 +0100 Subject: [PATCH 1/4] added cliff sensor signals --- include/create/create.h | 20 ++++++++++++++++++++ src/create.cpp | 40 ++++++++++++++++++++++++++++++++++++++++ src/data.cpp | 4 ++++ 3 files changed, 64 insertions(+) diff --git a/include/create/create.h b/include/create/create.h index 619205f..80beee3 100644 --- a/include/create/create.h +++ b/include/create/create.h @@ -406,6 +406,26 @@ namespace create { */ bool isCliffFrontRight() const; + /** + * \return true if the left sensor detects a cliff, false otherwise. + */ + uint16_t getCliffSignalLeft() const; + + /** + * \return true if the front left sensor detects a cliff, false otherwise. + */ + uint16_t getCliffSignalFrontLeft() const; + + /** + * \return true if the right sensor detects a cliff, false otherwise. + */ + uint16_t getCliffSignalRight() const; + + /** + * \return true if the front right sensor detects a cliff, false otherwise. + */ + uint16_t getCliffSignalFrontRight() const; + /** * \return true if there is a virtual wall signal is being received. */ diff --git a/src/create.cpp b/src/create.cpp index 0517b4a..72dbd26 100644 --- a/src/create.cpp +++ b/src/create.cpp @@ -738,6 +738,46 @@ namespace create { } } + uint16_t Create::getCliffSignalLeft() const { + if (data->isValidPacketID(ID_CLIFF_LEFT)) { + return GET_DATA(ID_CLIFF_LEFT_SIGNAL); + } + else { + CERR("[create::Create] ", "Left cliff sensor signals not supported!"); + return false; + } + } + + uint16_t Create::getCliffSignalFrontLeft() const { + if (data->isValidPacketID(ID_CLIFF_FRONT_LEFT)) { + return GET_DATA(ID_CLIFF_FRONT_LEFT_SIGNAL); + } + else { + CERR("[create::Create] ", "Front left cliff sensor signals not supported!"); + return false; + } + } + + uint16_t Create::getCliffSignalRight() const { + if (data->isValidPacketID(ID_CLIFF_RIGHT)) { + return GET_DATA(ID_CLIFF_RIGHT_SIGNAL); + } + else { + CERR("[create::Create] ", "Rightt cliff sensor signals not supported!"); + return false; + } + } + + uint16_t Create::getCliffSignalFrontRight() const { + if (data->isValidPacketID(ID_CLIFF_FRONT_RIGHT)) { + return GET_DATA(ID_CLIFF_FRONT_RIGHT_SIGNAL); + } + else { + CERR("[create::Create] ", "Front right cliff sensor signals not supported!"); + return false; + } + } + bool Create::isVirtualWall() const { if (data->isValidPacketID(ID_VIRTUAL_WALL)) { return GET_DATA(ID_VIRTUAL_WALL); diff --git a/src/data.cpp b/src/data.cpp index 5e8acce..be20717 100644 --- a/src/data.cpp +++ b/src/data.cpp @@ -16,6 +16,10 @@ namespace create { ADD_PACKET(ID_CLIFF_FRONT_LEFT, 1, "cliff_front_left", V_ALL); ADD_PACKET(ID_CLIFF_FRONT_RIGHT, 1, "cliff_front_right", V_ALL); ADD_PACKET(ID_CLIFF_RIGHT, 1, "cliff_right", V_ALL); + ADD_PACKET(ID_CLIFF_LEFT_SIGNAL, 2, "cliff_left_signal", V_3); + ADD_PACKET(ID_CLIFF_FRONT_LEFT_SIGNAL, 2, "cliff_front_left_signal", V_3); + ADD_PACKET(ID_CLIFF_FRONT_RIGHT_SIGNAL, 2, "cliff_front_right_signal", V_3); + ADD_PACKET(ID_CLIFF_RIGHT_SIGNAL, 2, "cliff_right_signal", V_3); ADD_PACKET(ID_VIRTUAL_WALL, 1, "virtual_wall", V_ALL); ADD_PACKET(ID_OVERCURRENTS, 1, "overcurrents", V_ALL); ADD_PACKET(ID_DIRT_DETECT_LEFT, 1, "dirt_detect_left", V_ALL); -- 2.47.2 From f9f3a2873559995f1585f9fe5c489044cef192e9 Mon Sep 17 00:00:00 2001 From: DuSack1220 Date: Mon, 13 Mar 2023 23:49:10 +0100 Subject: [PATCH 2/4] fixed encoder overflow --- src/create.cpp | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/create.cpp b/src/create.cpp index 72dbd26..f6bd595 100644 --- a/src/create.cpp +++ b/src/create.cpp @@ -156,17 +156,23 @@ namespace create { // Compute ticks since last update int ticksLeft = totalTicksLeft - prevTicksLeft; int ticksRight = totalTicksRight - prevTicksRight; - prevTicksLeft = totalTicksLeft; - prevTicksRight = totalTicksRight; // Handle wrap around - if (std::abs(ticksLeft) > 0.9 * util::V_3_MAX_ENCODER_TICKS) { - ticksLeft = (ticksLeft % util::V_3_MAX_ENCODER_TICKS) + 1; + if (ticksLeft > 0.9 * util::V_3_MAX_ENCODER_TICKS) { + ticksLeft = 2 * util::V_3_MAX_ENCODER_TICKS + prevTicksLeft - ticksLeft; + } else if (ticksLeft < 0.9 * -util::V_3_MAX_ENCODER_TICKS) { + ticksLeft = util::V_3_MAX_ENCODER_TICKS - prevTicksLeft + util::V_3_MAX_ENCODER_TICKS + ticksLeft; } - if (std::abs(ticksRight) > 0.9 * util::V_3_MAX_ENCODER_TICKS) { - ticksRight = (ticksRight % util::V_3_MAX_ENCODER_TICKS) + 1; + + if (ticksRight > 0.9 * util::V_3_MAX_ENCODER_TICKS) { + ticksRight = util::V_3_MAX_ENCODER_TICKS + prevTicksRight + util::V_3_MAX_ENCODER_TICKS - ticksRight; + } else if (ticksLeft < 0.9 * -util::V_3_MAX_ENCODER_TICKS) { + ticksRight = util::V_3_MAX_ENCODER_TICKS - prevTicksRight + util::V_3_MAX_ENCODER_TICKS + ticksRight; } + prevTicksLeft = totalTicksLeft; + prevTicksRight = totalTicksRight; + // Compute distance travelled by each wheel leftWheelDist = (ticksLeft / util::V_3_TICKS_PER_REV) * model.getWheelDiameter() * util::PI; -- 2.47.2 From 2bbcee117e9308b2db20b3ad3c78510b907cee37 Mon Sep 17 00:00:00 2001 From: Bernhard Klauninger Date: Wed, 15 Mar 2023 13:14:06 +0100 Subject: [PATCH 3/4] Actually fixed wrap around --- src/create.cpp | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/create.cpp b/src/create.cpp index f6bd595..87c12c9 100644 --- a/src/create.cpp +++ b/src/create.cpp @@ -157,18 +157,18 @@ namespace create { int ticksLeft = totalTicksLeft - prevTicksLeft; int ticksRight = totalTicksRight - prevTicksRight; - // Handle wrap around - if (ticksLeft > 0.9 * util::V_3_MAX_ENCODER_TICKS) { - ticksLeft = 2 * util::V_3_MAX_ENCODER_TICKS + prevTicksLeft - ticksLeft; - } else if (ticksLeft < 0.9 * -util::V_3_MAX_ENCODER_TICKS) { - ticksLeft = util::V_3_MAX_ENCODER_TICKS - prevTicksLeft + util::V_3_MAX_ENCODER_TICKS + ticksLeft; - } + // Handle wrap around + if (ticksLeft > 0.9 * util::V_3_MAX_ENCODER_TICKS) { + ticksLeft -= util::V_3_MAX_ENCODER_TICKS; + } else if (ticksLeft < -0.9 * util::V_3_MAX_ENCODER_TICKS) { + ticksLeft += util::V_3_MAX_ENCODER_TICKS; + } - if (ticksRight > 0.9 * util::V_3_MAX_ENCODER_TICKS) { - ticksRight = util::V_3_MAX_ENCODER_TICKS + prevTicksRight + util::V_3_MAX_ENCODER_TICKS - ticksRight; - } else if (ticksLeft < 0.9 * -util::V_3_MAX_ENCODER_TICKS) { - ticksRight = util::V_3_MAX_ENCODER_TICKS - prevTicksRight + util::V_3_MAX_ENCODER_TICKS + ticksRight; - } + if (ticksRight > 0.9 * util::V_3_MAX_ENCODER_TICKS) { + ticksRight -= util::V_3_MAX_ENCODER_TICKS; + } else if (ticksRight < -0.9 * util::V_3_MAX_ENCODER_TICKS) { + ticksRight += util::V_3_MAX_ENCODER_TICKS; + } prevTicksLeft = totalTicksLeft; prevTicksRight = totalTicksRight; -- 2.47.2 From 057fc1d2e76d94928892c291ec228ae18d995095 Mon Sep 17 00:00:00 2001 From: DuSack1220 Date: Wed, 15 Mar 2023 15:28:46 +0100 Subject: [PATCH 4/4] fixed cliff signal documentation --- include/create/create.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/include/create/create.h b/include/create/create.h index 80beee3..512d264 100644 --- a/include/create/create.h +++ b/include/create/create.h @@ -407,22 +407,22 @@ namespace create { bool isCliffFrontRight() const; /** - * \return true if the left sensor detects a cliff, false otherwise. + * \return the IR value of the left cliff sensor. */ uint16_t getCliffSignalLeft() const; /** - * \return true if the front left sensor detects a cliff, false otherwise. + * \return the IR value of the front left cliff sensor. */ uint16_t getCliffSignalFrontLeft() const; /** - * \return true if the right sensor detects a cliff, false otherwise. + * \return the IR value of the right cliff sensor. */ uint16_t getCliffSignalRight() const; /** - * \return true if the front right sensor detects a cliff, false otherwise. + * \return the IR value of the front right cliff sensor. */ uint16_t getCliffSignalFrontRight() const; -- 2.47.2