Fix wheel slip calculations

This commit is contained in:
Paul Dino Jones 2024-05-30 18:03:26 +00:00
parent b01e0f461c
commit 54dde79ad8
3 changed files with 23 additions and 23 deletions

View File

@ -45,21 +45,21 @@ int sounddev_tyreslip_update(SimDevice* this, SimData* simdata)
double play = 0; double play = 0;
if (this->tyre == FRONTLEFT || this->tyre == FRONTS || this->tyre == ALLFOUR) if (this->tyre == FRONTLEFT || this->tyre == FRONTS || this->tyre == ALLFOUR)
{ {
play += simdata->wheelslip[0]; play += (1.0 - simdata->wheelslip[0]);
} }
if (this->tyre == FRONTRIGHT || this->tyre == FRONTS || this->tyre == ALLFOUR) if (this->tyre == FRONTRIGHT || this->tyre == FRONTS || this->tyre == ALLFOUR)
{ {
play += simdata->wheelslip[1]; play += (1.0 - simdata->wheelslip[1]);
} }
if (this->tyre == REARLEFT || this->tyre == REARS || this->tyre == ALLFOUR) if (this->tyre == REARLEFT || this->tyre == REARS || this->tyre == ALLFOUR)
{ {
play += simdata->wheelslip[2]; play += (1.0 - simdata->wheelslip[2]);
} }
if (this->tyre == REARRIGHT || this->tyre == REARS || this->tyre == ALLFOUR) if (this->tyre == REARRIGHT || this->tyre == REARS || this->tyre == ALLFOUR)
{ {
play += simdata->wheelslip[3]; play += (1.0 - simdata->wheelslip[3]);
} }
if (play > 0) if (play > .40)
{ {
sounddevice->sounddata.curr_frequency = sounddevice->sounddata.frequency * play; sounddevice->sounddata.curr_frequency = sounddevice->sounddata.frequency * play;
sounddevice->sounddata.curr_duration = sounddevice->sounddata.duration; sounddevice->sounddata.curr_duration = sounddevice->sounddata.duration;

View File

@ -19,19 +19,19 @@ int usbhapticdev_update(USBGenericHapticDevice* usbhapticdevice, SimData* simdat
{ {
if (usbhapticdevice->tyre == FRONTLEFT || usbhapticdevice->tyre == FRONTS || usbhapticdevice->tyre == ALLFOUR) if (usbhapticdevice->tyre == FRONTLEFT || usbhapticdevice->tyre == FRONTS || usbhapticdevice->tyre == ALLFOUR)
{ {
play += simdata->wheelslip[0]; play += (1.0 - simdata->wheelslip[0]);
} }
if (usbhapticdevice->tyre == FRONTRIGHT || usbhapticdevice->tyre == FRONTS || usbhapticdevice->tyre == ALLFOUR) if (usbhapticdevice->tyre == FRONTRIGHT || usbhapticdevice->tyre == FRONTS || usbhapticdevice->tyre == ALLFOUR)
{ {
play += simdata->wheelslip[1]; play += (1.0 - simdata->wheelslip[1]);
} }
if (usbhapticdevice->tyre == REARLEFT || usbhapticdevice->tyre == REARS || usbhapticdevice->tyre == ALLFOUR) if (usbhapticdevice->tyre == REARLEFT || usbhapticdevice->tyre == REARS || usbhapticdevice->tyre == ALLFOUR)
{ {
play += simdata->wheelslip[2]; play += (1.0 - simdata->wheelslip[2]);
} }
if (usbhapticdevice->tyre == REARRIGHT || usbhapticdevice->tyre == REARS || usbhapticdevice->tyre == ALLFOUR) if (usbhapticdevice->tyre == REARRIGHT || usbhapticdevice->tyre == REARS || usbhapticdevice->tyre == ALLFOUR)
{ {
play += simdata->wheelslip[3]; play += (1.0 - simdata->wheelslip[3]);
} }
} }
break; break;
@ -42,7 +42,7 @@ int usbhapticdev_update(USBGenericHapticDevice* usbhapticdevice, SimData* simdat
if (play != usbhapticdevice->state) if (play != usbhapticdevice->state)
{ {
if(play > 0) if(play > .40)
{ {
fprintf(usbhapticdevice->handle, "%i\n", usbhapticdevice->value1); fprintf(usbhapticdevice->handle, "%i\n", usbhapticdevice->value1);
fflush(usbhapticdevice->handle); fflush(usbhapticdevice->handle);

View File

@ -324,10 +324,10 @@ int tester(SimDevice* devices, int numdevices)
simdata->rpms = 100; simdata->rpms = 100;
simdata->maxrpm = 8000; simdata->maxrpm = 8000;
simdata->abs = 0; simdata->abs = 0;
simdata->wheelslip[0] = 0; simdata->wheelslip[0] = 1;
simdata->wheelslip[1] = 0; simdata->wheelslip[1] = 1;
simdata->wheelslip[2] = 0; simdata->wheelslip[2] = 1;
simdata->wheelslip[3] = 0; simdata->wheelslip[3] = 1;
sleep(3); sleep(3);
fprintf(stdout, "Setting rpms to 1000\n"); fprintf(stdout, "Setting rpms to 1000\n");
@ -347,20 +347,20 @@ int tester(SimDevice* devices, int numdevices)
sleep(3); sleep(3);
simdata->abs = 0; simdata->abs = 0;
fprintf(stdout, "Setting Wheelslip to 1\n"); fprintf(stdout, "Setting Wheelslip to 0, no traction\n");
simdata->wheelslip[0] = 1; simdata->wheelslip[0] = 0;
simdata->wheelslip[1] = 1; simdata->wheelslip[1] = 0;
simdata->wheelslip[2] = 1; simdata->wheelslip[2] = 0;
simdata->wheelslip[3] = 1; simdata->wheelslip[3] = 0;
for (int x = 0; x < numdevices; x++) for (int x = 0; x < numdevices; x++)
{ {
devices[x].update(&devices[x], simdata); devices[x].update(&devices[x], simdata);
} }
sleep(3); sleep(3);
simdata->wheelslip[0] = 0; simdata->wheelslip[0] = 1;
simdata->wheelslip[1] = 0; simdata->wheelslip[1] = 1;
simdata->wheelslip[2] = 0; simdata->wheelslip[2] = 1;
simdata->wheelslip[3] = 0; simdata->wheelslip[3] = 1;
fprintf(stdout, "Shifting into first gear\n"); fprintf(stdout, "Shifting into first gear\n");
simdata->gear = 2; simdata->gear = 2;