Add wheelslip and abs to test loop
This commit is contained in:
parent
aac41aa882
commit
e1ddd73352
|
|
@ -1,4 +1,3 @@
|
|||
#include <stdbool.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
|
@ -6,31 +5,16 @@
|
|||
#include <sys/stat.h>
|
||||
#include <poll.h>
|
||||
#include <termios.h>
|
||||
#include <signal.h>
|
||||
|
||||
#include "gameloop.h"
|
||||
#include "../helper/parameters.h"
|
||||
#include "../helper/confighelper.h"
|
||||
#include "../devices/simdevice.h"
|
||||
#include "../simulatorapi/simapi/simapi/simdata.h"
|
||||
#include "../simulatorapi/simapi/simapi/simmapper.h"
|
||||
#include "../simulatorapi/simdata.h"
|
||||
#include "../simulatorapi/simmapper.h"
|
||||
#include "../slog/slog.h"
|
||||
|
||||
#define DEFAULT_UPDATE_RATE 240.0
|
||||
#define SIM_CHECK_RATE 1.0
|
||||
bool go = false;
|
||||
bool go2 = false;
|
||||
struct sigaction act;
|
||||
|
||||
void sighandler(int signum, siginfo_t* info, void* ptr)
|
||||
{
|
||||
sloge("caught signal");
|
||||
go = false;
|
||||
go2 = false;
|
||||
//gfx_clear(pixels, pixels_len);
|
||||
//gfx_swapbuffers();
|
||||
//gfx_close();
|
||||
}
|
||||
#define DEFAULT_UPDATE_RATE 120.0
|
||||
|
||||
int showstats(SimData* simdata)
|
||||
{
|
||||
|
|
@ -181,64 +165,20 @@ int showstats(SimData* simdata)
|
|||
fflush(stdout);
|
||||
}
|
||||
|
||||
|
||||
int clilooper(SimDevice* devices, int numdevices, Parameters* p, SimData* simdata, SimMap* simmap)
|
||||
int looper(SimDevice* devices[], int numdevices, Simulator simulator)
|
||||
{
|
||||
struct pollfd mypoll = { STDIN_FILENO, POLLIN|POLLPRI };
|
||||
double update_rate = DEFAULT_UPDATE_RATE;
|
||||
char ch;
|
||||
int t=0;
|
||||
int s=0;
|
||||
go2 = true;
|
||||
while (go2 == true && simdata->simstatus > 1)
|
||||
{
|
||||
simdatamap(simdata, simmap, p->sim);
|
||||
showstats(simdata);
|
||||
t++;
|
||||
s++;
|
||||
if(simdata->rpms<100)
|
||||
{
|
||||
simdata->rpms=100;
|
||||
}
|
||||
for (int x = 0; x < numdevices; x++)
|
||||
{
|
||||
devices[x].update(&devices[x], simdata);
|
||||
}
|
||||
|
||||
if( poll(&mypoll, 1, 1000.0/update_rate) )
|
||||
{
|
||||
scanf("%c", &ch);
|
||||
if(ch == 'q')
|
||||
{
|
||||
go2 = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
simdata->velocity = 0;
|
||||
simdata->rpms = 100;
|
||||
for (int x = 0; x < numdevices; x++)
|
||||
{
|
||||
devices[x].update(&devices[x], simdata);
|
||||
}
|
||||
|
||||
fprintf(stdout, "\n");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int looper(SimDevice* devices, int numdevices, Parameters* p)
|
||||
{
|
||||
memset(&act, 0, sizeof(act));
|
||||
act.sa_sigaction = sighandler;
|
||||
act.sa_flags = SA_SIGINFO;
|
||||
sigaction(SIGTERM, &act, NULL);
|
||||
sigaction(SIGINT, &act, NULL);
|
||||
sigaction(SIGTSTP, &act, NULL);
|
||||
|
||||
slogi("preparing game loop with %i devices...", numdevices);
|
||||
SimData* simdata = malloc(sizeof(SimData));
|
||||
SimMap* simmap = malloc(sizeof(SimMap));
|
||||
|
||||
int error = siminit(simdata, simmap, simulator);
|
||||
|
||||
if (error != MONOCOQUE_ERROR_NONE)
|
||||
{
|
||||
return error;
|
||||
}
|
||||
|
||||
struct termios newsettings, canonicalmode;
|
||||
tcgetattr(0, &canonicalmode);
|
||||
newsettings = canonicalmode;
|
||||
|
|
@ -249,51 +189,46 @@ int looper(SimDevice* devices, int numdevices, Parameters* p)
|
|||
char ch;
|
||||
struct pollfd mypoll = { STDIN_FILENO, POLLIN|POLLPRI };
|
||||
|
||||
fprintf(stdout, "Searching for sim data... Press q to quit...\n");
|
||||
p->simon = false;
|
||||
double update_rate = SIM_CHECK_RATE;
|
||||
go = true;
|
||||
double update_rate = DEFAULT_UPDATE_RATE;
|
||||
int t=0;
|
||||
int go = true;
|
||||
while (go == true)
|
||||
{
|
||||
p->simon = false;
|
||||
getSim(simdata, simmap, &p->simon, &p->sim);
|
||||
|
||||
if (p->simon == true && simdata->simstatus > 1)
|
||||
simdatamap(simdata, simmap, simulator);
|
||||
showstats(simdata);
|
||||
t++;
|
||||
if(simdata->rpms<250)
|
||||
{
|
||||
slogi("preparing game loop with %i devices...", numdevices);
|
||||
|
||||
|
||||
slogi("sending initial data to devices");
|
||||
simdata->velocity = 16;
|
||||
simdata->rpms = 100;
|
||||
for (int x = 0; x < numdevices; x++)
|
||||
{
|
||||
devices[x].update(&devices[x], simdata);
|
||||
}
|
||||
sleep(3);
|
||||
|
||||
clilooper(devices, numdevices, p, simdata, simmap);
|
||||
simdata->rpms=250;
|
||||
}
|
||||
if (p->simon == true)
|
||||
for (int x = 0; x < numdevices; x++)
|
||||
{
|
||||
p->simon = false;
|
||||
fprintf(stdout, "Searching for sim data... Press q again to quit...\n");
|
||||
sleep(2);
|
||||
}
|
||||
|
||||
if (poll(&mypoll, 1, 1000.0/update_rate) )
|
||||
{
|
||||
if (go != false )
|
||||
if (devices[x]->type == SIMDEV_SERIAL)
|
||||
{
|
||||
scanf("%c", &ch);
|
||||
if(ch == 'q')
|
||||
if(t>=update_rate)
|
||||
{
|
||||
go = false;
|
||||
devupdate(devices[x], simdata);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
devupdate(devices[x], simdata);
|
||||
}
|
||||
|
||||
}
|
||||
if(t>=update_rate)
|
||||
{
|
||||
t=0;
|
||||
}
|
||||
if( poll(&mypoll, 1, 1000.0/update_rate) )
|
||||
{
|
||||
scanf("%c", &ch);
|
||||
if(ch == 'q')
|
||||
{
|
||||
go = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fprintf(stdout, "\n");
|
||||
fflush(stdout);
|
||||
tcsetattr(0, TCSANOW, &canonicalmode);
|
||||
|
|
@ -303,144 +238,3 @@ int looper(SimDevice* devices, int numdevices, Parameters* p)
|
|||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int tester(SimDevice* devices, int numdevices)
|
||||
{
|
||||
|
||||
slogi("preparing test with %i devices...", numdevices);
|
||||
SimData* simdata = malloc(sizeof(SimData));
|
||||
|
||||
struct termios newsettings, canonicalmode;
|
||||
tcgetattr(0, &canonicalmode);
|
||||
newsettings = canonicalmode;
|
||||
newsettings.c_lflag &= (~ICANON & ~ECHO);
|
||||
newsettings.c_cc[VMIN] = 1;
|
||||
newsettings.c_cc[VTIME] = 0;
|
||||
tcsetattr(0, TCSANOW, &newsettings);
|
||||
|
||||
fprintf(stdout, "\n");
|
||||
simdata->gear = 0;
|
||||
simdata->velocity = 16;
|
||||
simdata->rpms = 100;
|
||||
simdata->maxrpm = 8000;
|
||||
sleep(3);
|
||||
|
||||
fprintf(stdout, "Setting rpms to 1000\n");
|
||||
simdata->rpms = 1000;
|
||||
for (int x = 0; x < numdevices; x++)
|
||||
{
|
||||
devices[x].update(&devices[x], simdata);
|
||||
}
|
||||
sleep(3);
|
||||
|
||||
fprintf(stdout, "Shifting into first gear\n");
|
||||
simdata->gear = 2;
|
||||
for (int x = 0; x < numdevices; x++)
|
||||
{
|
||||
devices[x].update(&devices[x], simdata);
|
||||
}
|
||||
for (int x = 0; x < numdevices; x++)
|
||||
{
|
||||
devices[x].update(&devices[x], simdata);
|
||||
}
|
||||
sleep(3);
|
||||
|
||||
fprintf(stdout, "Setting speed to 100\n");
|
||||
simdata->velocity = 100;
|
||||
for (int x = 0; x < numdevices; x++)
|
||||
{
|
||||
devices[x].update(&devices[x], simdata);
|
||||
}
|
||||
sleep(3);
|
||||
|
||||
fprintf(stdout, "Shifting into second gear\n");
|
||||
simdata->gear = 3;
|
||||
for (int x = 0; x < numdevices; x++)
|
||||
{
|
||||
devices[x].update(&devices[x], simdata);
|
||||
}
|
||||
for (int x = 0; x < numdevices; x++)
|
||||
{
|
||||
devices[x].update(&devices[x], simdata);
|
||||
}
|
||||
sleep(3);
|
||||
|
||||
fprintf(stdout, "Setting speed to 200\n");
|
||||
simdata->velocity = 200;
|
||||
for (int x = 0; x < numdevices; x++)
|
||||
{
|
||||
devices[x].update(&devices[x], simdata);
|
||||
}
|
||||
sleep(3);
|
||||
|
||||
fprintf(stdout, "Shifting into third gear\n");
|
||||
simdata->gear = 4;
|
||||
for (int x = 0; x < numdevices; x++)
|
||||
{
|
||||
devices[x].update(&devices[x], simdata);
|
||||
}
|
||||
for (int x = 0; x < numdevices; x++)
|
||||
{
|
||||
devices[x].update(&devices[x], simdata);
|
||||
}
|
||||
sleep(3);
|
||||
|
||||
fprintf(stdout, "Setting rpms to 2000\n");
|
||||
simdata->rpms = 2000;
|
||||
for (int x = 0; x < numdevices; x++)
|
||||
{
|
||||
devices[x].update(&devices[x], simdata);
|
||||
}
|
||||
sleep(3);
|
||||
|
||||
fprintf(stdout, "Setting rpms to 4000\n");
|
||||
simdata->rpms = 4000;
|
||||
for (int x = 0; x < numdevices; x++)
|
||||
{
|
||||
devices[x].update(&devices[x], simdata);
|
||||
}
|
||||
sleep(3);
|
||||
|
||||
fprintf(stdout, "Shifting into fourth gear\n");
|
||||
simdata->gear = 5;
|
||||
for (int x = 0; x < numdevices; x++)
|
||||
{
|
||||
devices[x].update(&devices[x], simdata);
|
||||
}
|
||||
for (int x = 0; x < numdevices; x++)
|
||||
{
|
||||
devices[x].update(&devices[x], simdata);
|
||||
}
|
||||
sleep(3);
|
||||
|
||||
fprintf(stdout, "Setting speed to 300\n");
|
||||
simdata->velocity = 300;
|
||||
for (int x = 0; x < numdevices; x++)
|
||||
{
|
||||
devices[x].update(&devices[x], simdata);
|
||||
}
|
||||
sleep(3);
|
||||
|
||||
fprintf(stdout, "Setting rpms to 8000\n");
|
||||
simdata->rpms = 8000;
|
||||
for (int x = 0; x < numdevices; x++)
|
||||
{
|
||||
devices[x].update(&devices[x], simdata);
|
||||
}
|
||||
sleep(3);
|
||||
|
||||
simdata->velocity = 0;
|
||||
simdata->rpms = 100;
|
||||
for (int x = 0; x < numdevices; x++)
|
||||
{
|
||||
devices[x].update(&devices[x], simdata);
|
||||
}
|
||||
sleep(1);
|
||||
|
||||
fflush(stdout);
|
||||
tcsetattr(0, TCSANOW, &canonicalmode);
|
||||
|
||||
free(simdata);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue