-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
31 changed files
with
238 additions
and
637 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
74 changes: 74 additions & 0 deletions
74
examples/active_entanglement_case/activeEntanglementExample.cpp
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,74 @@ | ||
#include "robotDescription.h" | ||
#include <math.h> | ||
|
||
|
||
extern ofstream logging_output_file; // defined in main.cpp | ||
/* | ||
* Dynamic Cantilever Example | ||
* | ||
* Define your soft robot structure(s), boundary conditions, | ||
* custom external forces, and loggers in the function below. | ||
*/ | ||
|
||
void get_robot_description(int argc, char** argv, | ||
const shared_ptr<softRobots>& soft_robots, | ||
const shared_ptr<forceContainer>& forces, | ||
shared_ptr<worldLogger>& logger, | ||
simParams& sim_params) { | ||
|
||
sim_params.dt = 2.5e-3; | ||
sim_params.sim_time = 15; | ||
sim_params.dtol = 1e-2; | ||
sim_params.render_scale = 3.0; | ||
sim_params.adaptive_time_stepping = 10; | ||
|
||
int n = 60; | ||
double radius = 0.005; | ||
double young_mod = 3e5; | ||
double density = 1200; | ||
double poisson = 0.5; | ||
|
||
int num_fingers = 5; | ||
double dist = 0.015; | ||
|
||
double theta = (num_fingers - 2) * M_PI / (2 * num_fingers); | ||
double R = dist / 2.0 / cos(theta); | ||
theta = 2 * M_PI / num_fingers; | ||
|
||
for (int i = 0; i < num_fingers; i++) { | ||
|
||
double t = theta * i; | ||
double x = R - R * cos(t); | ||
double y = R * sin(t); | ||
|
||
|
||
soft_robots->addLimb(Vector3d(x, y, 0.0), Vector3d(x, y, -0.3), n, density, radius, young_mod, poisson); | ||
soft_robots->lockEdge(i, 0); | ||
} | ||
|
||
// Add gravity | ||
Vector3d gravity_vec(0.0, 0.0, -9.8); | ||
forces->addForce(make_shared<gravityForce>(soft_robots, gravity_vec)); | ||
|
||
// Add viscous damping | ||
double viscosity = 5.0; | ||
forces->addForce(make_shared<dampingForce>(soft_robots, viscosity)); | ||
|
||
// Add self-contact | ||
double col_limit = 1e-3; | ||
double delta = 5e-4; | ||
double k_scaler = 1e5; | ||
double mu = 0.4; | ||
double nu = 1e-3; | ||
bool self_contact = true; | ||
forces->addForce(make_shared<contactForce>(soft_robots, col_limit, delta, k_scaler, mu, nu, self_contact)); | ||
|
||
// Add custom active entanglement controller | ||
double start_time = 0.0; | ||
double end_time = 10.0; | ||
soft_robots->addController(make_shared<activeEntanglementController>(soft_robots, start_time, end_time)); | ||
|
||
// string logfile_base = "log_files/active_entanglement"; | ||
// int logging_period = 5; | ||
// logger = make_shared<rodNodeLogger>(logfile_base, logging_output_file, logging_period); | ||
} |
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,42 @@ | ||
#include "activeEntanglementController.h" | ||
#include "rod_mechanics/softRobots.h" | ||
|
||
|
||
activeEntanglementController::activeEntanglementController(const shared_ptr <softRobots> &soft_robots, | ||
double start_time, double end_time) : | ||
baseController(soft_robots->limbs), | ||
start_time(start_time), end_time(end_time) | ||
{ | ||
for (int limb_idx = 0; limb_idx < num_actuators; limb_idx++) { | ||
auto limb = limbs[limb_idx]; | ||
|
||
random_curvatures.emplace_back(); | ||
|
||
for (int i = 1; i < limb->ne; i++) { | ||
double random_curvature = rand() % 40 * (M_PI / 180); | ||
random_curvatures[limb_idx].push_back(random_curvature); | ||
} | ||
} | ||
} | ||
|
||
|
||
activeEntanglementController::~activeEntanglementController() = default; | ||
|
||
|
||
void activeEntanglementController::updateTimeStep(double dt) { | ||
baseController::updateTimeStep(dt); | ||
|
||
if (current_time < start_time || current_time > end_time) return; | ||
|
||
double curr_ratio = 0.5 * (current_time - start_time) / (end_time - start_time); | ||
|
||
for (int limb_idx = 0; limb_idx < num_actuators; limb_idx++) { | ||
auto limb = limbs[limb_idx]; | ||
|
||
for (int i = 1; i < limb->ne; i++) { | ||
double random_curvature = 2 * tan(random_curvatures.at(limb_idx).at(i-1) * curr_ratio * 0.5); | ||
limb->kappa_bar(i, 0) = random_curvature; | ||
limb->kappa_bar(i, 1) = random_curvature; | ||
} | ||
} | ||
} |
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,22 @@ | ||
#ifndef ACTIVE_ENTANGLEMENT_CONTROLLER_H | ||
#define ACTIVE_ENTANGLEMENT_CONTROLLER_H | ||
|
||
#include "baseController.h" | ||
|
||
class softRobots; | ||
|
||
class activeEntanglementController : public baseController | ||
{ | ||
public: | ||
explicit activeEntanglementController(const shared_ptr<softRobots>& soft_robots, double start_time, double end_time); | ||
~activeEntanglementController(); | ||
|
||
void updateTimeStep(double dt) override; | ||
|
||
private: | ||
vector<vector<double>> random_curvatures; | ||
double start_time; | ||
double end_time; | ||
}; | ||
|
||
#endif |
8 changes: 4 additions & 4 deletions
8
src/controllers/rodController.cpp → src/controllers/baseController.cpp
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 |
---|---|---|
@@ -1,17 +1,17 @@ | ||
#include "rodController.h" | ||
#include "baseController.h" | ||
|
||
|
||
rodController::rodController(const vector<shared_ptr<elasticRod>>& limbs) : | ||
baseController::baseController(const vector<shared_ptr<elasticRod>>& limbs) : | ||
limbs(limbs), num_actuators(limbs.size()), current_time(0) | ||
{ | ||
} | ||
|
||
|
||
rodController::~rodController() = default; | ||
baseController::~baseController() = default; | ||
|
||
|
||
// but we can also implement the timestepping here, for others to override if desired. | ||
void rodController::updateTimestep(double dt) | ||
void baseController::updateTimeStep(double dt) | ||
{ | ||
current_time += dt; | ||
} |
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,22 @@ | ||
#ifndef BASE_CONTROLLER_H | ||
#define BASE_CONTROLLER_H | ||
|
||
#include "eigenIncludes.h" | ||
|
||
class elasticRod; | ||
|
||
class baseController | ||
{ | ||
public: | ||
explicit baseController(const vector<shared_ptr<elasticRod>>& limbs); | ||
~baseController(); | ||
|
||
virtual void updateTimeStep(double dt); | ||
|
||
protected: | ||
vector<shared_ptr<elasticRod>> limbs; | ||
int num_actuators; | ||
double current_time; | ||
}; | ||
|
||
#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
1 change: 1 addition & 0 deletions
1
src/controllers/openloop_control_trajectories/.~lock.active_entanglement_controller.csv#
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 @@ | ||
,asjchoi,QuantuMopeDT,18.12.2023 13:28,file:///home/asjchoi/.config/libreoffice/4; |
5 changes: 5 additions & 0 deletions
5
src/controllers/openloop_control_trajectories/active_entanglement_controller.csv
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,5 @@ | ||
Simulation time (sec),kappabar_phi_00,kappabar_phi_01,kappabar_phi10,kappabar_phi11,kappabar_phi20,kappabar_phi21,kappabar_phi30,kappabar_phi31,kappabar_phi40,kappabar_phi41,Empty | ||
0.0,0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0, | ||
0.01,0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0, | ||
5.2,0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0, | ||
5.3,0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0, |
Oops, something went wrong.