Merge commit '7e95d8957905a7f913e8d420cbaa05f4ba815c7d' into ControlCore

This commit is contained in:
Pascal Serrarens 2025-03-04 17:07:57 +01:00
commit f6f47d99ab
6 changed files with 38 additions and 16 deletions

View File

@ -3,9 +3,10 @@
#include "Thing.h" #include "Thing.h"
#include "Things/DifferentialDrive.h" #include "Things/DifferentialDrive.h"
/// @brief Support for a DRV8833 motor controller
namespace RoboidControl { namespace RoboidControl {
namespace Arduino {
/// @brief Support for a DRV8833 motor controller
class DRV8833Motor : public Thing { class DRV8833Motor : public Thing {
public: public:
/// @brief Motor turning direction /// @brief Motor turning direction
@ -15,10 +16,7 @@ class DRV8833Motor : public Thing {
/// @param pinIn1 the pin number for the in1 signal /// @param pinIn1 the pin number for the in1 signal
/// @param pinIn2 the pin number for the in2 signal /// @param pinIn2 the pin number for the in2 signal
/// @param direction the forward turning direction of the motor /// @param direction the forward turning direction of the motor
DRV8833Motor(Participant* participant, DRV8833Motor(Participant* participant, unsigned char pinIn1, unsigned char pinIn2, bool reverse = false);
unsigned char pinIn1,
unsigned char pinIn2,
bool reverse = false);
void SetMaxRPM(unsigned int rpm); void SetMaxRPM(unsigned int rpm);
virtual void SetAngularVelocity(Spherical velocity) override; virtual void SetAngularVelocity(Spherical velocity) override;
@ -58,4 +56,5 @@ class DRV8833 : public Thing {
unsigned char pinStandby = 255; unsigned char pinStandby = 255;
}; };
} // namespace Arduino
} // namespace RoboidControl } // namespace RoboidControl

View File

@ -5,13 +5,19 @@
namespace RoboidControl { namespace RoboidControl {
namespace Arduino { namespace Arduino {
/// @brief A digital input represents the stat of a digital GPIO pin
class DigitalInput : public TouchSensor { class DigitalInput : public TouchSensor {
public: public:
/// @brief Create a new digital input
/// @param participant The participant to use
/// @param pin The digital pin
DigitalInput(Participant* participant, unsigned char pin); DigitalInput(Participant* participant, unsigned char pin);
/// @copydoc RoboidControl::Thing::Update(unsigned long currentTimeMs)
virtual void Update(unsigned long currentTimeMs) override; virtual void Update(unsigned long currentTimeMs) override;
protected: protected:
/// @brief The pin used for digital input
unsigned char pin = 0; unsigned char pin = 0;
}; };

View File

@ -5,25 +5,35 @@
namespace RoboidControl { namespace RoboidControl {
namespace Arduino { namespace Arduino {
/// @brief An HC-SR04 ultrasonic distance sensor
class UltrasonicSensor : public TouchSensor { class UltrasonicSensor : public TouchSensor {
public: public:
/// @brief Setup an ultrasonic sensor
/// @param participant The participant to use
/// @param pinTrigger The pin number of the trigger signal
/// @param pinEcho The pin number of the echo signal
UltrasonicSensor(Participant* participant, unsigned char pinTrigger, unsigned char pinEcho); UltrasonicSensor(Participant* participant, unsigned char pinTrigger, unsigned char pinEcho);
// parameters // parameters
/// @brief The distance at which the object is considered to be touched
float touchDistance = 0.2f; float touchDistance = 0.2f;
// state // state
/// @brief The last read distance
float distance = 0; float distance = 0;
/// @brief erform an ultrasonic 'ping' to determine the distance to the nearest object
/// @return the measured distance in meters to the nearest object
float GetDistance(); float GetDistance();
/// @copydoc RoboidControl::Thing::Update(unsigned long currentTimeMs)
virtual void Update(unsigned long currentTimeMs) override; virtual void Update(unsigned long currentTimeMs) override;
// virtual void ProcessBinary(char* bytes) override;
protected: protected:
/// @brief The pin number of the trigger signal
unsigned char pinTrigger = 0; unsigned char pinTrigger = 0;
/// @brief The pin number of the echo signal
unsigned char pinEcho = 0; unsigned char pinEcho = 0;
}; };

View File

@ -31,8 +31,9 @@ namespace RoboidControl {
/// An participant can be isolated. In that case it is standalong and does not communicate with other participants. /// An participant can be isolated. In that case it is standalong and does not communicate with other participants.
/// ///
/// It is possible to work with an hidden participant by creating things without specifying a participant in the /// It is possible to work with an hidden participant by creating things without specifying a participant in the
/// constructor (@sa RoboidControl::Thing::Thing()). In that case an hidden isolated participant is created which can be /// constructor. In that case an hidden isolated participant is created which can be
/// obtained using RoboidControl::LocalParticipant::Isolated(). /// obtained using RoboidControl::LocalParticipant::Isolated().
/// @sa RoboidControl::Thing::Thing()
class LocalParticipant : public Participant { class LocalParticipant : public Participant {
public: public:
/// @brief Create a participant without connecting to a site /// @brief Create a participant without connecting to a site

View File

@ -30,9 +30,5 @@ unsigned char BinaryMsg::Serialize(char* buffer) {
return ix; return ix;
} }
BinaryMsg BinaryMsg::Receive(char* buffer, unsigned char bufferSize) {
BinaryMsg msg = BinaryMsg(buffer);
return msg;
}
} // namespace RoboidControl } // namespace RoboidControl

View File

@ -4,25 +4,35 @@
namespace RoboidControl { namespace RoboidControl {
/// @brief Message to send thing-specific data
class BinaryMsg : public IMessage { class BinaryMsg : public IMessage {
public: public:
/// @brief The message ID
static const unsigned char id = 0xB1; static const unsigned char id = 0xB1;
/// @brief The length of the message without the binary data itslef
static const unsigned length = 3; static const unsigned length = 3;
/// @brief The network ID of the thing
unsigned char networkId; unsigned char networkId;
/// @brief The ID of the thing
unsigned char thingId; unsigned char thingId;
/// @brief The thing for which the binary data is communicated
Thing* thing; Thing* thing;
unsigned char bytesSize; /// @brief The binary data which is communicated
char* bytes = nullptr; char* bytes = nullptr;
BinaryMsg(char* buffer); /// @brief Create a new message for sending
/// @param networkId The network ID of the thing
/// @param thing The thing for which binary data is sent
BinaryMsg(unsigned char networkId, Thing* thing); BinaryMsg(unsigned char networkId, Thing* thing);
/// @copydoc RoboidControl::IMessage::IMessage(char*)
BinaryMsg(char* buffer);
/// @brief Destructor for the message
virtual ~BinaryMsg(); virtual ~BinaryMsg();
/// @copydoc RoboidControl::IMessage::Serialize
virtual unsigned char Serialize(char* buffer) override; virtual unsigned char Serialize(char* buffer) override;
static BinaryMsg Receive(char* buffer, unsigned char bufferSize);
}; };
} // namespace RoboidControl } // namespace RoboidControl