广东电白建设集团有限公司官方网站,h5页面生成,做网站准备,会员管理系统登录由于Chrono的官方教程在一些细节方面解释的并不清楚#xff0c;自己做了一些尝试#xff0c;做学习总结。
1、基本介绍
Vehicle Overview Vehicle Mannel Vehicle的官方demo
1.1 Vehicle的构型
一个车辆由许多子系统构成#xff1a;悬挂、转向、轮子/履带、刹车/油门、动…由于Chrono的官方教程在一些细节方面解释的并不清楚自己做了一些尝试做学习总结。
1、基本介绍
Vehicle Overview Vehicle Mannel Vehicle的官方demo
1.1 Vehicle的构型
一个车辆由许多子系统构成悬挂、转向、轮子/履带、刹车/油门、动力传统系统(driverline)。Chrono提供了一些典型的车辆模型例如悍马车、小型轿车等 vehicle models只需要直接代码选定即可如果不用官方的车型就需要自己定义各种子系统。chono提供一些典型的子系统构型例如悬挂包括双横臂、前麦花臣支柱等 悬挂类型转向包括转向垂臂( Pitman arm)等转向类型。如果连官方的子系统都不想用就需要自己定义一些弹簧/轴的连接就复杂一些一般采用JSON文件的方式这样比较清晰明了。
1.2 Vehicle部分仿真的逻辑
https://api.projectchrono.org/vehicle_overview.html#vehicle_simulation_loop
每一步仿真时依次执行获取系统输出、同步各个系统(synchronize system)、系统动力学仿真前进一步(advance system)。
在各个系统同步时可能不仅包括vehicle的模块还包括可视化等多个模块同时vehicle部分需要同步驾驶控制器、地型交互、车体、可视化等模块如有。在同步之后进行advance操作前进一步。
正因为如此在仿真代码中每次loop最后会有这么两段
// Update modules (process inputs from other modules
driver-Synchronize(time);
terrain.Synchronize(time);
hmmwv.Synchronize(time, driver_inputs, terrain);
vis-Synchronize(time, driver_inputs);
// Advance simulation for one timestep for all modules
driver-Advance(step_size);
terrain.Advance(step_size);
hmmwv.Advance(step_size);
vis-Advance(step_size);1.3 vehicle的可视化
Vehicle的可视化与之前的整体仿真环境的可视化有些相同但不完全相同。相同之处是是选用irrlicht、还是OpenGL、还是离线POV-Ray可视化。我这里采用irrlicht。
除此之外由于vehicle包括很多子模块例如地盘、悬挂、轮胎等在仿真时可以选择是否进行显示。一般显示方式为三种不显示(VisualizationType::None)、显示基础结构(PRIMITIVES)、显示完整表面mesh(MESH)。例如地盘、悬挂、转向、轮胎、外壳全部显示MESH和只显示基础结构分别是这样的
2. 车辆控制系统
2.1 控制系统基础概念
车辆控制系统在chrono里面称作“driver”ChDriver。
对于车辆的控制主要控制量只有两个油门throttle和刹车brake、转向steering 左/右。
控制系统包括交互控制ChIteractiveDriver、闭环控制ChClosedLoopDriver、AI Driver等多种方式每个模块的控制代码写法不同。这里暂不展开介绍。 2.2 交互控制系统
这里采用较为简单的交互控制。交互控制通过可视化模块获取来自键盘的输入控制量通过WSAD分别控制加油门、刹车、左转向、右转向。需要注意在开启交互控制前需要按键j启动键盘控制否则无效注意是否关闭了中文输入法。
交互系统部分的代码是这样的
DriverInputs driver_inputs driver-GetInputs();之后在调用driver-Advance函数时即对车辆的控制量进行更新。
需要注意的是在交互控制中每次按键改变的是上述控制量的增量即按一下油门油门会增大一些。因此并不是直接控制的速度所以在操作时需要练习手感。
在程序运行时右上角会显示控制量和车辆状态 可以看出此时的油门是88油门控制量默认是0-100刹车是0通过按键S将油门在减为0后刹车会上来此时车速是8.51m/s以及一些其他参数。
3、官方例子
这次以官方例子进行介绍 #include chrono/core/ChStream.h
#include chrono/utils/ChUtilsInputOutput.h
#include chrono/utils/ChFilters.h
#include chrono_vehicle/ChConfigVehicle.h
#include chrono_vehicle/ChVehicleModelData.h
#include chrono_vehicle/terrain/RigidTerrain.h
#include chrono_vehicle/output/ChVehicleOutputASCII.h
#include chrono_models/vehicle/hmmwv/HMMWV.h
#include chrono_thirdparty/filesystem/path.h
#include chrono_vehicle/driver/ChInteractiveDriverIRR.h
#include chrono_vehicle/wheeled_vehicle/ChWheeledVehicleVisualSystemIrrlicht.h
#include iostreamusing namespace chrono;
using namespace chrono::irrlicht;
using namespace chrono::vehicle;
using namespace chrono::vehicle::hmmwv;// Simulation step sizes
double step_size 1e-3;
double tire_step_size step_size;
double t_end 1000;// Time interval between two render frames
double render_step_size 1.0 / 50; // FPS 50int main(int argc, char* argv[]) {chrono::SetChronoDataPath(E:/codeGit/chrono/chrono/build/data/); // change the default data loading path.chrono::vehicle::SetDataPath(E:/codeGit/chrono/chrono/build/data/vehicle/); // change the vehicle data pathChContactMethod contact_method ChContactMethod::SMC; // 设定碰撞类型// Create the HMMWV vehicle, set parameters, and initialize// 创建一个HMMWV车注意如果有vehicle模块则不需要重新定义一个物理系统这个vehicle自带一个系统可以直接给别的模块调用。HMMWV_Full hmmwv;hmmwv.SetCollisionSystemType(ChCollisionSystem::Type::BULLET);hmmwv.SetContactMethod(contact_method);hmmwv.SetChassisCollisionType(CollisionType::NONE);hmmwv.SetChassisFixed(false);hmmwv.SetInitPosition(ChCoordsys({ 0, 0, 0.5 }, { 1, 0, 0, 0 }));hmmwv.SetEngineType(EngineModelType::SHAFTS);hmmwv.SetTransmissionType(TransmissionModelType::SHAFTS);hmmwv.SetDriveType(DrivelineTypeWV::AWD);hmmwv.UseTierodBodies(true);hmmwv.SetSteeringType(SteeringTypeWV::PITMAN_ARM);hmmwv.SetBrakeType(BrakeType::SHAFTS);hmmwv.SetTireType(TireModelType::PAC02);hmmwv.SetTireStepSize(tire_step_size);hmmwv.Initialize();// Visualization type for vehicle parts (PRIMITIVES, MESH, or NONE)// 设置车辆各个模块的可视化程度。VisualizationType chassis_vis_type VisualizationType::PRIMITIVES;VisualizationType suspension_vis_type VisualizationType::PRIMITIVES;VisualizationType steering_vis_type VisualizationType::PRIMITIVES;VisualizationType wheel_vis_type VisualizationType::PRIMITIVES;VisualizationType tire_vis_type VisualizationType::PRIMITIVES;hmmwv.SetChassisVisualizationType(chassis_vis_type);hmmwv.SetSuspensionVisualizationType(suspension_vis_type);hmmwv.SetSteeringVisualizationType(steering_vis_type);hmmwv.SetWheelVisualizationType(wheel_vis_type);hmmwv.SetTireVisualizationType(tire_vis_type);// Create the terrain 创建地形并设置地形的一些物理参数。RigidTerrain terrain(hmmwv.GetSystem());ChContactMaterialData minfo;minfo.mu 0.9f;minfo.cr 0.01f;minfo.Y 2e7f;auto patch_mat minfo.CreateMaterial(contact_method);// Rigid terraindouble terrainHeight 0; // terrain height (FLAT terrain only)double terrainLength 200.0; // size in X directiondouble terrainWidth 200.0; // size in Y directionstd::shared_ptrRigidTerrain::Patch patch;patch terrain.AddPatch(patch_mat, CSYSNORM, terrainLength, terrainWidth);patch-SetTexture(vehicle::GetDataFile(terrain/textures/dirt.jpg), 200, 200);patch-SetColor(ChColor(0.8f, 0.8f, 0.5f));terrain.Initialize();// 创建基于irrlicht的可视化以及交互控制系统。定义每次控制量、可hi话等内容。// ------------------------------------------------------------------------------// Create the vehicle run-time visualization interface and the interactive driver// ------------------------------------------------------------------------------// Set the time response for steering and throttle keyboard inputs.double steering_time 1.0; // time to go from 0 to 1 (or from 0 to -1)double throttle_time 1.0; // time to go from 0 to 1double braking_time 0.3; // time to go from 0 to 1std::shared_ptrChVehicleVisualSystem vis;std::shared_ptrChDriver driver;// Create the vehicle Irrlicht interfaceauto vis_irr chrono_types::make_sharedChWheeledVehicleVisualSystemIrrlicht(); //~ ChWheeled这个类继承了可视化的基类vis_irr-SetWindowTitle(HMMWV Demo);vis_irr-SetChaseCamera({ 0.0, 0.0, 1.75 }, 6.0, 0.5); // 将可视化的“相机位置”和车底盘上一点绑定。vis_irr-Initialize();vis_irr-AddLightDirectional();vis_irr-AddSkyBox();vis_irr-AddLogo();vis_irr-AttachVehicle(hmmwv.GetVehicle()); // 将可视化与vehicle绑定// Create the interactive Irrlicht driver system 自定义每次按键的增量auto driver_irr chrono_types::make_sharedChInteractiveDriverIRR(*vis_irr);driver_irr-SetSteeringDelta(render_step_size / steering_time);driver_irr-SetThrottleDelta(render_step_size / throttle_time);driver_irr-SetBrakingDelta(render_step_size / braking_time);driver_irr-Initialize();vis vis_irr;driver driver_irr;// ---------------// Simulation loop// ---------------// Number of simulation steps between miscellaneous eventsint render_steps (int)std::ceil(render_step_size / step_size);// Initialize simulation frame countersint step_number 0;int render_frame 0;hmmwv.GetVehicle().EnableRealtime(true);while (vis-Run()) {double time hmmwv.GetSystem()-GetChTime();// End simulationif (time t_end)break;// Render scene and output post-processing dataif (step_number % render_steps 0) {vis-BeginScene();vis-Render();vis-EndScene();render_frame;}// Driver inputsDriverInputs driver_inputs driver-GetInputs();// Update modules (process inputs from other modules)driver-Synchronize(time);terrain.Synchronize(time);hmmwv.Synchronize(time, driver_inputs, terrain);vis-Synchronize(time, driver_inputs);// Advance simulation for one timestep for all modulesdriver-Advance(step_size);terrain.Advance(step_size);hmmwv.Advance(step_size);vis-Advance(step_size); //~ 更新vis的trackpoint等。// Increment frame numberstep_number;std::cout Step: step_number std::endl;}return 0;}
}运行这个例子就可以用WASD控制悍马车在自定义的一个地形上开动了。