Description

Interactive driver for the a vehicle.

This class implements support for keyboard or joystick control of a vehicle, but is independent of a particular implementation of a keyboard/joystick event handler.

#include <ChInteractiveDriver.h>

Inheritance diagram for chrono::vehicle::ChInteractiveDriver:
Collaboration diagram for chrono::vehicle::ChInteractiveDriver:

Public Types

enum  InputMode { InputMode::LOCK, InputMode::KEYBOARD, InputMode::JOYSTICK }
 Functioning modes for a ChInteractiveDriver. More...
 
enum  KeyboardMode { KeyboardMode::CUMULATIVE, KeyboardMode::HELD }
 Semantics of the keyboard driving controls (used only in InputMode::KEYBOARD). More...
 
enum  InputKey {
  InputKey::THROTTLE, InputKey::BRAKE, InputKey::STEER_LEFT, InputKey::STEER_RIGHT,
  InputKey::CLUTCH
}
 Driving controls tracked in KeyboardMode::HELD. More...
 

Public Member Functions

 ChInteractiveDriver (ChVehicle &vehicle)
 Construct an interactive driver.
 
virtual bool HasJoystick () const
 Check if joystick is supported.
 
void SetInputMode (InputMode mode)
 Set the current functioning mode.
 
InputMode GetInputMode () const
 
void SetKeyboardMode (KeyboardMode mode)
 Select the semantics of the keyboard driving controls. More...
 
KeyboardMode GetKeyboardMode () const
 
void SetDefaultKeyboardMode (KeyboardMode mode)
 Propose a keyboard mode, to be called by an input backend that knows which modes it can support. More...
 
void SetKeyState (InputKey key, bool pressed)
 Report that a driving control key was pressed (true) or released (false). More...
 
void ReleaseAllKeys ()
 Report that all driving control keys are released. More...
 
void SetThrottleDelta (double delta)
 Set the increment in throttle input for each recorded keypress (default 1/50). More...
 
void SetSteeringDelta (double delta)
 Set the increment in steering input for each recorded keypress (default 1/50). More...
 
void SetBrakingDelta (double delta)
 Set the increment in braking input for each recorded keypress (default 1/50). More...
 
void SetClutchDelta (double delta)
 Set the increment in clutch input for each recorded keypress (default 1/50). More...
 
void SetStepsize (double val)
 Set the step size for integration of the internal driver dynamics.
 
void SetGains (double steering_gain=1, double throttle_gain=1, double braking_gain=1, double clutch_gain=1)
 Set gains for internal dynamics (default values are 4.0). More...
 
void IncreaseThrottle ()
 Increase Throttle (KeyboardMode::CUMULATIVE)
 
void DecreaseThrottle ()
 Decrease Throttle (KeyboardMode::CUMULATIVE)
 
void SteeringLeft ()
 Steering Left (KeyboardMode::CUMULATIVE)
 
void SteeringRight ()
 Steering Right (KeyboardMode::CUMULATIVE)
 
void IncreaseClutch ()
 Increase Clutch (KeyboardMode::CUMULATIVE)
 
void DecreaseClutch ()
 Decrease Clutch (KeyboardMode::CUMULATIVE)
 
void SteeringCenter ()
 Center Steering.
 
void ReleasePedals ()
 Release Pedals.
 
virtual void Synchronize (double time) override
 Update the state of this driver system at the specified time.
 
virtual void Advance (double step) override
 Advance the state of this driver system by the specified time step.
 
- Public Member Functions inherited from chrono::vehicle::ChDriver
 ChDriver (ChVehicle &vehicle)
 Construct a driver subsystem associated with the given vehicle.
 
double GetThrottle () const
 Get the driver throttle input (in the range [0,1]).
 
double GetSteering () const
 Get the driver steering input (in the range [-1,+1]).
 
double GetBraking () const
 Get the driver braking input (in the range [0,1]).
 
double GetClutch () const
 Get the driver clutch input (in the range [0,1]).
 
DriverInputs GetInputs () const
 Get all current inputs at once.
 
virtual void Initialize ()
 Initialize this driver system.
 
bool LogInit (const std::string &filename)
 Initialize output file for recording driver inputs.
 
bool Log (double time)
 Record the current driver inputs to the log file.
 
void SetSteering (double steering)
 Overwrite the value for the driver steering input (input is clamped in [-1,+1]).
 
void SetThrottle (double throttle)
 Overwrite the value for the driver throttle input (input is clamped in [0,+1]).
 
void SetBraking (double braking)
 Overwrite the value for the driver braking input (input is clamped in [0,+1]).
 
void SetClutch (double clutch)
 Overwrite the value for the clutch braking input (input is clamped in [0,+1]).
 
virtual void WriteCheckpoint (ChCheckpoint::Format format, const std::string &filename) const
 Checkpoint the state of this driver to the given checkpoint file. More...
 
virtual void ReadCheckpoint (ChCheckpoint::Format format, const std::string &filename)
 Initialize this driver from the given checkpoint file. More...
 

Protected Member Functions

void UpdateTargetsFromHeldKeys ()
 Recompute the input targets from the set of keys currently held down (KeyboardMode::HELD).
 

Protected Attributes

InputMode m_mode
 current mode of the driver
 
KeyboardMode m_keyboard_mode
 semantics of the keyboard driving controls
 
bool m_keyboard_mode_user_set
 application explicitly selected a keyboard mode
 
bool m_key_throttle
 throttle key currently held down
 
bool m_key_brake
 brake key currently held down
 
bool m_key_steer_left
 steer-left key currently held down
 
bool m_key_steer_right
 steer-right key currently held down
 
bool m_key_clutch
 clutch key currently held down
 
double m_steering_target
 current target value for steering input
 
double m_throttle_target
 current target value for throttle input
 
double m_braking_target
 current target value for braking input
 
double m_clutch_target
 current target value for clutch input
 
double m_stepsize
 time step for internal dynamics
 
double m_steering_delta
 steering increment on each keypress
 
double m_throttle_delta
 throttle increment on each keypress
 
double m_braking_delta
 braking increment on each keypress
 
double m_clutch_delta
 clutch increment on each keypress
 
double m_steering_gain
 gain for steering internal dynamics
 
double m_throttle_gain
 gain for throttle internal dynamics
 
double m_braking_gain
 gain for braking internal dynamics
 
double m_clutch_gain
 gain for clutch internal dynamics
 
- Protected Attributes inherited from chrono::vehicle::ChDriver
ChVehiclem_vehicle
 reference to associated vehicle
 
double m_throttle
 current value of throttle input
 
double m_steering
 current value of steering input
 
double m_braking
 current value of braking input
 
double m_clutch
 current value of clutch input
 

Member Enumeration Documentation

◆ InputKey

Driving controls tracked in KeyboardMode::HELD.

Enumerator
THROTTLE 

accelerator pedal (default key 'W')

BRAKE 

brake pedal (default key 'S')

STEER_LEFT 

steer left (default key 'A')

STEER_RIGHT 

steer right (default key 'D')

CLUTCH 

clutch pedal (default key 'E'; manual transmission only)

◆ InputMode

Functioning modes for a ChInteractiveDriver.

Enumerator
LOCK 

driver inputs locked at current values

KEYBOARD 

driver inputs from keyboard

JOYSTICK 

driver inputs from joystick

◆ KeyboardMode

Semantics of the keyboard driving controls (used only in InputMode::KEYBOARD).

Enumerator
CUMULATIVE 

each keypress nudges the input by a fixed increment; historical Chrono::Vehicle behavior

HELD 

inputs follow the keys currently held down, as in a driving game (see SetKeyState)

Member Function Documentation

◆ ReleaseAllKeys()

void chrono::vehicle::ChInteractiveDriver::ReleaseAllKeys ( )

Report that all driving control keys are released.

Call this when the input backend can no longer observe the keyboard (e.g., on loss of window focus), so that inputs do not stay pinned at their last value.

◆ SetBrakingDelta()

void chrono::vehicle::ChInteractiveDriver::SetBrakingDelta ( double  delta)
inline

Set the increment in braking input for each recorded keypress (default 1/50).

Used only in KeyboardMode::CUMULATIVE.

◆ SetClutchDelta()

void chrono::vehicle::ChInteractiveDriver::SetClutchDelta ( double  delta)
inline

Set the increment in clutch input for each recorded keypress (default 1/50).

Used only in KeyboardMode::CUMULATIVE.

◆ SetDefaultKeyboardMode()

void chrono::vehicle::ChInteractiveDriver::SetDefaultKeyboardMode ( KeyboardMode  mode)

Propose a keyboard mode, to be called by an input backend that knows which modes it can support.

Has no effect if the application already made an explicit call to SetKeyboardMode.

◆ SetGains()

void chrono::vehicle::ChInteractiveDriver::SetGains ( double  steering_gain = 1,
double  throttle_gain = 1,
double  braking_gain = 1,
double  clutch_gain = 1 
)

Set gains for internal dynamics (default values are 4.0).

Each input approaches its target exponentially with time constant 1/gain; in KeyboardMode::HELD this also sets how fast a held key ramps an input up or down.

◆ SetKeyboardMode()

void chrono::vehicle::ChInteractiveDriver::SetKeyboardMode ( KeyboardMode  mode)

Select the semantics of the keyboard driving controls.

Takes precedence over any default proposed by an input backend (see SetDefaultKeyboardMode).

◆ SetKeyState()

void chrono::vehicle::ChInteractiveDriver::SetKeyState ( InputKey  key,
bool  pressed 
)

Report that a driving control key was pressed (true) or released (false).

Used only in KeyboardMode::HELD. Calls are idempotent, so key auto-repeat is harmless.

◆ SetSteeringDelta()

void chrono::vehicle::ChInteractiveDriver::SetSteeringDelta ( double  delta)
inline

Set the increment in steering input for each recorded keypress (default 1/50).

Used only in KeyboardMode::CUMULATIVE.

◆ SetThrottleDelta()

void chrono::vehicle::ChInteractiveDriver::SetThrottleDelta ( double  delta)
inline

Set the increment in throttle input for each recorded keypress (default 1/50).

Used only in KeyboardMode::CUMULATIVE.


The documentation for this class was generated from the following files:
  • /builds/uwsbel/chrono/src/chrono_vehicle/driver/ChInteractiveDriver.h
  • /builds/uwsbel/chrono/src/chrono_vehicle/driver/ChInteractiveDriver.cpp