Fixed parenting
This commit is contained in:
parent
8ff0fdd78f
commit
045826d3c2
@ -9,11 +9,13 @@ namespace Arduino {
|
|||||||
uint8_t DRV8833Motor::nextAvailablePwmChannel = 0;
|
uint8_t DRV8833Motor::nextAvailablePwmChannel = 0;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
DRV8833Motor::DRV8833Motor(Participant* participant,
|
DRV8833Motor::DRV8833Motor(DRV8833* driver,
|
||||||
unsigned char pinIn1,
|
unsigned char pinIn1,
|
||||||
unsigned char pinIn2,
|
unsigned char pinIn2,
|
||||||
bool reverse)
|
bool reverse)
|
||||||
: Thing(participant) {
|
: Thing(driver->owner) {
|
||||||
|
this->parent = driver;
|
||||||
|
|
||||||
this->pinIn1 = pinIn1;
|
this->pinIn1 = pinIn1;
|
||||||
this->pinIn2 = pinIn2;
|
this->pinIn2 = pinIn2;
|
||||||
|
|
||||||
@ -120,11 +122,30 @@ DRV8833::DRV8833(Participant* participant,
|
|||||||
if (pinStandby != 255)
|
if (pinStandby != 255)
|
||||||
pinMode(pinStandby, OUTPUT);
|
pinMode(pinStandby, OUTPUT);
|
||||||
|
|
||||||
this->motorA = new DRV8833Motor(participant, pinAIn1, pinAIn2, reverseA);
|
this->motorA = new DRV8833Motor(this, pinAIn1, pinAIn2, reverseA);
|
||||||
this->motorA->name = "Motor A";
|
this->motorA->name = "Motor A";
|
||||||
this->motorB = new DRV8833Motor(participant, pinBIn1, pinBIn2, reverseB);
|
this->motorB = new DRV8833Motor(this, pinBIn1, pinBIn2, reverseB);
|
||||||
this->motorB->name = "Motor B";
|
this->motorB->name = "Motor B";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
DRV8833::DRV8833(Thing* parent,
|
||||||
|
unsigned char pinAIn1,
|
||||||
|
unsigned char pinAIn2,
|
||||||
|
unsigned char pinBIn1,
|
||||||
|
unsigned char pinBIn2,
|
||||||
|
unsigned char pinStandby,
|
||||||
|
bool reverseA,
|
||||||
|
bool reverseB)
|
||||||
|
: DRV8833(parent->owner,
|
||||||
|
pinAIn1,
|
||||||
|
pinAIn2,
|
||||||
|
pinBIn1,
|
||||||
|
pinBIn2,
|
||||||
|
pinStandby,
|
||||||
|
reverseA,
|
||||||
|
reverseB) {
|
||||||
|
this->parent = parent;
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace Arduino
|
} // namespace Arduino
|
||||||
} // namespace RoboidControl
|
} // namespace RoboidControl
|
@ -7,6 +7,42 @@
|
|||||||
namespace RoboidControl {
|
namespace RoboidControl {
|
||||||
namespace Arduino {
|
namespace Arduino {
|
||||||
|
|
||||||
|
class DRV8833Motor;
|
||||||
|
|
||||||
|
class DRV8833 : public Thing {
|
||||||
|
public:
|
||||||
|
/// @brief Setup a DRV8833 motor controller
|
||||||
|
/// @param pinAIn1 The pin number connected to the AIn1 port
|
||||||
|
/// @param pinAIn2 The pin number connected to the AIn2 port
|
||||||
|
/// @param pinBIn1 The pin number connected to the BIn1 port
|
||||||
|
/// @param pinBIn2 The pin number connceted to the BIn2 port
|
||||||
|
/// @param pinStandby The pin number connected to the standby port, 255
|
||||||
|
/// indicated that the port is not connected
|
||||||
|
/// @param reverseA The forward turning direction of motor A
|
||||||
|
/// @param reverseB The forward turning direction of motor B
|
||||||
|
DRV8833(Participant* participant,
|
||||||
|
unsigned char pinAIn1,
|
||||||
|
unsigned char pinAIn2,
|
||||||
|
unsigned char pinBIn1,
|
||||||
|
unsigned char pinBIn2,
|
||||||
|
unsigned char pinStandby = 255,
|
||||||
|
bool reverseA = false,
|
||||||
|
bool reverseB = false);
|
||||||
|
DRV8833(Thing* parent,
|
||||||
|
unsigned char pinAIn1,
|
||||||
|
unsigned char pinAIn2,
|
||||||
|
unsigned char pinBIn1,
|
||||||
|
unsigned char pinBIn2,
|
||||||
|
unsigned char pinStandby = 255,
|
||||||
|
bool reverseA = false,
|
||||||
|
bool reverseB = false);
|
||||||
|
DRV8833Motor* motorA = nullptr;
|
||||||
|
DRV8833Motor* motorB = nullptr;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
unsigned char pinStandby = 255;
|
||||||
|
};
|
||||||
|
|
||||||
/// @brief Support for a DRV8833 motor controller
|
/// @brief Support for a DRV8833 motor controller
|
||||||
class DRV8833Motor : public Thing {
|
class DRV8833Motor : public Thing {
|
||||||
public:
|
public:
|
||||||
@ -17,7 +53,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(DRV8833* driver,
|
||||||
unsigned char pinIn1,
|
unsigned char pinIn1,
|
||||||
unsigned char pinIn2,
|
unsigned char pinIn2,
|
||||||
bool reverse = false);
|
bool reverse = false);
|
||||||
@ -39,32 +75,5 @@ class DRV8833Motor : public Thing {
|
|||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
class DRV8833 : public Thing {
|
|
||||||
public:
|
|
||||||
/// @brief Setup a DRV8833 motor controller
|
|
||||||
/// @param pinAIn1 The pin number connected to the AIn1 port
|
|
||||||
/// @param pinAIn2 The pin number connected to the AIn2 port
|
|
||||||
/// @param pinBIn1 The pin number connected to the BIn1 port
|
|
||||||
/// @param pinBIn2 The pin number connceted to the BIn2 port
|
|
||||||
/// @param pinStandby The pin number connected to the standby port, 255
|
|
||||||
/// indicated that the port is not connected
|
|
||||||
/// @param reverseA The forward turning direction of motor A
|
|
||||||
/// @param reverseB The forward turning direction of motor B
|
|
||||||
DRV8833(Participant* participant,
|
|
||||||
unsigned char pinAIn1,
|
|
||||||
unsigned char pinAIn2,
|
|
||||||
unsigned char pinBIn1,
|
|
||||||
unsigned char pinBIn2,
|
|
||||||
unsigned char pinStandby = 255,
|
|
||||||
bool reverseA = false,
|
|
||||||
bool reverseB = false);
|
|
||||||
|
|
||||||
DRV8833Motor* motorA = nullptr;
|
|
||||||
DRV8833Motor* motorB = nullptr;
|
|
||||||
|
|
||||||
protected:
|
|
||||||
unsigned char pinStandby = 255;
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace Arduino
|
} // namespace Arduino
|
||||||
} // namespace RoboidControl
|
} // namespace RoboidControl
|
@ -16,6 +16,13 @@ UltrasonicSensor::UltrasonicSensor(Participant* participant,
|
|||||||
pinMode(pinEcho, INPUT); // configure the echo pin to input mode
|
pinMode(pinEcho, INPUT); // configure the echo pin to input mode
|
||||||
}
|
}
|
||||||
|
|
||||||
|
UltrasonicSensor::UltrasonicSensor(Thing* parent,
|
||||||
|
unsigned char pinTrigger,
|
||||||
|
unsigned char pinEcho)
|
||||||
|
: UltrasonicSensor(parent->owner, pinTrigger, pinEcho) {
|
||||||
|
this->parent = parent;
|
||||||
|
}
|
||||||
|
|
||||||
float UltrasonicSensor::GetDistance() {
|
float UltrasonicSensor::GetDistance() {
|
||||||
// Start the ultrasonic 'ping'
|
// Start the ultrasonic 'ping'
|
||||||
digitalWrite(pinTrigger, LOW);
|
digitalWrite(pinTrigger, LOW);
|
||||||
|
@ -8,6 +8,9 @@ namespace Arduino {
|
|||||||
/// @brief An HC-SR04 ultrasonic distance sensor
|
/// @brief An HC-SR04 ultrasonic distance sensor
|
||||||
class UltrasonicSensor : public TouchSensor {
|
class UltrasonicSensor : public TouchSensor {
|
||||||
public:
|
public:
|
||||||
|
// Inherit all constructors
|
||||||
|
using TouchSensor::TouchSensor;
|
||||||
|
|
||||||
/// @brief Setup an ultrasonic sensor
|
/// @brief Setup an ultrasonic sensor
|
||||||
/// @param participant The participant to use
|
/// @param participant The participant to use
|
||||||
/// @param pinTrigger The pin number of the trigger signal
|
/// @param pinTrigger The pin number of the trigger signal
|
||||||
@ -15,6 +18,9 @@ class UltrasonicSensor : public TouchSensor {
|
|||||||
UltrasonicSensor(Participant* participant,
|
UltrasonicSensor(Participant* participant,
|
||||||
unsigned char pinTrigger,
|
unsigned char pinTrigger,
|
||||||
unsigned char pinEcho);
|
unsigned char pinEcho);
|
||||||
|
UltrasonicSensor(Thing* parent,
|
||||||
|
unsigned char pinTrigger,
|
||||||
|
unsigned char pinEcho);
|
||||||
|
|
||||||
// parameters
|
// parameters
|
||||||
|
|
||||||
|
@ -179,12 +179,13 @@ void ParticipantUDP::SendThingInfo(Participant* remoteParticipant,
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool ParticipantUDP::Send(Participant* remoteParticipant, IMessage* msg) {
|
bool ParticipantUDP::Send(Participant* remoteParticipant, IMessage* msg) {
|
||||||
// std::cout << "send msg " << (int)this->buffer[0] << " to "
|
|
||||||
// << remoteParticipant->ipAddress << std::endl;
|
|
||||||
int bufferSize = msg->Serialize(this->buffer);
|
int bufferSize = msg->Serialize(this->buffer);
|
||||||
if (bufferSize <= 0)
|
if (bufferSize <= 0)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
|
std::cout << "send msg " << (int)this->buffer[0] << " to "
|
||||||
|
<< remoteParticipant->ipAddress << std::endl;
|
||||||
|
|
||||||
#if defined(_WIN32) || defined(_WIN64)
|
#if defined(_WIN32) || defined(_WIN64)
|
||||||
Windows::ParticipantUDP* thisWindows =
|
Windows::ParticipantUDP* thisWindows =
|
||||||
static_cast<Windows::ParticipantUDP*>(this);
|
static_cast<Windows::ParticipantUDP*>(this);
|
||||||
@ -227,7 +228,7 @@ void ParticipantUDP::PublishThingInfo(Thing* thing) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool ParticipantUDP::Publish(IMessage* msg) {
|
bool ParticipantUDP::Publish(IMessage* msg) {
|
||||||
// std::cout << "publish msg\n";
|
std::cout << "publish msg\n";
|
||||||
#if defined(_WIN32) || defined(_WIN64)
|
#if defined(_WIN32) || defined(_WIN64)
|
||||||
Windows::ParticipantUDP* thisWindows =
|
Windows::ParticipantUDP* thisWindows =
|
||||||
static_cast<Windows::ParticipantUDP*>(this);
|
static_cast<Windows::ParticipantUDP*>(this);
|
||||||
|
10
Thing.cpp
10
Thing.cpp
@ -42,8 +42,14 @@ Thing::Thing(Participant* owner, int thingType, unsigned char thingId) {
|
|||||||
this->angularVelocity = Spherical::zero;
|
this->angularVelocity = Spherical::zero;
|
||||||
|
|
||||||
// std::cout << "add thing [" << (int)this->id << "] to owner "
|
// std::cout << "add thing [" << (int)this->id << "] to owner "
|
||||||
// << this->owner->ipAddress << ":" << this->owner->port << std::endl;
|
// << this->owner->ipAddress << ":" << this->owner->port <<
|
||||||
this->owner->Add(this, false);
|
// std::endl;
|
||||||
|
this->owner->Add(this, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
Thing::Thing(Thing* parent, int thingType, unsigned char thingId)
|
||||||
|
: Thing(parent->owner, thingType, thingId) {
|
||||||
|
this->parent = parent;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Thing::Thing(Participant* owner,
|
// Thing::Thing(Participant* owner,
|
||||||
|
1
Thing.h
1
Thing.h
@ -58,6 +58,7 @@ class Thing {
|
|||||||
// unsigned char networkId,
|
// unsigned char networkId,
|
||||||
// unsigned char thingId,
|
// unsigned char thingId,
|
||||||
// Type thingType = Type::Undetermined);
|
// Type thingType = Type::Undetermined);
|
||||||
|
Thing(Thing* parent, int thingType = 0, unsigned char thingId = 0);
|
||||||
|
|
||||||
/// @brief The participant managing this thing
|
/// @brief The participant managing this thing
|
||||||
Participant* owner;
|
Participant* owner;
|
||||||
|
@ -7,6 +7,9 @@ namespace RoboidControl {
|
|||||||
/// @brief A sensor which can detect touches
|
/// @brief A sensor which can detect touches
|
||||||
class TouchSensor : public Thing {
|
class TouchSensor : public Thing {
|
||||||
public:
|
public:
|
||||||
|
// Inherit all constructors
|
||||||
|
using Thing::Thing;
|
||||||
|
|
||||||
/// @brief Create a touch sensor with isolated participant
|
/// @brief Create a touch sensor with isolated participant
|
||||||
TouchSensor();
|
TouchSensor();
|
||||||
/// @brief Create a touch sensor
|
/// @brief Create a touch sensor
|
||||||
|
Loading…
x
Reference in New Issue
Block a user