Skip to content

Commit

Permalink
24 DOF GPU done
Browse files Browse the repository at this point in the history
  • Loading branch information
ishaanamahajan committed Mar 24, 2024
1 parent 717f66e commit 4c26a7d
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 30 deletions.
23 changes: 11 additions & 12 deletions wheeled_vehicle_models/24dof-gpu/dof24_gpu.cu
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ __device__ void d24GPU::vehToSusTransform(const VehicleState* v_states,
susrr_st->_vs = -v_params->_b * v_states->_wz + v_states->_v; // y direction
susrr_st->_ws = (-v_params->_cr * v_states->_wx / 2.) + v_params->_b * v_states->_wy + v_states->_w; // z direction

// Evalute the length of the struct and its compression velocity in current time step
// Evaluate the length of the struct and its compression velocity in current time step
// This is to get the unsprung mass velocity and accelerations in G-RF

// Instantaneous length of the strut
Expand Down Expand Up @@ -942,7 +942,7 @@ __device__ void d24GPU::computeTireRHS(const VehicleState* v_states,
double fs = hypot(fxs * calpha, fys * salpha);
double ss = hypot(sxs * calpha / hsxn, sys * salpha / hsyn);

// calculate force and force /slip from the curve characteritics
// calculate force and force /slip from the curve characteristics
double f, fos;
tmxy_combined(&f, &fos, sc, df0, sm, fm, ss, fs);

Expand All @@ -953,7 +953,7 @@ __device__ void d24GPU::computeTireRHS(const VehicleState* v_states,
t_states->_My =
-sineStep(vta, vx_min, 0., vx_max, 1.) * t_params->_rr * fz * t_states->_rStat * sgn(t_states->_omega);

// some normalised slip velocities
// some normalized slip velocities
double vtxs = r_eff * abs(t_states->_omega) * hsxn + 0.01;
double vtys = r_eff * abs(t_states->_omega) * hsyn + 0.01;

Expand All @@ -966,7 +966,7 @@ __device__ void d24GPU::computeTireRHS(const VehicleState* v_states,

// Also compute the tire forces that need to be applied on the vehicle
// Note here that these tire forces are computed using the current pre
// integreated xe, unline in the semi-implicit solver
// integrated xe, unline in the semi-implicit solver
double fxdyn = t_params->_dx * (-vtxs * t_params->_cx * t_states->_xe - fos * vsx) / (vtxs * t_params->_dx + fos) +
t_params->_cx * t_states->_xe;

Expand Down Expand Up @@ -1071,7 +1071,7 @@ __device__ void d24GPU::computeTireRHS(const VehicleState* v_states,
double sxs = InterpL(fz, t_params->_sxsPn, t_params->_sxsP2n, t_params->_pn);
double sys = InterpL(fz, t_params->_sysPn, t_params->_sysP2n, t_params->_pn);

// Compute the coefficient to "blend" the columb force with the slip force
// Compute the coefficient to "blend" the coulomb force with the slip force
double frblend = sineStep(abs(t_states->_vsx), t_params->_frblend_begin, 0., t_params->_frblend_end, 1.);
// Now standard TMeasy tire forces
// For now, not using any normalization of the slips - similar to Chrono implementation
Expand Down Expand Up @@ -1106,7 +1106,7 @@ __device__ void d24GPU::computeTireRHS(const VehicleState* v_states,
Fy = 0.;
}

// Now that we have both the columb force and the slip force, we can combine them with the sine blend to prevent
// Now that we have both the coulomb force and the slip force, we can combine them with the sine blend to prevent
// force jumping

Fx = (1.0 - frblend) * Fx0 + frblend * Fx;
Expand Down Expand Up @@ -1288,7 +1288,7 @@ __device__ double d24GPU::driveTorque(const VehicleParam* v_params, const double
powertrain_map[i]._y = v_params->_powertrainMap[i]._y * throttle;
}

// interpolate in the torque map to get the torque at this paticular
// interpolate in the torque map to get the torque at this particular
// speed
motor_torque = getMapY(powertrain_map, motor_speed, v_params->_powertrainMapSize);
double motor_losses = getMapY(v_params->_lossesMap, motor_speed, v_params->_lossesMapSize);
Expand Down Expand Up @@ -1438,7 +1438,7 @@ __device__ void d24GPU::computePowertrainRHS(VehicleState* v_states,
v_states->_crankOmega = 0.25 * (tirelf_st->_omega + tirerf_st->_omega + tirelr_st->_omega + tirerr_st->_omega) /
v_params->_gearRatios[v_states->_current_gr];

// The torque after tranny will then just become as there is no torque
// The torque after transmission will then just become as there is no torque
// converter
torque_t = driveTorque(v_params, controls->m_throttle, v_states->_crankOmega) /
v_params->_gearRatios[v_states->_current_gr];
Expand Down Expand Up @@ -1614,7 +1614,7 @@ __device__ void d24GPU::computePowertrainRHS(VehicleState* v_states,
v_states->_crankOmega = 0.25 * (tirelf_st->_omega + tirerf_st->_omega + tirelr_st->_omega + tirerr_st->_omega) /
v_params->_gearRatios[v_states->_current_gr];

// The torque after tranny will then just become as there is no torque
// The torque after transmission will then just become as there is no torque
// converter
torque_t = driveTorque(v_params, controls->m_throttle, v_states->_crankOmega) /
v_params->_gearRatios[v_states->_current_gr];
Expand Down Expand Up @@ -1804,8 +1804,7 @@ __host__ void d24GPU::setTireParamsJSON(TMeasyParam& t_params, const char* fileN
std::cout << "Error with rapidjson:" << std::endl << d.GetParseError() << std::endl;
}

// pray to what ever you believe in and hope that the json file has all
// these

t_params._jw = d["jw"].GetDouble();
t_params._rr = d["rr"].GetDouble();
t_params._r0 = d["r0"].GetDouble();
Expand Down Expand Up @@ -2203,7 +2202,7 @@ __host__ void d24GPU::setSuspensionParamsJSON(SuspensionParam& sus_params, const
std::cout << "Error with rapidjson:" << std::endl << d.GetParseError() << std::endl;
}

// pray to what ever you believe in and hope that the json file has all these

sus_params._ks = d["ks"].GetDouble();
sus_params._bs = d["bs"].GetDouble();
}
Expand Down
22 changes: 11 additions & 11 deletions wheeled_vehicle_models/24dof-gpu/dof24_gpu.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,8 @@ struct TMeasyParam {
// Longitudinal
double _dfx0Pn; //!< Initial longitudinal slopes dFx/dsx [N] at Nominal load
double _dfx0P2n; //!< Intial longitudinal slopes dFx/dsx [N] at max load
double _fxmPn; //!< Maximum longituidnal force [N] at nominal load
double _fxmP2n; //!< Maximum longituidnal force [N] at max load
double _fxmPn; //!< Maximum longitudinal force [N] at nominal load
double _fxmP2n; //!< Maximum longitudinal force [N] at max load
double _fxsPn; //!< Longitudinal load at sliding [N] at nominal load
double _fxsP2n; //!< Longitudinal load at sliding [N] at max load
double _sxmPn; //!< Slip sx at maximum longitudinal load Fx at nominal load
Expand Down Expand Up @@ -416,8 +416,8 @@ struct TMeasyNrParam {
// Longitudinal
double _dfx0Pn; //!< Initial longitudinal slopes dFx/dsx [N] at Nominal load
double _dfx0P2n; //!< Intial longitudinal slopes dFx/dsx [N] at max load
double _fxmPn; //!< Maximum longituidnal force [N] at nominal load
double _fxmP2n; //!< Maximum longituidnal force [N] at max load
double _fxmPn; //!< Maximum longitudinal force [N] at nominal load
double _fxmP2n; //!< Maximum longitudinal force [N] at max load
double _fxsPn; //!< Longitudinal load at sliding [N] at nominal load
double _fxsP2n; //!< Longitudinal load at sliding [N] at max load
double _sxmPn; //!< Slip sx at maximum longitudinal load Fx at nominal load
Expand Down Expand Up @@ -581,7 +581,7 @@ struct TMeasyNrState {
// Vehicle Structs
// -----------------------------------------------------------------------------
/// @brief Defined here are chassis, engine/motor, powertrain, driveline and steering parameters required for the
/// simualtion of a 24 DOF model.
/// simulation of a 24 DOF model.

/// The 24 DOF model, which considers the suspension at each corner, offers the same
/// benefits as the 18 DOF model, but it can also predict vehicle heave and pitch motions.
Expand Down Expand Up @@ -655,7 +655,7 @@ struct VehicleParam {
_TRmapSize(other->_TRmapSize),
_shiftMap(other->_shiftMap) {}

// Declaration of all the 14 DOF vehicle parameters pretty much the same as the 8DOF model
// Declaration of all the 24 DOF vehicle parameters pretty much the same as the 18 DOF model
double _a; //!< Distance of C.G to front axle (m)
double _b; //!< Distance of C.G to rear axle (m)
double _h; //!< Height of C.G
Expand Down Expand Up @@ -713,7 +713,7 @@ struct VehicleParam {
bool _tcbool; //!< Boolean that checks for the presence of a torque converter. Can be set using "tcBool" in the
//!< JSON file. Defaults to 0 if not specified.

double _maxBrakeTorque; //!< The maximum braking torque (Nm) that the brakes applu to the wheels. Can be set using
double _maxBrakeTorque; //!< The maximum braking torque (Nm) that the brakes apply to the wheels. Can be set using
//!< "maxBrakeTorque" in the JSON file. Based on the normalized brake input between 0 and
//!< 1, a torque input*_maxBrakeTorque is applied to the wheel.

Expand Down Expand Up @@ -788,7 +788,7 @@ struct VehicleParam {
};

/// @brief The VehicleState struct holds the chassis, engine/motor, powertrain, driveline and steering states required
/// for the simualtion.
/// for the simulation.

/// Apart from the states that are updated by time integration, this struct also holds "non-states"
/// such as accelerations, forces and torques that are not updated by time integration. See here for more details
Expand Down Expand Up @@ -1110,7 +1110,7 @@ struct SuspensionState {

/// In essence, this
/// stores all the "data" required to simulate 1 vehicle on the GPU. This is something largely the user does not have to
/// worrry about.
/// worry about.
struct SimData {
SimData() : _driver_data(nullptr), _driver_data_len(0) {}

Expand Down Expand Up @@ -1473,7 +1473,7 @@ __device__ void computeForcesThroughSus(const VehicleState* v_states,
/// input parameters
__device__ void tmxy_combined(double* f, double* fos, double s, double df0, double sm, double fm, double ss, double fs);

/// @brief Computes the combined columnb force for the TMeasyNr tire model
/// @brief Computes the combined coulomb force for the TMeasyNr tire model

/// This force provides the stability at low speeds and is belnded with the slip force provided by the tmxy_combined
/// function.
Expand All @@ -1497,7 +1497,7 @@ __device__ void computeTireRHS(const VehicleState* v_states,
/// @brief Computes the tire forces for the TMeasyNr tire model in the tire contact patch frame (T-RF)

/// For the TMeasyNr tire model, since there is no relaxation, the tire forces from slip are blended with the tire
/// forces from columb friction. The blend coefficient depends on the longitudinal slip velocity of the tire. This model
/// forces from coulomb friction. The blend coefficient depends on the longitudinal slip velocity of the tire. This model
/// is an approximation of the original TMeasy tire model and is inspired by the Project Chrono implementation (see code
/// at https://github.com/projectchrono/chrono/blob/main/src/chrono_vehicle/wheeled_vehicle/tire/ChTMeasyTire.h).
/// @param v_states Vehicle States
Expand Down
8 changes: 4 additions & 4 deletions wheeled_vehicle_models/24dof-gpu/dof24_halfImplicit_gpu.cu
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ __host__ void d24SolverHalfImplicitGPU::Initialize(d24GPU::VehicleState& vehicle
d24GPU::SuspensionState& sus_states_LR,
d24GPU::SuspensionState& sus_states_RR,
unsigned int num_vehicles) {
// Esnure that construct was called with TMeasy tire type
// Ensure that construct was called with TMeasy tire type
assert((m_tire_type == TireType::TMeasy) &&
"Construct function called with TMeasyNr tire type, but Initialize called with TMeasy tire type");
assert((num_vehicles + m_vehicle_count_tracker_states <= m_total_num_vehicles) &&
Expand Down Expand Up @@ -354,7 +354,7 @@ __host__ void d24SolverHalfImplicitGPU::Initialize(d24GPU::VehicleState& vehicle
d24GPU::SuspensionState& sus_states_LR,
d24GPU::SuspensionState& sus_states_RR,
unsigned int num_vehicles) {
// Esnure that construct was called with TMeasy tire type
// Ensure that construct was called with TMeasy tire type
assert((m_tire_type == TireType::TMeasy) &&
"Construct function called with TMeasyNr tire type, but Initialize called with TMeasy tire type");
assert((num_vehicles + m_vehicle_count_tracker_states <= m_total_num_vehicles) &&
Expand Down Expand Up @@ -390,7 +390,7 @@ __host__ void d24SolverHalfImplicitGPU::SetOutput(const std::string& output_file
m_store_all = store_all;
if (!m_store_all) {
// Check if number of outputs asked is greater than the total number of vehicles, if this is the case, raise
// awarning and set to m_total_num_vehicles
// a warning and set to m_total_num_vehicles
if (no_outs > m_total_num_vehicles) {
std::cout << "Number of outputs asked is greater than the total number of vehicles, setting number of "
"outputs to total number of vehicles"
Expand Down Expand Up @@ -506,7 +506,7 @@ __host__ void d24SolverHalfImplicitGPU::Solve() {

// If we have to save output, copy over the device into the response
if (m_output) {
// Amount of respoonse already filled
// Amount of response already filled
unsigned int filled_response = m_total_num_vehicles * m_collection_states * m_device_collection_timeSteps *
kernel_launches_since_last_dump;

Expand Down
6 changes: 3 additions & 3 deletions wheeled_vehicle_models/24dof-gpu/dof24_halfImplicit_gpu.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class d24SolverHalfImplicitGPU {
/// Each of these vehicles will have the specified parameters and driver inputs. To add
/// more vehicles (ensuring they are still lesser than the total number of vehicles initally specified in the class
/// constructor) with different parameters, call the Construct function again. The tire type defaults to TMEasy and
/// is set for all the vehilces. It is also important to note thet the TireType has to be consistent across all the
/// is set for all the vehicles. It is also important to note thet the TireType has to be consistent across all the
/// vehicles currently. For examples of use, see demos.
/// @param vehicle_params_file Path to the vehicle parameter json file
/// @param tire_params_file Path to the tire parameter json file
Expand Down Expand Up @@ -82,7 +82,7 @@ class d24SolverHalfImplicitGPU {
/// parameters. This is mainly provided for cases where the driver inputs are not available at the start of the
/// simulation but rather come from a controller during the simualtion and the user wants to specify a TireType. To
/// add more vehicles with different parameters, call the Construct function again. It is also important to note
/// thet the TireType has to be consistent across all the vehicles currently. For examples of use, see demos.
/// that the TireType has to be consistent across all the vehicles currently. For examples of use, see demos.
/// @param vehicle_params_file Path to the vehicle parameter json file
/// @param tire_params_file Path to the tire parameter json file
/// @param sus_params_file Path to the suspension parameter json file
Expand Down Expand Up @@ -365,7 +365,7 @@ class d24SolverHalfImplicitGPU {
// Need a bunch of csv writers for each of the vehicles. We will store a pointer to this list
std::unique_ptr<CSV_writer[]> m_csv_writers_ptr;
};
// Cannout have global function as class member function
// Cannot have global function as class member function
/// @brief Integrate the system of equations using the half implicit method - Calls the RHS function at each time step

/// Used internally within Solve
Expand Down

0 comments on commit 4c26a7d

Please sign in to comment.