Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to Chrono v9.0.0 #59

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
#--------------------------------------------------------------

cmake_minimum_required(VERSION 3.18.2)
cmake_policy(SET CMP0091 NEW)


# guard against in-source builds
if(${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_BINARY_DIR})
Expand Down Expand Up @@ -41,6 +43,14 @@ project(HydroChrono
# Add the cmake folder so the FindSphinx module is found
set(CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake" ${CMAKE_MODULE_PATH})

#--------------------------------------------------------------
# Important! To ensure ABI compatibility, use the same C++ standard
# as the one used to build the Chrono libraries.
#--------------------------------------------------------------

set(CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_STANDARD ${CHRONO_CXX_STANDARD})

# ===================
# OPTIONS
# ===================
Expand Down Expand Up @@ -123,9 +133,9 @@ target_include_directories(
target_compile_definitions(HydroChrono

PUBLIC

PRIVATE
CHRONO_DATA_DIR=\"${CHRONO_DATA_DIR}\"
PRIVATE

)

target_compile_options(HydroChrono BEFORE
Expand Down
12 changes: 12 additions & 0 deletions demos/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ if(HYDROCHRONO_ENABLE_IRRLICHT)
target_compile_definitions(demo_sphere_decay
PRIVATE
HYDROCHRONO_HAVE_IRRLICHT=1
"CHRONO_DATA_DIR=\"${CHRONO_DATA_DIR}\""
)
endif()

Expand Down Expand Up @@ -49,6 +50,7 @@ if(HYDROCHRONO_ENABLE_IRRLICHT)
target_compile_definitions(demo_sphere_reg_waves
PRIVATE
HYDROCHRONO_HAVE_IRRLICHT=1
"CHRONO_DATA_DIR=\"${CHRONO_DATA_DIR}\""
)
endif()

Expand Down Expand Up @@ -83,6 +85,7 @@ if(HYDROCHRONO_ENABLE_IRRLICHT)
target_compile_definitions(demo_sphere_irreg_waves
PRIVATE
HYDROCHRONO_HAVE_IRRLICHT=1
"CHRONO_DATA_DIR=\"${CHRONO_DATA_DIR}\""
)
endif()

Expand Down Expand Up @@ -116,6 +119,7 @@ if(HYDROCHRONO_ENABLE_IRRLICHT)
target_compile_definitions(demo_sphere_irreg_waves_eta_import
PRIVATE
HYDROCHRONO_HAVE_IRRLICHT=1
"CHRONO_DATA_DIR=\"${CHRONO_DATA_DIR}\""
)
endif()

Expand Down Expand Up @@ -148,6 +152,7 @@ if(HYDROCHRONO_ENABLE_IRRLICHT)
target_compile_definitions(demo_rm3_decay
PRIVATE
HYDROCHRONO_HAVE_IRRLICHT=1
"CHRONO_DATA_DIR=\"${CHRONO_DATA_DIR}\""
)
endif()

Expand Down Expand Up @@ -182,6 +187,7 @@ if(HYDROCHRONO_ENABLE_IRRLICHT)
target_compile_definitions(demo_rm3_reg_waves
PRIVATE
HYDROCHRONO_HAVE_IRRLICHT=1
"CHRONO_DATA_DIR=\"${CHRONO_DATA_DIR}\""
)
endif()

Expand Down Expand Up @@ -216,6 +222,7 @@ if(HYDROCHRONO_ENABLE_IRRLICHT)
target_compile_definitions(demo_oswec_decay
PRIVATE
HYDROCHRONO_HAVE_IRRLICHT=1
"CHRONO_DATA_DIR=\"${CHRONO_DATA_DIR}\""
)
endif()

Expand Down Expand Up @@ -249,6 +256,7 @@ if(HYDROCHRONO_ENABLE_IRRLICHT)
target_compile_definitions(demo_oswec_reg_waves
PRIVATE
HYDROCHRONO_HAVE_IRRLICHT=1
"CHRONO_DATA_DIR=\"${CHRONO_DATA_DIR}\""
)
endif()

Expand Down Expand Up @@ -282,6 +290,7 @@ if(HYDROCHRONO_ENABLE_IRRLICHT)
target_compile_definitions(demo_f3of_DT1
PRIVATE
HYDROCHRONO_HAVE_IRRLICHT=1
"CHRONO_DATA_DIR=\"${CHRONO_DATA_DIR}\""
)
endif()

Expand Down Expand Up @@ -315,6 +324,7 @@ if(HYDROCHRONO_ENABLE_IRRLICHT)
target_compile_definitions(demo_f3of_DT2
PRIVATE
HYDROCHRONO_HAVE_IRRLICHT=1
"CHRONO_DATA_DIR=\"${CHRONO_DATA_DIR}\""
)
endif()

Expand Down Expand Up @@ -347,6 +357,7 @@ if(HYDROCHRONO_ENABLE_IRRLICHT)
target_compile_definitions(demo_f3of_DT3
PRIVATE
HYDROCHRONO_HAVE_IRRLICHT=1
"CHRONO_DATA_DIR=\"${CHRONO_DATA_DIR}\""
)
endif()

Expand Down Expand Up @@ -380,6 +391,7 @@ if(HYDROCHRONO_ENABLE_IRRLICHT)
target_compile_definitions(demo_DeepCWind_decay
PRIVATE
HYDROCHRONO_HAVE_IRRLICHT=1
"CHRONO_DATA_DIR=\"${CHRONO_DATA_DIR}\""
)
endif()

Expand Down
48 changes: 24 additions & 24 deletions demos/DeepCWind/demo_DeepCWind_decay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,13 @@
#include <hydroc/hydro_forces.h>

#include <chrono/core/ChRealtimeStep.h>
#include <chrono/physics/ChLinkMate.h>

#include <chrono> // std::chrono::high_resolution_clock::now
#include <iomanip> // std::setprecision
#include <vector> // std::vector<double>

// Use the namespaces of Chrono
using namespace chrono;
using namespace chrono::geometry;

// usage: ./sphere_deca.exe [DATADIR] [--nogui]
//
Expand All @@ -20,7 +18,9 @@ using namespace chrono::geometry;
//
int main(int argc, char* argv[]) {
// auto start = std::chrono::high_resolution_clock::now();
GetLog() << "Chrono version: " << CHRONO_VERSION << "\n\n";
std::cout << "Chrono version: " << CHRONO_VERSION << "\n\n";

SetChronoDataPath(CHRONO_DATA_DIR);

if (hydroc::SetInitialEnvironment(argc, argv) != 0) {
return 1;
Expand All @@ -39,21 +39,21 @@ int main(int argc, char* argv[]) {

// system/solver settings
ChSystemSMC system;
system.Set_G_acc(ChVector<>(0.0, 0.0, -9.81));
system.SetGravitationalAcceleration(ChVector3d(0.0, 0.0, -9.81));
double timestep = 0.08;
system.SetTimestepperType(ChTimestepper::Type::HHT);
system.SetSolverType(ChSolver::Type::GMRES);
system.SetSolverMaxIterations(300); // the higher, the easier to keep the constraints satisfied.
system.SetStep(timestep);
system.GetSolver()->AsIterative()->SetMaxIterations(
300); // the higher, the easier to keep the constraints satisfied.
double simulationDuration = 1000.0;

// Create user interface
std::shared_ptr<hydroc::gui::UI> pui = hydroc::gui::CreateUI(visualizationOn);
hydroc::gui::UI& ui = *pui.get();
hydroc::gui::UI& ui = *pui.get();

// some io/viz options
bool profilingOn = true;
bool saveDataOn = true;
bool profilingOn = true;
bool saveDataOn = true;
std::vector<double> time_vector;
std::vector<double> base_pitch;
std::vector<double> base_surge;
Expand All @@ -70,33 +70,33 @@ int main(int argc, char* argv[]) {

// define the base's initial conditions
system.Add(base);
base->SetNameString("body1");
auto cg = ChVector<>(0.0, 0.0, -7.53);
base->SetName("body1");
auto cg = ChVector3d(0.0, 0.0, -7.53);
// offset used for heave/surge decay test
auto offset = ChVector<>(0.0, 0.0, 0.0);
auto offset = ChVector3d(0.0, 0.0, 0.0);
base->SetPos(cg + offset);
// Use for pitch decay test
double ang_rad = -3.95 * CH_C_PI / 180.0;
base->SetRot(Q_from_AngAxis(ang_rad, VECT_Y));
double ang_rad = -3.95 * CH_PI / 180.0;
base->SetRot(QuatFromAngleY(ang_rad));
base->SetMass(1.419625e7);
base->SetInertiaXX(ChVector<>(1.2898e10, 1.2851e10, 1.4189e10));
base->SetInertiaXX(ChVector3d(1.2898e10, 1.2851e10, 1.4189e10));

// add fixed ground for linear damping (surge or pitch)
auto ground = chrono_types::make_shared<ChBody>();
system.AddBody(ground);
ground->SetPos(cg);
ground->SetRot(Q_from_AngAxis(CH_C_PI / 2.0, VECT_X));
ground->SetIdentifier(-1);
ground->SetBodyFixed(true);
ground->SetCollide(false);
ground->SetRot(QuatFromAngleX(CH_PI / 2.0));
ground->SetTag(-1);
ground->SetFixed(true);
ground->EnableCollision(false);

// define damping in pitch
auto rot_damp = chrono_types::make_shared<ChLinkRSDA>();
// need to set damping to 31 MN-m/(rad/s)
rot_damp->SetDampingCoefficient(31e6);
// puts Z axis for link into screen, keeping x axis the same (to the right)
ChQuaternion<> rev_rot = Q_from_AngAxis(CH_C_PI / 2.0, VECT_X); // do not change
rot_damp->Initialize(base, ground, false, ChCoordsys(cg, rev_rot), ChCoordsys(cg, rev_rot));
ChQuaternion<> rev_rot = QuatFromAngleX(CH_PI / 2.0); // do not change
rot_damp->Initialize(base, ground, false, ChFramed(cg, rev_rot), ChFramed(cg, rev_rot));
system.AddLink(rot_damp);

// set up hydro forces
Expand All @@ -120,7 +120,7 @@ int main(int argc, char* argv[]) {
// append data to output vector
time_vector.push_back(system.GetChTime());
base_surge.push_back(base->GetPos().x());
base_pitch.push_back(base->GetRot().Q_to_Euler123().y());
base_pitch.push_back(base->GetRot().GetCardanAnglesXYZ().y());
}
}

Expand Down Expand Up @@ -153,8 +153,8 @@ int main(int argc, char* argv[]) {
outputFile.open("./results/DeepCWind_decay.txt");
if (!outputFile.is_open()) {
if (!std::filesystem::exists("./results")) {
std::cout << "Path " << std::filesystem::absolute("./results")
<< " does not exist, creating it now..." << std::endl;
std::cout << "Path " << std::filesystem::absolute("./results") << " does not exist, creating it now..."
<< std::endl;
std::filesystem::create_directory("./results");
outputFile.open("./results/DeepCWind_decay.txt");
if (!outputFile.is_open()) {
Expand Down
40 changes: 20 additions & 20 deletions demos/Test/Test_1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ class MyEventReceiver : public IEventReceiver {
// wheel and the many radial rollers, already lined to the wheel with revolute joints.)
// The function returns the pointer to the central wheel.
std::shared_ptr<ChBody> create_mecanum_wheel(ChSystemNSC& sys,
ChVector<> shaft_position,
ChVector3d shaft_position,
ChQuaternion<> shaft_alignment,
double wheel_radius,
double wheel_width,
Expand Down Expand Up @@ -122,7 +122,7 @@ std::shared_ptr<ChBody> create_mecanum_wheel(ChSystemNSC& sys,
double roller_elliptical_rad_Vert = wheel_radius * 1.0 / (cos(roller_angle));

for (int iroller = 0; iroller < n_rollers; iroller++) {
double pitch = CH_C_2PI * ((double)iroller / (double)n_rollers);
double pitch = CH_2PI * ((double)iroller / (double)n_rollers);

double Roffset = -(wheel_radius - roller_midradius);

Expand All @@ -131,9 +131,9 @@ std::shared_ptr<ChBody> create_mecanum_wheel(ChSystemNSC& sys,
sys.Add(roller);

// move it to slanted aligment
ChFrameMoving<> f1(ChVector<>(0, 0, -(wheel_radius - roller_midradius)),
Q_from_AngAxis(roller_angle, ChVector<>(0, 0, 1)));
ChFrameMoving<> f2(ChVector<>(0, 0, 0), Q_from_AngAxis(pitch, ChVector<>(0, 1, 0)));
ChFrameMoving<> f1(ChVector3d(0, 0, -(wheel_radius - roller_midradius)),
QuatFromAngleZ(roller_angle));
ChFrameMoving<> f2(ChVector3d(0, 0, 0), QuatFromAngleY(pitch));
ChFrameMoving<> f3 = f1 >> f2 >> ftot;
roller->ConcatenatePreTransformation(f3);

Expand All @@ -150,7 +150,7 @@ std::shared_ptr<ChBody> create_mecanum_wheel(ChSystemNSC& sys,
roller_elliptical_rad_Vert, roller_elliptical_rad_Hor, //
Roffset);
roller->GetCollisionModel()->BuildModel();
roller->SetCollide(true);
roller->EnableCollision(true);

// add visualization shape
auto rollershape =
Expand All @@ -161,7 +161,7 @@ std::shared_ptr<ChBody> create_mecanum_wheel(ChSystemNSC& sys,

// Make the revolute joint between the roller and the central wheel
// (preconcatenate rotation 90 degrees on X, to set axis of revolute joint)
ChFrameMoving<> fr(ChVector<>(0, 0, 0), Q_from_AngAxis(CH_C_PI / 2.0, ChVector<>(1, 0, 0)));
ChFrameMoving<> fr(ChVector3d(0, 0, 0), QuatFromAngleX(CH_PI / 2.0));
ChFrameMoving<> frabs = fr >> f3;
auto link_roller = chrono_types::make_shared<ChLinkLockRevolute>();
link_roller->Initialize(roller, centralWheel, frabs.GetCoord());
Expand All @@ -172,14 +172,14 @@ std::shared_ptr<ChBody> create_mecanum_wheel(ChSystemNSC& sys,
}

int main(int argc, char* argv[]) {
GetLog() << "Copyright (c) 2017 projectchrono.org\nChrono version: " << CHRONO_VERSION << "\n\n";
std::cout << "Copyright (c) 2017 projectchrono.org\nChrono version: " << CHRONO_VERSION << "\n\n";

// Create a ChronoENGINE physical system
ChSystemNSC sys;

double platform_radius = 8;
double wheel_radius = 3;
double roller_angle = CH_C_PI / 4;
double roller_angle = CH_PI / 4;

// Create the robot truss, as a circular platform
auto platform = chrono_types::make_shared<ChBodyEasyCylinder>(platform_radius * 0.7, 2, // radius, height
Expand All @@ -193,11 +193,11 @@ int main(int argc, char* argv[]) {

// create the wheels and link them to the platform

ChFrame<> f0(ChVector<>(0, 0, 0), Q_from_AngAxis(CH_C_PI / 2.0, ChVector<>(1, 0, 0)));
ChFrame<> f1(ChVector<>(0, 0, platform_radius), QUNIT);
ChFrame<> f2_wA(VNULL, Q_from_AngAxis(0 * (CH_C_2PI / 3.0), ChVector<>(0, 1, 0)));
ChFrame<> f2_wB(VNULL, Q_from_AngAxis(1 * (CH_C_2PI / 3.0), ChVector<>(0, 1, 0)));
ChFrame<> f2_wC(VNULL, Q_from_AngAxis(2 * (CH_C_2PI / 3.0), ChVector<>(0, 1, 0)));
ChFrame<> f0(ChVector3d(0, 0, 0), QuatFromAngleX(CH_PI / 2.0));
ChFrame<> f1(ChVector3d(0, 0, platform_radius), QUNIT);
ChFrame<> f2_wA(VNULL, QuatFromAngleY(0 * (CH_2PI / 3.0)));
ChFrame<> f2_wB(VNULL, QuatFromAngleY(1 * (CH_2PI / 3.0)));
ChFrame<> f2_wC(VNULL, QuatFromAngleY(2 * (CH_2PI / 3.0)));
ChFrame<> ftot_wA = f0 >> f1 >> f2_wA;
ChFrame<> ftot_wB = f0 >> f1 >> f2_wB;
ChFrame<> ftot_wC = f0 >> f1 >> f2_wC;
Expand Down Expand Up @@ -259,8 +259,8 @@ int main(int argc, char* argv[]) {
true, // visualize
true, // collide
ground_mat); // contact material
ground->SetPos(ChVector<>(0, -5, 0));
ground->SetBodyFixed(true);
ground->SetPos(ChVector3d(0, -5, 0));
ground->SetFixed(true);
ground->GetVisualShape(0)->SetTexture(GetChronoDataFile("textures/concrete.jpg"), 100, 100);
sys.Add(ground);

Expand All @@ -272,7 +272,7 @@ int main(int argc, char* argv[]) {
vis->Initialize();
vis->AddLogo();
vis->AddSkyBox();
vis->AddCamera(ChVector<>(0, 14, -20));
vis->AddCamera(ChVector3d(0, 14, -20));
vis->AddTypicalLights();

vis->GetGUIEnvironment()->addStaticText(L"Use keys Q,W, A,Z, E,R to move the robot", rect<s32>(150, 10, 430, 40),
Expand All @@ -286,7 +286,7 @@ int main(int argc, char* argv[]) {
sys.SetTimestepperType(ChTimestepper::Type::EULER_IMPLICIT_PROJECTED);

sys.SetSolverType(ChSolver::Type::PSOR);
sys.SetSolverMaxIterations(30);
sys.GetSolver()->AsIterative()->SetMaxIterations(30);

// Simulation loop

Expand All @@ -303,8 +303,8 @@ int main(int argc, char* argv[]) {

// change motor speeds depending on user setpoints from GUI

ChVector<> imposed_speed(STATIC_x_speed, 0, STATIC_z_speed);
ChFrame<> roll_twist(ChVector<>(0, -wheel_radius, 0), Q_from_AngAxis(-roller_angle, ChVector<>(0, 1, 0)));
ChVector3d imposed_speed(STATIC_x_speed, 0, STATIC_z_speed);
ChFrame<> roll_twist(ChVector3d(0, -wheel_radius, 0), QuatFromAngleY(-roller_angle));

ChFrame<> abs_roll_wA = roll_twist >> f2_wA >> ChFrame<>(platform->GetCoord());
double wheel_A_rotspeed =
Expand Down
Loading