-
-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implemented "push" actuator which can be used as a simple thruster fo…
…r underwater vehicles or as a general 1D force generating actuator.
- Loading branch information
1 parent
ed4a9bf
commit 1ff9a89
Showing
9 changed files
with
221 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
/* | ||
This file is a part of Stonefish. | ||
Stonefish is free software: you can redistribute it and/or modify | ||
it under the terms of the GNU General Public License as published by | ||
the Free Software Foundation, either version 3 of the License, or | ||
(at your option) any later version. | ||
Stonefish is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU General Public License for more details. | ||
You should have received a copy of the GNU General Public License | ||
along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
// | ||
// Push.h | ||
// Stonefish | ||
// | ||
// Created by Patryk Cieslak on 04/07/2023. | ||
// Copyright (c) 2023 Patryk Cieslak. All rights reserved. | ||
// | ||
|
||
#ifndef __Stonefish_Push__ | ||
#define __Stonefish_Push__ | ||
|
||
#include "actuators/LinkActuator.h" | ||
|
||
namespace sf | ||
{ | ||
//! A class representing a thruster. | ||
class Push : public LinkActuator | ||
{ | ||
public: | ||
//! A constructor. | ||
/*! | ||
\param uniqueName a name for the push | ||
\param inverted a flag indicating if the direction of the generated force should be reversed | ||
\param onlyWorksSubmerged a flag indicating if the actuator is simulating an underwater thruster | ||
*/ | ||
Push(std::string uniqueName, bool inverted = false, bool onlyWorksSubmerged = false); | ||
|
||
//! A method used to update the internal state of the push actuator. | ||
/*! | ||
\param dt a time step of the simulation [s] | ||
*/ | ||
void Update(Scalar dt); | ||
|
||
//! A method implementing the rendering of the push actuator. | ||
std::vector<Renderable> Render(); | ||
|
||
//! A method used to set the force limits. | ||
void setForceLimits(double lower, double upper); | ||
|
||
//! A method setting the new value of the desired force. | ||
/*! | ||
\param f the desired force to be generated | ||
*/ | ||
void setForce(Scalar f); | ||
|
||
//! A method returning the current setpoint. | ||
Scalar getForce() const; | ||
|
||
//! A method returning the type of the actuator. | ||
ActuatorType getType() const; | ||
|
||
private: | ||
Scalar setpoint; | ||
bool underwater; | ||
bool inv; | ||
std::pair<double, double> limits; | ||
}; | ||
} | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
/* | ||
This file is a part of Stonefish. | ||
Stonefish is free software: you can redistribute it and/or modify | ||
it under the terms of the GNU General Public License as published by | ||
the Free Software Foundation, either version 3 of the License, or | ||
(at your option) any later version. | ||
Stonefish is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU General Public License for more details. | ||
You should have received a copy of the GNU General Public License | ||
along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
// | ||
// Push.cpp | ||
// Stonefish | ||
// | ||
// Created by Patryk Cieslak on 04/07/2023. | ||
// Copyright (c) 2023 Patryk Cieslak. All rights reserved. | ||
// | ||
|
||
#include "actuators/Push.h" | ||
|
||
#include "core/SimulationApp.h" | ||
#include "core/SimulationManager.h" | ||
|
||
namespace sf | ||
{ | ||
|
||
Push::Push(std::string uniqueName, bool inverted, bool onlyWorksSubmerged) : LinkActuator(uniqueName) | ||
{ | ||
setpoint = Scalar(0); | ||
inv = inverted; | ||
underwater = onlyWorksSubmerged; | ||
setForceLimits(1, -1); // No limits | ||
} | ||
|
||
ActuatorType Push::getType() const | ||
{ | ||
return ActuatorType::PUSH; | ||
} | ||
|
||
void Push::setForceLimits(double lower, double upper) | ||
{ | ||
limits.first = lower; | ||
limits.second = upper; | ||
} | ||
|
||
void Push::setForce(Scalar f) | ||
{ | ||
if(limits.second > limits.first) // Limitted | ||
setpoint = f < limits.first ? limits.first : (f > limits.second ? limits.second : f); | ||
else | ||
setpoint = f; | ||
} | ||
|
||
Scalar Push::getForce() const | ||
{ | ||
return setpoint; | ||
} | ||
|
||
void Push::Update(Scalar dt) | ||
{ | ||
if(attach != nullptr) | ||
{ | ||
//Get transforms | ||
Transform solidTrans = attach->getCGTransform(); | ||
Transform pushTrans = attach->getOTransform() * o2a; | ||
|
||
Scalar force(0); | ||
if(underwater) | ||
{ | ||
Ocean* ocn = SimulationApp::getApp()->getSimulationManager()->getOcean(); | ||
if(ocn != nullptr && ocn->IsInsideFluid(pushTrans.getOrigin())) | ||
force = inv ? -setpoint : setpoint; | ||
} | ||
else | ||
force = inv ? -setpoint : setpoint; | ||
|
||
Vector3 forceV(force, 0, 0); | ||
attach->ApplyCentralForce(pushTrans.getBasis() * forceV); | ||
attach->ApplyTorque((pushTrans.getOrigin() - solidTrans.getOrigin()).cross(pushTrans.getBasis() * forceV)); | ||
} | ||
} | ||
|
||
std::vector<Renderable> Push::Render() | ||
{ | ||
Transform pushTrans = Transform::getIdentity(); | ||
if(attach != nullptr) | ||
pushTrans = attach->getOTransform() * o2a; | ||
else | ||
LinkActuator::Render(); | ||
|
||
//Add renderable | ||
std::vector<Renderable> items(0); | ||
Renderable item; | ||
item.model = glMatrixFromTransform(pushTrans); | ||
item.type = RenderableType::ACTUATOR_LINES; | ||
item.points.push_back(glm::vec3(0,0,0)); | ||
item.points.push_back(glm::vec3(0.1f*(inv ? -setpoint : setpoint),0,0)); | ||
items.push_back(item); | ||
|
||
return items; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters