From cafe0c5e56e45fbe106635da8551b872ed019f1c Mon Sep 17 00:00:00 2001 From: Jacob Perron Date: Mon, 26 Aug 2019 20:46:49 -0700 Subject: [PATCH] Add API for getting left and right cliff detections Signed-off-by: Jacob Perron --- include/create/create.h | 20 ++++++++++++++++++++ src/create.cpp | 40 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+) diff --git a/include/create/create.h b/include/create/create.h index 40196c4..4e03b61 100644 --- a/include/create/create.h +++ b/include/create/create.h @@ -366,6 +366,26 @@ namespace create { */ bool isCliff() const; + /** + * \return true if the left sensor detects a cliff, false otherwise. + */ + bool isCliffLeft() const; + + /** + * \return true if the front left sensor detects a cliff, false otherwise. + */ + bool isCliffFrontLeft() const; + + /** + * \return true if the right sensor detects a cliff, false otherwise. + */ + bool isCliffRight() const; + + /** + * \return true if the front right sensor detects a cliff, false otherwise. + */ + bool isCliffFrontRight() const; + /** * \return true if there is a virtual wall signal is being received. */ diff --git a/src/create.cpp b/src/create.cpp index 8279e2a..e71a556 100644 --- a/src/create.cpp +++ b/src/create.cpp @@ -663,6 +663,46 @@ namespace create { } } + bool Create::isCliffLeft() const { + if (data->isValidPacketID(ID_CLIFF_LEFT)) { + return GET_DATA(ID_CLIFF_LEFT) == 1; + } + else { + CERR("[create::Create] ", "Left cliff sensors not supported!"); + return false; + } + } + + bool Create::isCliffFrontLeft() const { + if (data->isValidPacketID(ID_CLIFF_FRONT_LEFT)) { + return GET_DATA(ID_CLIFF_FRONT_LEFT) == 1; + } + else { + CERR("[create::Create] ", "Front left cliff sensors not supported!"); + return false; + } + } + + bool Create::isCliffRight() const { + if (data->isValidPacketID(ID_CLIFF_RIGHT)) { + return GET_DATA(ID_CLIFF_RIGHT) == 1; + } + else { + CERR("[create::Create] ", "Rightt cliff sensors not supported!"); + return false; + } + } + + bool Create::isCliffFrontRight() const { + if (data->isValidPacketID(ID_CLIFF_FRONT_RIGHT)) { + return GET_DATA(ID_CLIFF_FRONT_RIGHT) == 1; + } + else { + CERR("[create::Create] ", "Front right cliff sensors not supported!"); + return false; + } + } + bool Create::isVirtualWall() const { if (data->isValidPacketID(ID_VIRTUAL_WALL)) { return GET_DATA(ID_VIRTUAL_WALL);