Class CruiseControlModule
Holds a target speed with a PID controller on throttle, and on the brakes when applyBrakesWhenSpeeding is set. Forward motion only: it disengages when the vehicle stops or reverses, when the brake is pressed with deactivateOnBrake set, or on the cruise input.
Inherited Members
Namespace: NWH.VehiclePhysics2.Modules.CruiseControl
Assembly: NWH.VehiclePhysics2.dll
Syntax
[Serializable]
public class CruiseControlModule : VehicleComponent
Fields
Kd
Derivative gain. Damps rapid error changes and so limits overshoot. Usable range 0.05 to 0.3; higher is more stable but slower to respond.
Declaration
[Tooltip("Derivative gain of PID controller.")]
public float Kd
Field Value
| Type | Description |
|---|---|
| float |
Ki
Integral gain. Removes the steady-state offset, so raise it if speed settles off the target. Usable range 0.1 to 0.5; too high oscillates.
Declaration
[Tooltip("Integral gain of PID controller.")]
public float Ki
Field Value
| Type | Description |
|---|---|
| float |
Kp
Proportional gain, the main response to speed error. Usable range 0.3 to 1.0; higher matches the target faster but starts hunting.
Declaration
[Tooltip("Proportional gain of PID controller.")]
public float Kp
Field Value
| Type | Description |
|---|---|
| float |
applyBrakesWhenSpeeding
Lets cruise control brake when over the target speed. Off, it can only lift the throttle, so speed still builds on a descent.
Declaration
[Tooltip("If true brakes will be applied when speeding.")]
public bool applyBrakesWhenSpeeding
Field Value
| Type | Description |
|---|---|
| bool |
cruiseControlActive
True while cruise control is holding speed. Engagement normally runs off the cruise input; writing this field directly skips the target speed capture and the PID error seed, so set targetSpeed yourself on that path.
Declaration
[Tooltip("Is the cruise control currently active and trying to hold the vehicle speed?")]
public bool cruiseControlActive
Field Value
| Type | Description |
|---|---|
| bool |
deactivateOnBrake
Disengages cruise control as soon as the brakes are applied.
Declaration
[Tooltip("If true cruise control will be disabled if brakes are activated.")]
public bool deactivateOnBrake
Field Value
| Type | Description |
|---|---|
| bool |
setTargetSpeedOnEnable
Captures the current speed as the target when cruise control engages through the cruise input. Leave off to hold a previously set target speed; a non-positive target is captured either way.
Declaration
[Tooltip("Should the speed be captured automatically when cruise control is engaged?")]
public bool setTargetSpeedOnEnable
Field Value
| Type | Description |
|---|---|
| bool |
targetSpeed
Speed to hold, in m/s. Captured on engage or set manually. Roughly 10 to 20 m/s in town, 25 to 35 m/s on a highway.
Declaration
[Tooltip("The speed the vehicle will try to hold.")]
public float targetSpeed
Field Value
| Type | Description |
|---|---|
| float |
Methods
VC_Disable(bool)
Disables the cruise control module and unregisters input callbacks.
Declaration
public override bool VC_Disable(bool calledByParent)
Parameters
| Type | Name | Description |
|---|---|---|
| bool | calledByParent | Whether this was called by the parent component. |
Returns
| Type | Description |
|---|---|
| bool | True if successfully disabled. |
Overrides
VC_Enable(bool)
Enables the cruise control module and registers input callbacks.
Declaration
public override bool VC_Enable(bool calledByParent)
Parameters
| Type | Name | Description |
|---|---|---|
| bool | calledByParent | Whether this was called by the parent component. |
Returns
| Type | Description |
|---|---|
| bool | True if successfully enabled. |
Overrides
VC_FixedUpdate(float)
Runs the PID step and handles engage and disengage.
Declaration
public override void VC_FixedUpdate(float DeltaTime)
Parameters
| Type | Name | Description |
|---|---|---|
| float | DeltaTime | Fixed time step in seconds. |