Throttle on a PS4 Button

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

Throttle on a PS4 Button

Postby thedude » Sun Aug 11, 2019 5:21 pm

Hi there.

Short version: does PS4 buttons hold negative analog values, in range -100 to 100?

Background:
Still improving my project, which I published here https://www.consoletuner.com/greslib/?0&F&0&0&&dmlycGls

I have mapped the Virpil throttle to PS4_R2 button.
In the ConsoleTunner, it shows the PS4_R2 button moving from -100 to 100 as I move the throttle, which is just as I expect.

I have mapped the throttle to ACCEL_2_X and then scripted this to get me values between -100 and 100:

Code: Select all
set_val(PS4_R2, (get_actual(ACCEL_2_X)*2.0)-100.0);


I also tried round numbers:
Code: Select all
set_val(PS4_R2, floor((get_actual(ACCEL_2_X)*2.0)-100.0));


The problem:
In game, once I move throttle from maximum speed, to zero, and keep reverting to negative values/speed, the throttle jumps to full again. One full throttle travel (from max ahead to full reverse) gives two throttle's travels in game. And never reversing - always in the positive range.

Seeing the behaviour, I am assuming that, as I move the throttle, PS4_R2 goes from 100 --> 0 --> 100 -> 0


Make sense?
If it went 100 --> 0 --> 100 I would say that PS4_R2 does not hold negative numbers - but this is not happening.

Could be a bug in my code? Or in the the GPC2 language?
User avatar
thedude
Staff Sergeant
Staff Sergeant
 
Posts: 12
Joined: Wed Apr 10, 2019 8:09 pm

Re: Throttle on a PS4 Button

Postby J2Kbr » Mon Aug 19, 2019 7:56 pm

It seems the resulting values are overflowing. You can prevent that with the GPC function "clamp", example:

Code: Select all
main {
    set_val(BUTTON_5, clamp(2.0 * get_actual(ACCEL_2_X) - 100.0, 0.0, 100.0));
}
 

This will restrict the values from 0 .. to 100, which is the valid range for the triggers.
ConsoleTuner Support Team
User avatar
J2Kbr
General of the Army
General of the Army
 
Posts: 20323
Joined: Tue Mar 18, 2014 1:39 pm


Return to GPC2 Script Programming

Who is online

Users browsing this forum: No registered users and 93 guests