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 <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
@ -6,31 +5,16 @@
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <poll.h>
|
#include <poll.h>
|
||||||
#include <termios.h>
|
#include <termios.h>
|
||||||
#include <signal.h>
|
|
||||||
|
|
||||||
#include "gameloop.h"
|
#include "gameloop.h"
|
||||||
#include "../helper/parameters.h"
|
#include "../helper/parameters.h"
|
||||||
#include "../helper/confighelper.h"
|
#include "../helper/confighelper.h"
|
||||||
#include "../devices/simdevice.h"
|
#include "../devices/simdevice.h"
|
||||||
#include "../simulatorapi/simapi/simapi/simdata.h"
|
#include "../simulatorapi/simdata.h"
|
||||||
#include "../simulatorapi/simapi/simapi/simmapper.h"
|
#include "../simulatorapi/simmapper.h"
|
||||||
#include "../slog/slog.h"
|
#include "../slog/slog.h"
|
||||||
|
|
||||||
#define DEFAULT_UPDATE_RATE 240.0
|
#define DEFAULT_UPDATE_RATE 120.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();
|
|
||||||
}
|
|
||||||
|
|
||||||
int showstats(SimData* simdata)
|
int showstats(SimData* simdata)
|
||||||
{
|
{
|
||||||
|
|
@ -181,64 +165,20 @@ int showstats(SimData* simdata)
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int looper(SimDevice* devices[], int numdevices, Simulator simulator)
|
||||||
|
{
|
||||||
|
|
||||||
int clilooper(SimDevice* devices, int numdevices, Parameters* p, SimData* simdata, SimMap* simmap)
|
slogi("preparing game loop with %i devices...", numdevices);
|
||||||
{
|
|
||||||
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);
|
|
||||||
|
|
||||||
SimData* simdata = malloc(sizeof(SimData));
|
SimData* simdata = malloc(sizeof(SimData));
|
||||||
SimMap* simmap = malloc(sizeof(SimMap));
|
SimMap* simmap = malloc(sizeof(SimMap));
|
||||||
|
|
||||||
|
int error = siminit(simdata, simmap, simulator);
|
||||||
|
|
||||||
|
if (error != MONOCOQUE_ERROR_NONE)
|
||||||
|
{
|
||||||
|
return error;
|
||||||
|
}
|
||||||
|
|
||||||
struct termios newsettings, canonicalmode;
|
struct termios newsettings, canonicalmode;
|
||||||
tcgetattr(0, &canonicalmode);
|
tcgetattr(0, &canonicalmode);
|
||||||
newsettings = canonicalmode;
|
newsettings = canonicalmode;
|
||||||
|
|
@ -249,41 +189,38 @@ int looper(SimDevice* devices, int numdevices, Parameters* p)
|
||||||
char ch;
|
char ch;
|
||||||
struct pollfd mypoll = { STDIN_FILENO, POLLIN|POLLPRI };
|
struct pollfd mypoll = { STDIN_FILENO, POLLIN|POLLPRI };
|
||||||
|
|
||||||
fprintf(stdout, "Searching for sim data... Press q to quit...\n");
|
double update_rate = DEFAULT_UPDATE_RATE;
|
||||||
p->simon = false;
|
int t=0;
|
||||||
double update_rate = SIM_CHECK_RATE;
|
int go = true;
|
||||||
go = true;
|
|
||||||
while (go == true)
|
while (go == true)
|
||||||
{
|
{
|
||||||
p->simon = false;
|
simdatamap(simdata, simmap, simulator);
|
||||||
getSim(simdata, simmap, &p->simon, &p->sim);
|
showstats(simdata);
|
||||||
|
t++;
|
||||||
if (p->simon == true && simdata->simstatus > 1)
|
if(simdata->rpms<250)
|
||||||
{
|
{
|
||||||
slogi("preparing game loop with %i devices...", numdevices);
|
simdata->rpms=250;
|
||||||
|
}
|
||||||
|
|
||||||
slogi("sending initial data to devices");
|
|
||||||
simdata->velocity = 16;
|
|
||||||
simdata->rpms = 100;
|
|
||||||
for (int x = 0; x < numdevices; x++)
|
for (int x = 0; x < numdevices; x++)
|
||||||
{
|
{
|
||||||
devices[x].update(&devices[x], simdata);
|
if (devices[x]->type == SIMDEV_SERIAL)
|
||||||
}
|
|
||||||
sleep(3);
|
|
||||||
|
|
||||||
clilooper(devices, numdevices, p, simdata, simmap);
|
|
||||||
}
|
|
||||||
if (p->simon == true)
|
|
||||||
{
|
{
|
||||||
p->simon = false;
|
if(t>=update_rate)
|
||||||
fprintf(stdout, "Searching for sim data... Press q again to quit...\n");
|
{
|
||||||
sleep(2);
|
devupdate(devices[x], simdata);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
devupdate(devices[x], simdata);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
if(t>=update_rate)
|
||||||
|
{
|
||||||
|
t=0;
|
||||||
|
}
|
||||||
if( poll(&mypoll, 1, 1000.0/update_rate) )
|
if( poll(&mypoll, 1, 1000.0/update_rate) )
|
||||||
{
|
|
||||||
if (go != false )
|
|
||||||
{
|
{
|
||||||
scanf("%c", &ch);
|
scanf("%c", &ch);
|
||||||
if(ch == 'q')
|
if(ch == 'q')
|
||||||
|
|
@ -292,8 +229,6 @@ int looper(SimDevice* devices, int numdevices, Parameters* p)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
fprintf(stdout, "\n");
|
fprintf(stdout, "\n");
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
tcsetattr(0, TCSANOW, &canonicalmode);
|
tcsetattr(0, TCSANOW, &canonicalmode);
|
||||||
|
|
@ -303,144 +238,3 @@ int looper(SimDevice* devices, int numdevices, Parameters* p)
|
||||||
|
|
||||||
return 0;
|
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