Accessibility: Driving Cruise Control

GPC2 script programming for Titan Two. Code examples, questions, requests.

Accessibility: Driving Cruise Control

Postby SpecialEffect » Thu Oct 14, 2021 11:01 am

Activision's Enduro: https://www.retrogames.cz/play_028-Atari2600.php?language=EN - used a method of driving that is quite comfortable for single stick and a button play:

LEFT-RIGHT = STEER
FIRE BUTTON HELD = ACCELERATE PROGRESSIVELY (release to set your car to that speed).
DOWN = DECELERATE PROGRESSIVELY

It would be really useful for some people perhaps using a single stick on modern driving games to replicate this. Ideally with variables to adjust:

RATE OF ACCELERATION
RATE OF DECCELERATION
TOP-SPEED LIMIT (for players unable to cope with too much speed)
ACCELERATION CONTROL (e.g. left-stick up / R2 past a threshold OR a push-button).
DECCELERATION CONTROL (e.g. left-stick down / L2 past a threshold OR a push button).

And beyond this, ideally a way to toggle this driving mode ON/OFF, e.g. TAP VIEW to enable/disable this driving mode. I'll chip away in the back-ground, but any help appreciated whilst I scratch my not-very-good-at-coding head.
User avatar
SpecialEffect
Sergeant Major of the Army
Sergeant Major of the Army
 
Posts: 203
Joined: Mon Apr 07, 2014 3:26 pm

Re: Accessibility: Driving Cruise Control

Postby SpecialEffect » Thu Oct 14, 2021 3:08 pm

Meanwhile, I've knocked up some code for accessible driving on the left-stick alone:

R3/RSB toggles between normal left-stick control and DRIVING MODE (indicated by a Green LED and rumble)

UP = accelerate with it's own deadzone and speed limiter.
DOWN = decellerate with it's own deadzone and speed limiter.
LEFT/RIGHT = steer as normal

If you use the actual L2/LT or R2/RT controls this will over-ride the speed, allowing for a team-member to dictate the speed, or for the user (perhaps via an accessibility switch) to give themself a turbo boost (e.g. to get up a hill).



Code: Select all
// ONE-STICK DRIVING with SPEED LIMITER
 
// Written by Barrie Ellis (www.specialeffect.org.uk) - 20/10/2021
// viewtopic.php?f=26&t=18892&wpureload=1#p114935
// Use with driving games where left-stick = steer, L2/LT = brake, R2/RT = accelerate.
 
// TOUCH/VIEW/BACK/SELECT = DRIVE MODE ON/OFF
 
// DRIVE MODE ON (GREEN LED) = Left-stick accelerate (UP), brake (DOWN) and steer (LEFT/RIGHT).
// Use actual L2/LT and R2/RT controls for boost/helper override.
 
#pragma  METAINFO("R3 = 1 STICK DRIVE (35%)", 1, 00, "Barrie Ellis - SpecialEffect")
#include <ps4.gph>                  // enable the use of PS4 terms
 
#define MODE_BUTTON PS4_R3          // MODE toggle button. Change to something else if needed, e.g. PS4_TOUCH
 
#define UP_DEADZONE 20.0            // CHANGE THESE FIGURES BETWEEN 0.0 and 100.0 TO ADJUST DRIVING PROPERTIES
#define UP_SPEED_LIMIT 35.0
#define DOWN_DEADZONE 40.0
#define DOWN_SPEED_LIMIT 60.0
 
 
bool toggle;
 
 
main {
    // XAC Titan Two bug fix (R2 through XAC into T2 causes SHARE/CAPTURE to activate)
     if (get_actual(PS4_R2) > 0.0) set_val(PS4_SHARE,0.0);
 
    // DRIVE MODE TOGGLE - VIA RIGHT-STICK BUTTON
    if(event_active(MODE_BUTTON)) toggle = !toggle;
        if(toggle) {led_set(LED_1, 0.0, 0);led_set(LED_2, 0.0, 0);led_set(LED_3, 100.0, 0);} else {led_reset();}     // SET LED COLOUR
 
 
    if(toggle) {
 
    if(event_active(MODE_BUTTON)) {ffb_set(FFB_1, 80.0, 200);ffb_set(FFB_2, 90.0, 200);}           // SHORT RUMBLE BURST
        else if(is_release(MODE_BUTTON)) {uint32 duration;ffb_get(FFB_1, &duration);ffb_get(FFB_2, &duration);if(duration == 0) {ffb_reset();}}
 
    // DRIVING MODE ACTIVE (GREEN LED)
    static fix32 LY = 0.0;
 
    LY = (get_actual(PS4_LY));           
    if (LY < -UP_SPEED_LIMIT) LY = -UP_SPEED_LIMIT;                                      // IMPOSE SPEED-LIMIT FOR UP
    if (LY > DOWN_SPEED_LIMIT) LY = DOWN_SPEED_LIMIT;                              // IMPOSE SPEED-LIMIT FOR DOWN
 
    if (LY > -UP_DEADZONE && LY < DOWN_DEADZONE) LY = 0.0;                     // IMPOSE DEADZONES
 
    if (LY > DOWN_DEADZONE) set_val(PS4_L2,LY);set_val(PS4_LY,0.0);           // SET L2 VALUE
    if (LY < -UP_DEADZONE) set_val(PS4_R2,-LY);set_val(PS4_LY,0.0);             // SET R2 VALUE
 
    if (get_actual(PS4_R2) > 0.0) set_val(PS4_R2,get_actual(PS4_R2));      // ACTUAL R2 OVER-RIDE
    if (get_actual(PS4_L2) > 0.0) set_val(PS4_L2,get_actual(PS4_L2));          // ACTUAL L2 OVER-RIDE
    }
 
}
 
 
// For more game accessibility scripts search on "accessibility" in the GTuner IV Online Resources.
Last edited by SpecialEffect on Wed Oct 20, 2021 12:43 pm, edited 3 times in total.
User avatar
SpecialEffect
Sergeant Major of the Army
Sergeant Major of the Army
 
Posts: 203
Joined: Mon Apr 07, 2014 3:26 pm

Re: Accessibility: Driving Cruise Control

Postby SpecialEffect » Wed Oct 20, 2021 9:44 am

With many thanks to Jefferson for the core code, this is the cruise control method I was hoping for (inspired by Activision's Enduro for the Atari VCS):

R3/RSB = toggle between LEFT-STICK mode and ACCESSIBLE "ENDURO" DRIVING mode.

DRIVING MODE active (LED goes out, short rumble):

LEFT-STICK = STEER
A/CROSS = PROGRESSIVE ACCELERATION (let go and the car stays at that speed - LED gets brighter the faster you go)
B/CIRCLE = PROGRESSIVE BRAKING (let go and the car stays at that speed - LED flashes RED if braking getting brighter the harder you brake)

Double-press R3/RSB to reset the driving mode (L2&R2 = 0%)

This code also includes a fix for the Xbox Adaptive Controller bug when RT/Right-Trigger is held into the XAC, Capture also activates. This is fixed below.




Code: Select all
 
 
// DRIVING - ACTIVISION ENDURO STYLE for accessibility
// Written by Jefferson Koppe and adapted by Barrie Ellis (http://www.specialeffect.org.uk) - 20-10-2021
// viewtopic.php?f=26&t=18892&wpureload=1#p114935
 
// USE MODE_BUTTON (e.g. PS4_R3) to toggle normal gamepad use / ENDURO DRIVING mode (black LED)
// USE CROSS/A button to accelerate progressively. Let go for cruise-control.
// USE CIRCLE/B button (or alternatively L-STICK down if enabled) to decelerate progressively. Let go for cruise-control.
// TAP MODE_BUTTON x2 to quickly reset
 
// ADJUST #define VALUES below to adjust the rate of acceleration/deceleration and speed limits for L2 and R2
 
#include <ps4.gph>      // PS4 terms - see bottom of script
 
#pragma METAINFO("ENDURO Driving - RSB-A-B", 1, 1, "J2Kbr/Barrie Ellis - SpecialEffect")
 
#define MODE_BUTTON PS4_R3          // MODE toggle button. Change to something else if needed, e.g. PS4_TOUCH
#define MODE_BUTTON_BLOCK_OFF         // MODE toggle button output block _ON or _OFF
 
#define ACCEL_BUTTON    PS4_CROSS   // ACCELERATOR   alternatives include  PS4_L3   PS4_R3
#define DECEL_BUTTON    PS4_CIRCLE  // BRAKE/REVERSE   
#define DOWN_DEADZONE   30.0        // JOYSTICK DOWN DEADZONE
 
#define ACCEL_MAX       100.0   // TOP-SPEED LIMITER (aka R2 limit)
#define ACCEL_RATE      0.08    // ACCELERATION SPEED (how fast the R3 button progressively accelerates)
#define BRAKE_MAX       100.0   // BRAKE-SPEED LIMITER (aka L2 limit)
#define BRAKE_RATE      0.08    // DECELERATION SPEED (how fast l-stick down progressively decelerates)
 
fix32 SPEED_val = 0.0;
fix32 BRAKE_val = 0.0;
bool toggle;
 
main {
    if (get_actual(PS4_R2) > 0.0) set_val(PS4_SHARE,0.0);                      // XAC Titan Two "R2 = R2+CAPTURE" bug fix - hopefully unnecessary soon.
 
 
    // PRESS MODE_BUTTON to toggle ENDURO DRIVING MODE ON/OFF - BLACK LED + RUMBLE = DRIVING MODE ON
    if(event_active(MODE_BUTTON)) toggle = !toggle;
 
    #ifdef MODE_BUTTON_BLOCK_ON
    if(event_active(MODE_BUTTON) set_val(MODE_BUTTON, 0.0);
    #endif
 
    if(toggle) {led_set(LED_1, 0.0, 0);led_set(LED_2, 0.0, 0);led_set(LED_3, 0.0, 0);} else {led_reset();SPEED_val = 0.0;BRAKE_val = 0.0;}
 
    // DRIVING MODE
    if(toggle) {
    if(event_active(MODE_BUTTON)) {ffb_set(FFB_1, 80.0, 200);ffb_set(FFB_2, 90.0, 200);}        // SHORT RUMBLE BURST
    else if(is_release(MODE_BUTTON)) {uint32 duration;ffb_get(FFB_1, &duration);ffb_get(FFB_2, &duration);if(duration == 0) {ffb_reset();}}
 
 
    if(get_actual(ACCEL_BUTTON)) {set_val(ACCEL_BUTTON, 0.0);         // IF ACCEL_BUTTON pressed block ACCEL_BUTTON output and....
 
    if(elapsed_time()) {                                            // ACCELERATE
        if(BRAKE_val) {BRAKE_val -= BRAKE_RATE;                        // if car was braking/reversing, slow BRAKE_val by BRAKE_RATE whilst ACCEL_BUTTON held
        if(BRAKE_val < 0.0) {BRAKE_val = 0.0;}} else {                // enforce braking limit bottom limit as 0.0...
        SPEED_val += ACCEL_RATE;                                    // if car is at rest or accelerating, increase SPEED by the ACCELERATION RATE.
        if(SPEED_val > ACCEL_MAX) {SPEED_val = ACCEL_MAX;}}}} else    // enforce ACCEL_MAX top-speed limit... else
 
 
    if(get_actual(DECEL_BUTTON)) {set_val(DECEL_BUTTON, 0.0);         // IF DECEL_BUTTON pressed block DECEL_BUTTON output and....
//    if(get_actual(STICK_2_Y) > DOWN_DEADZONE) {                     // ALTERNATIVE - if Left-stick DOWN is pushed beyond the DOWN_DEADZONE...
 
    if(elapsed_time()) {                                            // DECELERATE
        if(SPEED_val) {SPEED_val -= ACCEL_RATE;                        // if car is going forwards, reduce ACCEL_RATE by subtracting the BRAKE RATE.
        if(SPEED_val < 0.0) {SPEED_val = 0.0;}} else {                // enforce acceleration bottom limit as 0.0...
        BRAKE_val += BRAKE_RATE;                                    // if car is at rest or braking, increase BRAKING by the BRAKE_RATE
        if(BRAKE_val > BRAKE_MAX) {BRAKE_val = BRAKE_MAX;}}}}         // enforce BRAKE_MAX top-speed limit...
 
// IF accelerating above 0%  GREEN LED brightens and if decelerating below 0% RED FLASHING LED - BRIGHT GREEN ON PS4 DUAL-SHOCK = TOP-SPEED
    if(SPEED_val) {set_val(PS4_R2, SPEED_val);led_set(LED_2, 0.0, 0);led_set(LED_3, (SPEED_val*0.1), 0);led_set(LED_1, 0.0, 0);} else
    if(BRAKE_val) {set_val(PS4_L2, BRAKE_val);{combo_run(BRAKE_FLASH);}}
    if(SPEED_val == ACCEL_MAX) {led_set(LED_2, 0.0, 0);led_set(LED_3, 100.0, 0);led_set(LED_1, 0.0, 0);}
}
}
 
combo BRAKE_FLASH {
    led_set(LED_2, (BRAKE_val*0.2), 0);led_set(LED_3, 0.0, 0);led_set(LED_1, 0.0, 0);wait(600);
    led_set(LED_2, 0.0, 0);led_set(LED_3, 0.0, 0);led_set(LED_1, 0.0, 0);wait(150);
}
 
/*
PS4_PS          = BUTTON_1
PS4_TOUCH       = BUTTON_2     - TOUCH-CLICK
PS4_OPTIONS     = BUTTON_3
PS4_R1          = BUTTON_4
PS4_R2          = BUTTON_5
PS4_R3          = BUTTON_6
PS4_L1          = BUTTON_7
PS4_L2          = BUTTON_8
PS4_L3          = BUTTON_9
PS4_UP          = BUTTON_10
PS4_DOWN        = BUTTON_11
PS4_LEFT        = BUTTON_12
PS4_RIGHT       = BUTTON_13
PS4_TRIANGLE    = BUTTON_14
PS4_CIRCLE      = BUTTON_15
PS4_CROSS       = BUTTON_16
PS4_SQUARE      = BUTTON_17
PS4_SHARE       = BUTTON_18
 
PS4_RX          = STICK_1_X     - e.g. RIGHT-STICK X-AXIS LEFT = -1 to -100    RIGHT = +1 to +100
PS4_RY          = STICK_1_Y     - e.g. RIGHT-STICK Y-AXIS UP = -1 to -100      DOWN = +1 to +100
PS4_LX          = STICK_2_X
PS4_LY          = STICK_2_Y
 
PS4_TOUCH1      = BUTTON_19     - capacitive TOUCH 1 FINGER DETECTED - will return POINT1_X and POINT1_Y values
PS4_TOUCH2      = BUTTON_20     - capacitive TOUCH 2 FINGERS DETECTED - will return POINT2_X and POINT2_Y values
PS4_TOUCH1X     = POINT_1_X
PS4_TOUCH1Y     = POINT_1_Y
PS4_TOUCH2X     = POINT_2_X
PS4_TOUCH2Y     = POINT_2_Y
 
PS4_ACCX        = ACCEL_1_X
PS4_ACCY        = ACCEL_1_Y
PS4_ACCZ        = ACCEL_1_Z
PS4_GYROX       = GYRO_1_X
PS4_GYROY       = GYRO_1_Y
PS4_GYROZ       = GYRO_1_Z
*/
User avatar
SpecialEffect
Sergeant Major of the Army
Sergeant Major of the Army
 
Posts: 203
Joined: Mon Apr 07, 2014 3:26 pm

Re: Accessibility: Driving Cruise Control

Postby Mad » Wed Oct 20, 2021 8:45 pm

Thank you for sharing with us Barrie. :joia:
ConsoleTuner Support Team || ConsoleTuner Discord || InputSense Discord (2K / FPS)
Mad
Major General
Major General
 
Posts: 4532
Joined: Wed May 22, 2019 5:39 am

Re: Accessibility: Driving Cruise Control

Postby SpecialEffect » Fri Oct 22, 2021 10:16 am

Pleasure. :)
User avatar
SpecialEffect
Sergeant Major of the Army
Sergeant Major of the Army
 
Posts: 203
Joined: Mon Apr 07, 2014 3:26 pm


Return to GPC2 Script Programming

Who is online

Users browsing this forum: No registered users and 79 guests