Robot ant works
This commit is contained in:
parent
990100e0ae
commit
a1a6941a28
@ -7,7 +7,7 @@ namespace RoboidControl {
|
|||||||
DRV8833Motor::DRV8833Motor(Participant* participant,
|
DRV8833Motor::DRV8833Motor(Participant* participant,
|
||||||
unsigned char pinIn1,
|
unsigned char pinIn1,
|
||||||
unsigned char pinIn2,
|
unsigned char pinIn2,
|
||||||
RotationDirection direction)
|
bool reverse)
|
||||||
: Thing(participant) {
|
: Thing(participant) {
|
||||||
this->pinIn1 = pinIn1;
|
this->pinIn1 = pinIn1;
|
||||||
this->pinIn2 = pinIn2;
|
this->pinIn2 = pinIn2;
|
||||||
@ -24,7 +24,7 @@ DRV8833Motor::DRV8833Motor(Participant* participant,
|
|||||||
pinMode(pinIn2, OUTPUT); // configure the in1 pin to output mode
|
pinMode(pinIn2, OUTPUT); // configure the in1 pin to output mode
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
this->direction = direction;
|
this->reverse = reverse;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DRV8833Motor::SetMaxRPM(unsigned int rpm) {
|
void DRV8833Motor::SetMaxRPM(unsigned int rpm) {
|
||||||
@ -46,9 +46,11 @@ void DRV8833Motor::SetAngularVelocity(Spherical velocity) {
|
|||||||
// Determine the rotation direction
|
// Determine the rotation direction
|
||||||
if (velocity.direction.horizontal.InDegrees() < 0)
|
if (velocity.direction.horizontal.InDegrees() < 0)
|
||||||
motorSpeed = -motorSpeed;
|
motorSpeed = -motorSpeed;
|
||||||
|
if (this->reverse)
|
||||||
|
motorSpeed =-motorSpeed;
|
||||||
|
|
||||||
std::cout << "ang speed " << this->name << " = " << angularSpeed << " rpm " << rpm
|
// std::cout << "ang speed " << this->name << " = " << angularSpeed << " rpm " << rpm
|
||||||
<< ", motor signal = " << (int)motorSignal << "\n";
|
// << ", motor signal = " << (int)motorSignal << "\n";
|
||||||
|
|
||||||
#if (ESP32)
|
#if (ESP32)
|
||||||
if (motorSpeed == 0) { // stop
|
if (motorSpeed == 0) { // stop
|
||||||
@ -103,16 +105,16 @@ DRV8833::DRV8833(Participant* participant,
|
|||||||
unsigned char pinBIn1,
|
unsigned char pinBIn1,
|
||||||
unsigned char pinBIn2,
|
unsigned char pinBIn2,
|
||||||
unsigned char pinStandby,
|
unsigned char pinStandby,
|
||||||
DRV8833Motor::RotationDirection directionA,
|
bool reverseA,
|
||||||
DRV8833Motor::RotationDirection directionB)
|
bool reverseB)
|
||||||
: Thing(participant) {
|
: Thing(participant) {
|
||||||
this->pinStandby = pinStandby;
|
this->pinStandby = pinStandby;
|
||||||
if (pinStandby != 255)
|
if (pinStandby != 255)
|
||||||
pinMode(pinStandby, OUTPUT);
|
pinMode(pinStandby, OUTPUT);
|
||||||
|
|
||||||
this->motorA = new DRV8833Motor(participant, pinAIn1, pinAIn2, directionA);
|
this->motorA = new DRV8833Motor(participant, pinAIn1, pinAIn2, reverseA);
|
||||||
this->motorA->name = "Motor A";
|
this->motorA->name = "Motor A";
|
||||||
this->motorB = new DRV8833Motor(participant, pinBIn1, pinBIn2, directionB);
|
this->motorB = new DRV8833Motor(participant, pinBIn1, pinBIn2, reverseB);
|
||||||
this->motorB->name = "Motor B";
|
this->motorB->name = "Motor B";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -18,15 +18,16 @@ class DRV8833Motor : public Thing {
|
|||||||
DRV8833Motor(Participant* participant,
|
DRV8833Motor(Participant* participant,
|
||||||
unsigned char pinIn1,
|
unsigned char pinIn1,
|
||||||
unsigned char pinIn2,
|
unsigned char pinIn2,
|
||||||
RotationDirection direction = RotationDirection::Clockwise);
|
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;
|
||||||
|
|
||||||
|
bool reverse = false;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
unsigned char pinIn1 = 255;
|
unsigned char pinIn1 = 255;
|
||||||
unsigned char pinIn2 = 255;
|
unsigned char pinIn2 = 255;
|
||||||
RotationDirection direction = RotationDirection::Clockwise;
|
|
||||||
unsigned int maxRpm = 200;
|
unsigned int maxRpm = 200;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -39,16 +40,16 @@ class DRV8833 : public Thing {
|
|||||||
/// @param pinBIn2 The pin number connceted to the BIn2 port
|
/// @param pinBIn2 The pin number connceted to the BIn2 port
|
||||||
/// @param pinStandby The pin number connected to the standby port, 255
|
/// @param pinStandby The pin number connected to the standby port, 255
|
||||||
/// indicated that the port is not connected
|
/// indicated that the port is not connected
|
||||||
/// @param directionA The forward turning direction of motor A
|
/// @param reverseA The forward turning direction of motor A
|
||||||
/// @param directionB The forward turning direction of motor B
|
/// @param reverseB The forward turning direction of motor B
|
||||||
DRV8833(Participant* participant,
|
DRV8833(Participant* participant,
|
||||||
unsigned char pinAIn1,
|
unsigned char pinAIn1,
|
||||||
unsigned char pinAIn2,
|
unsigned char pinAIn2,
|
||||||
unsigned char pinBIn1,
|
unsigned char pinBIn1,
|
||||||
unsigned char pinBIn2,
|
unsigned char pinBIn2,
|
||||||
unsigned char pinStandby = 255,
|
unsigned char pinStandby = 255,
|
||||||
DRV8833Motor::RotationDirection directionA = DRV8833Motor::RotationDirection::Clockwise,
|
bool reverseA = false,
|
||||||
DRV8833Motor::RotationDirection directionB = DRV8833Motor::RotationDirection::Clockwise);
|
bool reverseB = false);
|
||||||
|
|
||||||
DRV8833Motor* motorA = nullptr;
|
DRV8833Motor* motorA = nullptr;
|
||||||
DRV8833Motor* motorB = nullptr;
|
DRV8833Motor* motorB = nullptr;
|
||||||
|
@ -41,7 +41,7 @@ float UltrasonicSensor::GetDistance() {
|
|||||||
// if (distance > 30)
|
// if (distance > 30)
|
||||||
// distance = 0;
|
// distance = 0;
|
||||||
|
|
||||||
this->touchedSomething = (this->distance <= this->touchDistance);
|
this->touchedSomething |= (this->distance <= this->touchDistance);
|
||||||
|
|
||||||
// std::cout << "Ultrasonic " << this->distance << " " << this->touchedSomething << "\n";
|
// std::cout << "Ultrasonic " << this->distance << " " << this->touchedSomething << "\n";
|
||||||
|
|
||||||
@ -49,8 +49,15 @@ float UltrasonicSensor::GetDistance() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void UltrasonicSensor::Update(unsigned long currentTimeMs) {
|
void UltrasonicSensor::Update(unsigned long currentTimeMs) {
|
||||||
|
this->touchedSomething = false;
|
||||||
GetDistance();
|
GetDistance();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// void UltrasonicSensor::ProcessBinary(char* bytes) {
|
||||||
|
// this->touchedSomething = (bytes[0] == 1);
|
||||||
|
// if (this->touchedSomething)
|
||||||
|
// std::cout << "Touching something!\n";
|
||||||
|
// }
|
||||||
|
|
||||||
} // namespace Arduino
|
} // namespace Arduino
|
||||||
} // namespace RoboidControl
|
} // namespace RoboidControl
|
@ -20,6 +20,8 @@ class UltrasonicSensor : public TouchSensor {
|
|||||||
|
|
||||||
virtual void Update(unsigned long currentTimeMs) override;
|
virtual void Update(unsigned long currentTimeMs) override;
|
||||||
|
|
||||||
|
// virtual void ProcessBinary(char* bytes) override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
unsigned char pinTrigger = 0;
|
unsigned char pinTrigger = 0;
|
||||||
unsigned char pinEcho = 0;
|
unsigned char pinEcho = 0;
|
||||||
|
@ -111,7 +111,7 @@ Participant* LocalParticipant::GetParticipant(const char* ipAddress, int port) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Participant* LocalParticipant::AddParticipant(const char* ipAddress, int port) {
|
Participant* LocalParticipant::AddParticipant(const char* ipAddress, int port) {
|
||||||
std::cout << "New LocalParticipant " << ipAddress << ":" << port << "\n";
|
std::cout << "New Participant " << ipAddress << ":" << port << "\n";
|
||||||
Participant* participant = new Participant(ipAddress, port);
|
Participant* participant = new Participant(ipAddress, port);
|
||||||
participant->networkId = (unsigned char)this->senders.size();
|
participant->networkId = (unsigned char)this->senders.size();
|
||||||
this->senders.push_back(participant);
|
this->senders.push_back(participant);
|
||||||
@ -289,8 +289,13 @@ void LocalParticipant::Process(Participant* sender, BinaryMsg* msg) {
|
|||||||
Thing* thing = sender->Get(msg->networkId, msg->thingId);
|
Thing* thing = sender->Get(msg->networkId, msg->thingId);
|
||||||
if (thing != nullptr)
|
if (thing != nullptr)
|
||||||
thing->ProcessBinary(msg->bytes);
|
thing->ProcessBinary(msg->bytes);
|
||||||
else
|
else {
|
||||||
std::cout << "custom msg for unknown thing [" << (int)msg->networkId << "/" << (int)msg->thingId << "]\n";
|
thing = this->Get(msg->networkId, msg->thingId);
|
||||||
|
if (thing != nullptr)
|
||||||
|
thing->ProcessBinary(msg->bytes);
|
||||||
|
else
|
||||||
|
std::cout << "custom msg for unknown thing [" << (int)msg->networkId << "/" << (int)msg->thingId << "]\n";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Receive
|
// Receive
|
||||||
|
@ -28,8 +28,8 @@ Thing* Participant::Get(unsigned char networkId, unsigned char thingId) {
|
|||||||
if (thing->id == thingId)
|
if (thing->id == thingId)
|
||||||
return thing;
|
return thing;
|
||||||
}
|
}
|
||||||
// std::cout << "Could not find thing " << this->ipAddress << ":" << this->port
|
// std::cout << "Could not find thing " << this->ipAddress << ":" << this->port
|
||||||
// << "[" << (int)networkId << "/" << (int)thingId << "]\n";
|
// << "[" << (int)networkId << "/" << (int)thingId << "]\n";
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -49,8 +49,8 @@ void DifferentialDrive::Update(unsigned long currentMs) {
|
|||||||
if (this->rightWheel != nullptr)
|
if (this->rightWheel != nullptr)
|
||||||
this->rightWheel->SetAngularVelocity(Spherical(speedRight, Direction::right));
|
this->rightWheel->SetAngularVelocity(Spherical(speedRight, Direction::right));
|
||||||
|
|
||||||
std::cout << "lin. speed " << linearVelocity << " ang. speed " << angularVelocity.distance << " left wheel "
|
// std::cout << "lin. speed " << linearVelocity << " ang. speed " << angularVelocity.distance << " left wheel "
|
||||||
<< speedLeft << " right wheel " << speedRight << "\n";
|
// << speedLeft << " right wheel " << speedRight << "\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace RoboidControl
|
} // namespace RoboidControl
|
@ -7,17 +7,12 @@ TouchSensor::TouchSensor(Participant* participant) : Thing(participant) {
|
|||||||
this->type = (unsigned char)Thing::Type::TouchSensor;
|
this->type = (unsigned char)Thing::Type::TouchSensor;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TouchSensor::TouchSensor(RemoteParticipant* participant, unsigned char networkId, unsigned char thingId) :
|
|
||||||
// Thing(participant, networkId, thingId) {
|
|
||||||
// this->touchedSomething = false;
|
|
||||||
// }
|
|
||||||
|
|
||||||
void TouchSensor::GenerateBinary(char* bytes, unsigned char* ix) {}
|
void TouchSensor::GenerateBinary(char* bytes, unsigned char* ix) {}
|
||||||
|
|
||||||
void TouchSensor::ProcessBinary(char* bytes) {
|
void TouchSensor::ProcessBinary(char* bytes) {
|
||||||
this->touchedSomething = (bytes[0] == 1);
|
if (bytes[0] == 1)
|
||||||
// if (this->touchedSomething)
|
std::cout << this->name << " is Touching something!\n";
|
||||||
// std::cout << "Touching something!\n";
|
this->touchedSomething |= (bytes[0] == 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace RoboidControl
|
} // namespace RoboidControl
|
Loading…
x
Reference in New Issue
Block a user