<commit_before>// =============================================================================
// PROJECT CHRONO - http://projectchrono.org
//
// Copyright (c) 2014 projectchrono.org
// All right reserved.
//
// Use of this source code is governed by a BSD-style license that can be found
// in the LICENSE file at the top level of the distribution and at
// http://projectchrono.org/license-chrono.txt.
//
// =============================================================================
// Authors: <NAME>
// =============================================================================
//
// Main driver function for a vehicle specified through JSON files.
//
// If using the Irrlicht interface, driver inputs are obtained from the keyboard.
//
// The vehicle reference frame has Z up, X towards the front of the vehicle, and
// Y pointing to the left.
//
// =============================================================================

#include <vector>

#include "core/ChFileutils.h"
#include "core/ChStream.h"
#include "core/ChRealtimeStep.h"
#include "physics/ChSystem.h"
#include "physics/ChLinkDistance.h"

#include "ChronoVehicle_config.h"

#include "utils/ChUtilsInputOutput.h"

#include "subsys/ChVehicleModelData.h"

#include "subsys/vehicle/Vehicle.h"
#include "subsys/powertrain/SimplePowertrain.h"
#include "subsys/driver/ChDataDriver.h"
#include "subsys/tire/RigidTire.h"
#include "subsys/terrain/RigidTerrain.h"

// If Irrlicht support is available...
#if IRRLICHT_ENABLED
  // ...include additional headers
# include "unit_IRRLICHT/ChIrrApp.h"
# include "subsys/driver/ChIrrGuiDriver.h"

  // ...and specify whether the demo should actually use Irrlicht
# define USE_IRRLICHT
#endif

using namespace chrono;

// =============================================================================

// JSON file for vehicle model
//std::string vehicle_file("hmmwv/vehicle/HMMWV_Vehicle.json");
//std::string vehicle_file("hmmwv/vehicle/HMMWV_Vehicle_simple_lugged.json");
//std::string vehicle_file("hmmwv/vehicle/HMMWV_Vehicle_4WD.json");
std::string vehicle_file("generic/vehicle/Vehicle_DoubleWishbones.json");
//std::string vehicle_file("generic/vehicle/Vehicle_DoubleWishbones_ARB.json");
//std::string vehicle_file("generic/vehicle/Vehicle_MultiLinks.json");
//std::string vehicle_file("generic/vehicle/Vehicle_SolidAxles.json");
//std::string vehicle_file("generic/vehicle/Vehicle_ThreeAxles.json");
//std::string vehicle_file("generic/vehicle_multisteer/Vehicle_DualFront_Independent.json");
//std::string vehicle_file("generic/vehicle_multisteer/Vehicle_DualFront_Shared.json");

// JSON files for tire models (rigid) and powertrain (simple)
std::string rigidtire_file("generic/tire/RigidTire.json");
std::string simplepowertrain_file("generic/powertrain/SimplePowertrain.json");

// Driver input file (if not using Irrlicht)
std::string driver_file("generic/driver/Sample_Maneuver.txt");

// Initial vehicle position
ChVector<> initLoc(0, 0, 1.0);

// Initial vehicle orientation
ChQuaternion<> initRot(1, 0, 0, 0);
//ChQuaternion<> initRot(0.866025, 0, 0, 0.5);
//ChQuaternion<> initRot(0.7071068, 0, 0, 0.7071068);
//ChQuaternion<> initRot(0.25882, 0, 0, 0.965926);
//ChQuaternion<> initRot(0, 0, 0, 1);

// Rigid terrain dimensions
double terrainHeight = 0;
double terrainLength = 100.0;   // size in X direction
double terrainWidth  = 100.0;   // size in Y direction

// Simulation step size
double step_size = 1e-3;

// Time interval between two render frames
double render_step_size = 1.0 / 50;   // FPS = 50

// Time interval between two output frames
double output_step_size = 1.0 / 1;    // once a second

// Point on chassis tracked by the camera (Irrlicht only)
ChVector<> trackPoint(0.0, 0.0, 1.75);

// Simulation length (Povray only)
double tend = 20.0;

// Output directories (Povray only)
const std::string out_dir = "../VEHICLE";
const std::string pov_dir = out_dir + "/POVRAY";

// =============================================================================

int main(int argc, char* argv[])
{
  SetChronoDataPath(CHRONO_DATA_DIR);

  // --------------------------
  // Create the various modules
  // --------------------------

  // Create the vehicle system
  Vehicle vehicle(vehicle::GetDataFile(vehicle_file));
  vehicle.Initialize(ChCoordsys<>(initLoc, initRot));
  ////vehicle.GetChassis()->SetBodyFixed(true);

  // Create the ground
  RigidTerrain terrain(vehicle.GetSystem(), terrainHeight, terrainLength, terrainWidth, 0.8);

  // Create and initialize the powertrain system
  SimplePowertrain powertrain(vehicle::GetDataFile(simplepowertrain_file));
  powertrain.Initialize();

  // Create and initialize the tires
  int num_axles = vehicle.GetNumberAxles();
  int num_wheels = 2 * num_axles;
  std::vector<ChSharedPtr<RigidTire> > tires(num_wheels);

  for (int i = 0; i < num_wheels; i++) {
    tires[i] = ChSharedPtr<RigidTire>(new RigidTire(vehicle::GetDataFile(rigidtire_file), terrain));
    tires[i]->Initialize(vehicle.GetWheelBody(i));
  }

#ifdef USE_IRRLICHT

  irr::ChIrrApp application(vehicle.GetSystem(),
                            L"Vehicle demo",
                            irr::core::dimension2d<irr::u32>(1000, 800),
                            false,
                            true);

  // make a skybox that has Z pointing up (default application.AddTypicalSky() makes Y up) 
  std::string mtexturedir = GetChronoDataFile("skybox/");
  std::string str_lf = mtexturedir + "sky_lf.jpg";
  std::string str_up = mtexturedir + "sky_up.jpg";
  std::string str_dn = mtexturedir + "sky_dn.jpg";
  irr::video::ITexture* map_skybox_side = 
      application.GetVideoDriver()->getTexture(str_lf.c_str());
  irr::scene::ISceneNode* mbox = application.GetSceneManager()->addSkyBoxSceneNode(
      application.GetVideoDriver()->getTexture(str_up.c_str()),
      application.GetVideoDriver()->getTexture(str_dn.c_str()),
      map_skybox_side,
      map_skybox_side,
      map_skybox_side,
      map_skybox_side);
  mbox->setRotation( irr::core::vector3df(90,0,0));
 
  bool do_shadows = false; // shadow map is experimental
  irr::scene::ILightSceneNode* mlight = 0;

  if (do_shadows) {
    mlight = application.AddLightWithShadow(
      irr::core::vector3df(10.f, 30.f, 60.f),
      irr::core::vector3df(0.f, 0.f, 0.f),
      150, 60, 80, 15, 512, irr::video::SColorf(1, 1, 1), false, false);
  } else {
    application.AddTypicalLights(
      irr::core::vector3df(30.f, -30.f, 100.f),
      irr::core::vector3df(30.f, 50.f, 100.f),
      250, 130);
  }

  application.SetTimestep(step_size);

  ChIrrGuiDriver driver(application, vehicle, powertrain, trackPoint, 6.0, 0.5, true);

  // Set the time response for steering and throttle keyboard inputs.
  // NOTE: this is not exact, since we do not render quite at the specified FPS.
  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 +1
  double braking_time = 0.3;   // time to go from 0 to +1
  driver.SetSteeringDelta(render_step_size / steering_time);
  driver.SetThrottleDelta(render_step_size / throttle_time);
  driver.SetBrakingDelta(render_step_size / braking_time);

  // Set up the assets for rendering
  application.AssetBindAll();
  application.AssetUpdateAll();
  if (do_shadows)
    application.AddShadowAll();

#else

  ChDataDriver driver(vehicle::GetDataFile(driver_file));

#endif
<commit_msg>Enable option in demo_Vehicle for using driver inputs from file.<commit_after>// =============================================================================
// PROJECT CHRONO - http://projectchrono.org
//
// Copyright (c) 2014 projectchrono.org
// All right reserved.
//
// Use of this source code is governed by a BSD-style license that can be found
// in the LICENSE file at the top level of the distribution and at
// http://projectchrono.org/license-chrono.txt.
//
// =============================================================================
// Authors: <NAME>
// =============================================================================
//
// Main driver function for a vehicle specified through JSON files.
//
// If using the Irrlicht interface, driver inputs are obtained from the keyboard.
//
// The vehicle reference frame has Z up, X towards the front of the vehicle, and
// Y pointing to the left.
//
// =============================================================================

#include <vector>

#include "core/ChFileutils.h"
#include "core/ChStream.h"
#include "core/ChRealtimeStep.h"
#include "physics/ChSystem.h"
#include "physics/ChLinkDistance.h"

#include "ChronoVehicle_config.h"

#include "utils/ChUtilsInputOutput.h"

#include "subsys/ChVehicleModelData.h"

#include "subsys/vehicle/Vehicle.h"
#include "subsys/powertrain/SimplePowertrain.h"
#include "subsys/driver/ChDataDriver.h"
#include "subsys/tire/RigidTire.h"
#include "subsys/terrain/RigidTerrain.h"

// If Irrlicht support is available...
#if IRRLICHT_ENABLED
  // ...include additional headers
# include "unit_IRRLICHT/ChIrrApp.h"
# include "subsys/driver/ChIrrGuiDriver.h"

  // ...and specify whether the demo should actually use Irrlicht
# define USE_IRRLICHT
#endif

using namespace chrono;

// =============================================================================

// JSON file for vehicle model
//std::string vehicle_file("hmmwv/vehicle/HMMWV_Vehicle.json");
//std::string vehicle_file("hmmwv/vehicle/HMMWV_Vehicle_simple_lugged.json");
//std::string vehicle_file("hmmwv/vehicle/HMMWV_Vehicle_4WD.json");
std::string vehicle_file("generic/vehicle/Vehicle_DoubleWishbones.json");
//std::string vehicle_file("generic/vehicle/Vehicle_DoubleWishbones_ARB.json");
//std::string vehicle_file("generic/vehicle/Vehicle_MultiLinks.json");
//std::string vehicle_file("generic/vehicle/Vehicle_SolidAxles.json");
//std::string vehicle_file("generic/vehicle/Vehicle_ThreeAxles.json");
//std::string vehicle_file("generic/vehicle_multisteer/Vehicle_DualFront_Independent.json");
//std::string vehicle_file("generic/vehicle_multisteer/Vehicle_DualFront_Shared.json");

// JSON files for tire models (rigid) and powertrain (simple)
std::string rigidtire_file("generic/tire/RigidTire.json");
std::string simplepowertrain_file("generic/powertrain/SimplePowertrain.json");

// Driver input file (if not using Irrlicht)
std::string driver_file("generic/driver/Sample_Maneuver.txt");

// Initial vehicle position
ChVector<> initLoc(0, 0, 1.0);

// Initial vehicle orientation
ChQuaternion<> initRot(1, 0, 0, 0);
//ChQuaternion<> initRot(0.866025, 0, 0, 0.5);
//ChQuaternion<> initRot(0.7071068, 0, 0, 0.7071068);
//ChQuaternion<> initRot(0.25882, 0, 0, 0.965926);
//ChQuaternion<> initRot(0, 0, 0, 1);

// Rigid terrain dimensions
double terrainHeight = 0;
double terrainLength = 300.0;   // size in X direction
double terrainWidth  = 200.0;   // size in Y direction

// Simulation step size
double step_size = 1e-3;

// Time interval between two render frames
double render_step_size = 1.0 / 50;   // FPS = 50

// Time interval between two output frames
double output_step_size = 1.0 / 1;    // once a second

// Point on chassis tracked by the camera (Irrlicht only)
ChVector<> trackPoint(0.0, 0.0, 1.75);

// Simulation length (Povray only)
double tend = 20.0;

// Output directories (Povray only)
const std::string out_dir = "../VEHICLE";
const std::string pov_dir = out_dir + "/POVRAY";

// =============================================================================

int main(int argc, char* argv[])
{
  SetChronoDataPath(CHRONO_DATA_DIR);

  // --------------------------
  // Create the various modules
  // --------------------------

  // Create the vehicle system
  Vehicle vehicle(vehicle::GetDataFile(vehicle_file));
  vehicle.Initialize(ChCoordsys<>(initLoc, initRot));
  ////vehicle.GetChassis()->SetBodyFixed(true);

  // Create the ground
  RigidTerrain terrain(vehicle.GetSystem(), terrainHeight, terrainLength, terrainWidth, 0.8);

  // Create and initialize the powertrain system
  SimplePowertrain powertrain(vehicle::GetDataFile(simplepowertrain_file));
  powertrain.Initialize();

  // Create and initialize the tires
  int num_axles = vehicle.GetNumberAxles();
  int num_wheels = 2 * num_axles;
  std::vector<ChSharedPtr<RigidTire> > tires(num_wheels);

  for (int i = 0; i < num_wheels; i++) {
    tires[i] = ChSharedPtr<RigidTire>(new RigidTire(vehicle::GetDataFile(rigidtire_file), terrain));
    tires[i]->Initialize(vehicle.GetWheelBody(i));
  }

#ifdef USE_IRRLICHT

  irr::ChIrrApp application(vehicle.GetSystem(),
                            L"Vehicle demo",
                            irr::core::dimension2d<irr::u32>(1000, 800),
                            false,
                            true);

  // make a skybox that has Z pointing up (default application.AddTypicalSky() makes Y up) 
  std::string mtexturedir = GetChronoDataFile("skybox/");
  std::string str_lf = mtexturedir + "sky_lf.jpg";
  std::string str_up = mtexturedir + "sky_up.jpg";
  std::string str_dn = mtexturedir + "sky_dn.jpg";
  irr::video::ITexture* map_skybox_side = 
      application.GetVideoDriver()->getTexture(str_lf.c_str());
  irr::scene::ISceneNode* mbox = application.GetSceneManager()->addSkyBoxSceneNode(
      application.GetVideoDriver()->getTexture(str_up.c_str()),
      application.GetVideoDriver()->getTexture(str_dn.c_str()),
      map_skybox_side,
      map_skybox_side,
      map_skybox_side,
      map_skybox_side);
  mbox->setRotation( irr::core::vector3df(90,0,0));
 
  bool do_shadows = false; // shadow map is experimental
  irr::scene::ILightSceneNode* mlight = 0;

  if (do_shadows) {
    mlight = application.AddLightWithShadow(
      irr::core::vector3df(10.f, 30.f, 60.f),
      irr::core::vector3df(0.f, 0.f, 0.f),
      150, 60, 80, 15, 512, irr::video::SColorf(1, 1, 1), false, false);
  } else {
    application.AddTypicalLights(
      irr::core::vector3df(30.f, -30.f, 100.f),
      irr::core::vector3df(30.f, 50.f, 100.f),
      250, 130);
  }

  application.SetTimestep(step_size);

  ChIrrGuiDriver driver(application, vehicle, powertrain, trackPoint, 6.0, 0.5, true);

  // Set the time response for steering and throttle keyboard inputs.
  // NOTE: this is not exact, since we do not render quite at the specified FPS.
  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 +1
  double braking_time = 0.3;   // time to go from 0 to +1
  driver.SetSteeringDelta(render_step_size / steering_time);
  driver.SetThrottleDelta(render_step_size / throttle_time);
  driver.SetBrakingDelta(render_step_size / braking_time);

  // Set file with driver input time series
  driver.SetInputDataFile(vehicle::GetDataFile(driver_file));

  // Set up the assets for rendering
  application.AssetBindAll();
  application.AssetUpdateAll();
  if (do_shadows)
    application.AddShadowAll();

#else

  ChDataDriver driver(vehicle::GetDataFile(driver_file));

#endif

{'fraction_non_alphanumeric': 0.19224091880341881, 'fraction_numerical': 0.023637820512820512, 'mean_word_length': 4.240377886634009, 'pattern_counts': {'":': 0, '<': 33, '<?xml version=': 0, '>': 45, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1884693', 'n_tokens_mistral': 5110, 'n_tokens_neox': 4768, 'n_words': 1121}