Updates for Quadcopter support
This commit is contained in:
parent
d3015be69c
commit
46142f6e29
@ -4,32 +4,33 @@ float Activation::HeavisideStep(float inputValue, float bias) {
|
|||||||
return (inputValue + bias > 0) ? 1.0F : 0.0F;
|
return (inputValue + bias > 0) ? 1.0F : 0.0F;
|
||||||
}
|
}
|
||||||
|
|
||||||
float Activation::Linear(float inputValue, float bias, float range) {
|
|
||||||
if (inputValue > bias + range)
|
|
||||||
return 0;
|
|
||||||
if (inputValue < bias)
|
|
||||||
return 1;
|
|
||||||
|
|
||||||
float f = inputValue * (1 / range); // normalize to 1..0
|
|
||||||
float influence = 1 - f; // invert
|
|
||||||
return influence;
|
|
||||||
}
|
|
||||||
|
|
||||||
float Activation::Tanh(float inputValue) {
|
float Activation::Tanh(float inputValue) {
|
||||||
return (exp(inputValue) - exp(-inputValue)) / (exp(inputValue) + exp(-inputValue));
|
return (exp(inputValue) - exp(-inputValue)) / (exp(inputValue) + exp(-inputValue));
|
||||||
}
|
}
|
||||||
|
|
||||||
float Activation::Sigmoid(float inputValue) {
|
float Activation::Sigmoid(float inputValue) {
|
||||||
return 1 / (1 + expf(-inputValue));
|
return 1 / (1 + expf(-inputValue));
|
||||||
}
|
}
|
||||||
|
|
||||||
float Activation::Quadratic(float minValue, float range, float inputValue) {
|
float Activation::Linear(float inputValue, float minValue, float range) {
|
||||||
if (inputValue > minValue + range)
|
if (inputValue > minValue + range)
|
||||||
return 0;
|
return 0;
|
||||||
if (inputValue < minValue)
|
if (inputValue < minValue)
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
float f = inputValue * (1 / range); // normalize to 1..0
|
float f = (inputValue - minValue) * (1 / range); // normalize to 1..0
|
||||||
|
float influence = 1 - f; // invert
|
||||||
|
return influence;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
float Activation::Quadratic(float inputValue, float minValue, float range) {
|
||||||
|
if (inputValue > minValue + range)
|
||||||
|
return 0;
|
||||||
|
if (inputValue < minValue)
|
||||||
|
return 1;
|
||||||
|
|
||||||
|
float f = (inputValue - minValue) * (1 / range); // normalize to 1..0
|
||||||
float influence = 1 - (f * f); // quadratic & invert
|
float influence = 1 - (f * f); // quadratic & invert
|
||||||
return influence;
|
return influence;
|
||||||
}
|
}
|
||||||
|
@ -13,7 +13,7 @@ class Activation {
|
|||||||
|
|
||||||
static float Linear(float inputValue, float bias = 0, float range = 0);
|
static float Linear(float inputValue, float bias = 0, float range = 0);
|
||||||
|
|
||||||
static float Quadratic(float minValue, float range, float inputValue); // minValue = bias
|
static float Quadratic(float inputValue, float bias = 0, float range = 0); // minValue = bias
|
||||||
|
|
||||||
static float ParticleLife(float minValue, float maxValue, float attraction, float inputValue); // minValue = bias
|
static float ParticleLife(float minValue, float maxValue, float attraction, float inputValue); // minValue = bias
|
||||||
};
|
};
|
||||||
|
@ -9,7 +9,7 @@ Placement::Placement() {
|
|||||||
// this->thing = thing;
|
// this->thing = thing;
|
||||||
// }
|
// }
|
||||||
|
|
||||||
Placement::Placement(Vector2 direction, Sensor* thing) {
|
Placement::Placement(Vector3 direction, Sensor* thing) {
|
||||||
this->position = Vector3::zero;
|
this->position = Vector3::zero;
|
||||||
this->direction = direction;
|
this->direction = direction;
|
||||||
this->thing = thing;
|
this->thing = thing;
|
||||||
@ -23,7 +23,7 @@ Placement::Placement(Vector2 direction, Sensor* thing) {
|
|||||||
|
|
||||||
Placement::Placement(Vector3 position, Motor* thing) {
|
Placement::Placement(Vector3 position, Motor* thing) {
|
||||||
this->position = position;
|
this->position = position;
|
||||||
this->direction = Vector2::zero;
|
this->direction = Vector3::zero;
|
||||||
this->thing = thing;
|
this->thing = thing;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -10,7 +10,7 @@
|
|||||||
class Placement {
|
class Placement {
|
||||||
public:
|
public:
|
||||||
Placement();
|
Placement();
|
||||||
Placement(Vector2 direction, Sensor* sensor);
|
Placement(Vector3 direction, Sensor* sensor);
|
||||||
|
|
||||||
//Placement(Vector3 position, Sensor* sensor);
|
//Placement(Vector3 position, Sensor* sensor);
|
||||||
Placement(Vector3 position, Motor* motor);
|
Placement(Vector3 position, Motor* motor);
|
||||||
@ -22,6 +22,6 @@ class Placement {
|
|||||||
unsigned int childCount = 0;
|
unsigned int childCount = 0;
|
||||||
|
|
||||||
Vector3 position;
|
Vector3 position;
|
||||||
Vector2 direction;
|
Vector3 direction;
|
||||||
Thing* thing;
|
Thing* thing;
|
||||||
};
|
};
|
||||||
|
@ -33,6 +33,10 @@ void Propulsion::AddMotors(Placement* things, unsigned int thingCount) {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Propulsion::AddQuadcopter() {
|
||||||
|
this->quadcopter = new Quadcopter();
|
||||||
|
}
|
||||||
|
|
||||||
unsigned int Propulsion::GetMotorCount() {
|
unsigned int Propulsion::GetMotorCount() {
|
||||||
return this->motorCount;
|
return this->motorCount;
|
||||||
}
|
}
|
||||||
@ -95,6 +99,10 @@ void Propulsion::SetTwistSpeed(float forward, float yaw, float pitch) {
|
|||||||
float leftSpeed = Float::Clamp(forward - yaw, -1, 1);
|
float leftSpeed = Float::Clamp(forward - yaw, -1, 1);
|
||||||
float rightSpeed = Float::Clamp(forward + yaw, -1, 1);
|
float rightSpeed = Float::Clamp(forward + yaw, -1, 1);
|
||||||
SetDiffDriveSpeed(leftSpeed, rightSpeed);
|
SetDiffDriveSpeed(leftSpeed, rightSpeed);
|
||||||
|
|
||||||
|
if (quadcopter != nullptr) {
|
||||||
|
quadcopter->SetTwistSpeed(forward, yaw, pitch);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Propulsion::SetTwistVelocity(float forwardVelocity, float turningVelocity) {
|
void Propulsion::SetTwistVelocity(float forwardVelocity, float turningVelocity) {
|
||||||
@ -103,6 +111,11 @@ void Propulsion::SetTwistVelocity(float forwardVelocity, float turningVelocity)
|
|||||||
SetDiffDriveVelocities(leftVelocity, rightVelocity);
|
SetDiffDriveVelocities(leftVelocity, rightVelocity);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Propulsion::SetLinearSpeed(Vector3 velocity, float yawSpeed, float rollSpeed) {
|
||||||
|
if (quadcopter != nullptr)
|
||||||
|
quadcopter->LinearMotion(velocity, yawSpeed, rollSpeed);
|
||||||
|
}
|
||||||
|
|
||||||
Quadcopter* Propulsion::GetQuadcopter() {
|
Quadcopter* Propulsion::GetQuadcopter() {
|
||||||
return quadcopter;
|
return quadcopter;
|
||||||
}
|
}
|
@ -22,6 +22,7 @@ class Propulsion {
|
|||||||
|
|
||||||
//void AddMotors(MotorPlacement* motors, unsigned int motorCount);
|
//void AddMotors(MotorPlacement* motors, unsigned int motorCount);
|
||||||
void AddMotors(Placement* motors, unsigned int motorCount);
|
void AddMotors(Placement* motors, unsigned int motorCount);
|
||||||
|
void AddQuadcopter();
|
||||||
|
|
||||||
unsigned int GetMotorCount();
|
unsigned int GetMotorCount();
|
||||||
Motor* GetMotor(unsigned int motorIx);
|
Motor* GetMotor(unsigned int motorIx);
|
||||||
@ -35,7 +36,7 @@ class Propulsion {
|
|||||||
|
|
||||||
// Think: drones
|
// Think: drones
|
||||||
Quadcopter* GetQuadcopter();
|
Quadcopter* GetQuadcopter();
|
||||||
void SetLinearSpeed(Vector3 direction);
|
void SetLinearSpeed(Vector3 direction, float yawSpeed = 0.0F, float rollSpeed = 0.0F);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
//unsigned long lastMillis;
|
//unsigned long lastMillis;
|
||||||
|
@ -3,7 +3,29 @@
|
|||||||
Quadcopter::Quadcopter() {
|
Quadcopter::Quadcopter() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void Quadcopter::LinearMotion(Vector3 velocity, float yawRate) {
|
void Quadcopter::LinearMotion(Vector3 velocity, float yawSpeed, float rollSpeed) {
|
||||||
this->velocity = velocity;
|
this->velocity = velocity;
|
||||||
this->yawRate = yawRate;
|
this->yawSpeed = yawSpeed;
|
||||||
|
this->rollSpeed = rollSpeed;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Quadcopter::SetTwistSpeed(float forward, float yaw, float pitch) {
|
||||||
|
this->velocity = Vector3::forward * forward;
|
||||||
|
this->yawSpeed = yaw;
|
||||||
|
this->pitchSpeed = pitch;
|
||||||
|
}
|
||||||
|
|
||||||
|
Vector3 Quadcopter::GetTargetVelocity() {
|
||||||
|
return this->velocity;
|
||||||
|
}
|
||||||
|
|
||||||
|
float Quadcopter::GetPitchSpeed() {
|
||||||
|
return this->pitchSpeed;
|
||||||
|
}
|
||||||
|
|
||||||
|
float Quadcopter::GetYawSpeed() {
|
||||||
|
return this->yawSpeed;
|
||||||
|
}
|
||||||
|
float Quadcopter::GetRollSpeed() {
|
||||||
|
return this->rollSpeed;
|
||||||
}
|
}
|
12
Quadcopter.h
12
Quadcopter.h
@ -7,8 +7,16 @@ class Quadcopter : public Thing {
|
|||||||
public:
|
public:
|
||||||
Quadcopter();
|
Quadcopter();
|
||||||
|
|
||||||
void LinearMotion(Vector3 velocity, float yawRate = 0.0F);
|
void LinearMotion(Vector3 velocity, float yawSpeed = 0.0F, float rollSpeed = 0.0);
|
||||||
|
void SetTwistSpeed(float forward, float yaw, float pitch);
|
||||||
|
|
||||||
|
Vector3 GetTargetVelocity();
|
||||||
|
float GetYawSpeed();
|
||||||
|
float GetPitchSpeed();
|
||||||
|
float GetRollSpeed();
|
||||||
protected:
|
protected:
|
||||||
Vector3 velocity = Vector3::zero;
|
Vector3 velocity = Vector3::zero;
|
||||||
float yawRate = 0.0F;
|
float pitchSpeed = 0.0F;
|
||||||
|
float yawSpeed = 0.0F;
|
||||||
|
float rollSpeed = 0.0F;
|
||||||
};
|
};
|
34
Sensing.cpp
34
Sensing.cpp
@ -109,6 +109,40 @@ float Sensing::DistanceRight(float angle) {
|
|||||||
return minDistance;
|
return minDistance;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
float Sensing::DistanceUp(float angle) {
|
||||||
|
float minDistance = INFINITY;
|
||||||
|
for (unsigned int sensorIx = 0; sensorIx < this->sensorCount; sensorIx++) {
|
||||||
|
Placement placement = sensorPlacements[sensorIx];
|
||||||
|
Sensor* sensor = (Sensor*)placement.thing;
|
||||||
|
if (sensor->isDistanceSensor == false)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
DistanceSensor* distanceSensor = (DistanceSensor*)placement.thing;
|
||||||
|
float sensorAngle = placement.direction.y; // not correct!
|
||||||
|
if (sensorAngle > 0 && sensorAngle < angle) {
|
||||||
|
minDistance = fmin(minDistance, distanceSensor->GetDistance());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return minDistance;
|
||||||
|
}
|
||||||
|
|
||||||
|
float Sensing::DistanceDown(float angle) {
|
||||||
|
float minDistance = INFINITY;
|
||||||
|
for (unsigned int sensorIx = 0; sensorIx < this->sensorCount; sensorIx++) {
|
||||||
|
Placement placement = sensorPlacements[sensorIx];
|
||||||
|
Sensor* sensor = (Sensor*)placement.thing;
|
||||||
|
if (sensor->isDistanceSensor == false)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
DistanceSensor* distanceSensor = (DistanceSensor*)placement.thing;
|
||||||
|
float sensorAngle = placement.direction.y; // not correct!
|
||||||
|
if (sensorAngle < 0 && sensorAngle > -angle) {
|
||||||
|
minDistance = fmin(minDistance, distanceSensor->GetDistance());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return minDistance;
|
||||||
|
}
|
||||||
|
|
||||||
bool Sensing::SwitchOn(float fromAngle, float toAngle) {
|
bool Sensing::SwitchOn(float fromAngle, float toAngle) {
|
||||||
if (toAngle < fromAngle)
|
if (toAngle < fromAngle)
|
||||||
return false;
|
return false;
|
||||||
|
@ -59,6 +59,11 @@ class Sensing {
|
|||||||
/// @note When an object is beyond `angle` meters, it is not reported.
|
/// @note When an object is beyond `angle` meters, it is not reported.
|
||||||
float DistanceRight(float angle);
|
float DistanceRight(float angle);
|
||||||
|
|
||||||
|
float DistanceUp() { return DistanceUp(180); }
|
||||||
|
float DistanceUp(float angle);
|
||||||
|
float DistanceDown() { return DistanceDown(180); }
|
||||||
|
float DistanceDown(float angle);
|
||||||
|
|
||||||
float Distance(float leftAngle, float rightAngle);
|
float Distance(float leftAngle, float rightAngle);
|
||||||
|
|
||||||
bool SwitchOn(float fromAngle, float toAngle);
|
bool SwitchOn(float fromAngle, float toAngle);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user