Compare commits
7
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0e96eb27ae | ||
|
|
218baed2ed | ||
|
|
c44af52ad5 | ||
|
|
084babb919 | ||
|
|
b3067e520d | ||
|
|
b4f459a539 | ||
|
|
b4ca18c351 |
@@ -16,12 +16,14 @@ Cross Platform device manager for driving and flight simulators, for use with co
|
|||||||
- Includes utility to configure revburner tachometer
|
- Includes utility to configure revburner tachometer
|
||||||
- Can send data to any serial device. So far only tested with arduino. Includes sample arduino sketch for sim lights.
|
- Can send data to any serial device. So far only tested with arduino. Includes sample arduino sketch for sim lights.
|
||||||
- The support for haptic bass shakers is limited and needs the most work. So far the engine rev is a simple sine wave, which I find convincing. The gear shift event works but not convincing enough for me.
|
- The support for haptic bass shakers is limited and needs the most work. So far the engine rev is a simple sine wave, which I find convincing. The gear shift event works but not convincing enough for me.
|
||||||
|
- Choice of Portaudio or Pulseaudio backend.
|
||||||
|
|
||||||
## Dependencies
|
## Dependencies
|
||||||
- libserialport - arduino serial devices
|
- libserialport - arduino serial devices
|
||||||
- hidapi - usb hid devices
|
- hidapi - usb hid devices
|
||||||
- libusb - used by hidapi
|
- libusb - used by hidapi
|
||||||
- portaudio - sound devices (haptic bass shakers)
|
- portaudio - sound devices (haptic bass shakers)
|
||||||
|
- pulseaudio - sound devices (haptic bass shakers)
|
||||||
- libenet - UDP support (not yet implemented)
|
- libenet - UDP support (not yet implemented)
|
||||||
- libxml2
|
- libxml2
|
||||||
- argtable2
|
- argtable2
|
||||||
@@ -44,6 +46,11 @@ cmake ..
|
|||||||
make
|
make
|
||||||
```
|
```
|
||||||
|
|
||||||
|
to use the pulseaudio backend use this cmake command
|
||||||
|
```
|
||||||
|
cmake -DUSE_PULSEAUDIO=YES ..
|
||||||
|
```
|
||||||
|
|
||||||
## Testing
|
## Testing
|
||||||
|
|
||||||
### Setting up Your Arduino Device
|
### Setting up Your Arduino Device
|
||||||
|
|||||||
+10
-3
@@ -6,11 +6,18 @@ devices = ( { device = "USB";
|
|||||||
granularity = 4;
|
granularity = 4;
|
||||||
config = "/home/paul/.config/monocoque/revburner1.xml"; },
|
config = "/home/paul/.config/monocoque/revburner1.xml"; },
|
||||||
{ device = "Sound";
|
{ device = "Sound";
|
||||||
type = "Engine"
|
type = "Engine";
|
||||||
devid = "98FD:83AC"; },
|
devid = "alsa_output.usb-Generic_USB2.0_Device_20170726905959-00.analog-stereo";
|
||||||
|
pan = 1;
|
||||||
|
volume = 90;
|
||||||
|
frequency = 27; },
|
||||||
{ device = "Sound";
|
{ device = "Sound";
|
||||||
type = "Gear"
|
type = "Gear"
|
||||||
devid = "98FD:83AC"; },
|
devid = "alsa_output.usb-Generic_USB2.0_Device_20170726905959-00.analog-stereo";
|
||||||
|
pan = 1;
|
||||||
|
duration = .25;
|
||||||
|
volume = 100;
|
||||||
|
frequency = 27; },
|
||||||
{ device = "Serial";
|
{ device = "Serial";
|
||||||
type = "ShiftLights";
|
type = "ShiftLights";
|
||||||
config = "None";
|
config = "None";
|
||||||
|
|||||||
@@ -7,6 +7,16 @@
|
|||||||
#define NUM_LEDS 6
|
#define NUM_LEDS 6
|
||||||
#define BRIGHTNESS 40
|
#define BRIGHTNESS 40
|
||||||
|
|
||||||
|
#define COLOR1A 0
|
||||||
|
#define COLOR1B 0
|
||||||
|
#define COLOR1C 255
|
||||||
|
#define COLOR2A 0
|
||||||
|
#define COLOR2B 255
|
||||||
|
#define COLOR2C 0
|
||||||
|
#define COLOR3A 255
|
||||||
|
#define COLOR3B 0
|
||||||
|
#define COLOR3C 0
|
||||||
|
|
||||||
CRGB leds[NUM_LEDS];
|
CRGB leds[NUM_LEDS];
|
||||||
SimData sd;
|
SimData sd;
|
||||||
int maxrpm = 0;
|
int maxrpm = 0;
|
||||||
@@ -75,15 +85,15 @@ void loop()
|
|||||||
|
|
||||||
if (l >= numlights / 2)
|
if (l >= numlights / 2)
|
||||||
{
|
{
|
||||||
leds[l] = CRGB ( 0, 0, 255);
|
leds[l] = CRGB ( COLOR1A, COLOR1B, COLOR1C);
|
||||||
}
|
}
|
||||||
if (l < numlights / 2)
|
if (l < numlights / 2)
|
||||||
{
|
{
|
||||||
leds[l] = CRGB ( 0, 255, 0);
|
leds[l] = CRGB ( COLOR2A, COLOR2B, COLOR2C);
|
||||||
}
|
}
|
||||||
if (l == numlights - 1)
|
if (l == numlights - 1)
|
||||||
{
|
{
|
||||||
leds[l] = CRGB ( 255, 0, 0);
|
leds[l] = CRGB ( COLOR3A, COLOR3B, COLOR3C);
|
||||||
}
|
}
|
||||||
if (lights[l] <= 0)
|
if (lights[l] <= 0)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
#define BYTE_SIZE sizeof(SimData)
|
#define BYTE_SIZE sizeof(SimData)
|
||||||
#define KPHTOMPH .621317
|
#define KPHTOMPH .621317
|
||||||
|
#define FANPOWER .6
|
||||||
|
|
||||||
Adafruit_MotorShield AFMS = Adafruit_MotorShield();
|
Adafruit_MotorShield AFMS = Adafruit_MotorShield();
|
||||||
|
|
||||||
@@ -46,6 +46,6 @@ void loop() {
|
|||||||
{
|
{
|
||||||
v = 255;
|
v = 255;
|
||||||
}
|
}
|
||||||
myMotor1->setSpeed(v);
|
myMotor1->setSpeed(v*FANPOWER);
|
||||||
myMotor2->setSpeed(v);
|
myMotor2->setSpeed(v*FANPOWER);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -123,7 +123,7 @@ int usb_generic_shaker_init(SoundDevice* sounddevice, pa_threaded_mainloop* main
|
|||||||
|
|
||||||
// recommended settings, i.e. server uses sensible values
|
// recommended settings, i.e. server uses sensible values
|
||||||
pa_buffer_attr buffer_attr;
|
pa_buffer_attr buffer_attr;
|
||||||
buffer_attr.maxlength = (uint32_t) -1;
|
buffer_attr.maxlength = (uint32_t) 32767;
|
||||||
buffer_attr.tlength = (uint32_t) -1;
|
buffer_attr.tlength = (uint32_t) -1;
|
||||||
buffer_attr.prebuf = (uint32_t) -1;
|
buffer_attr.prebuf = (uint32_t) -1;
|
||||||
buffer_attr.minreq = (uint32_t) -1;
|
buffer_attr.minreq = (uint32_t) -1;
|
||||||
@@ -131,22 +131,17 @@ int usb_generic_shaker_init(SoundDevice* sounddevice, pa_threaded_mainloop* main
|
|||||||
pa_cvolume cv;
|
pa_cvolume cv;
|
||||||
uint16_t pvolume = ceil(((double) volume/100.0d)*65535);
|
uint16_t pvolume = ceil(((double) volume/100.0d)*65535);
|
||||||
// Settings copied as per the chromium browser source
|
// Settings copied as per the chromium browser source
|
||||||
pa_stream_flags_t stream_flags;
|
|
||||||
stream_flags = PA_STREAM_INTERPOLATE_TIMING |
|
|
||||||
PA_STREAM_NOT_MONOTONIC | PA_STREAM_AUTO_TIMING_UPDATE |
|
|
||||||
PA_STREAM_ADJUST_LATENCY;
|
|
||||||
|
|
||||||
//stream_flags = PA_STREAM_START_CORKED;
|
pa_stream_flags_t stream_flags;
|
||||||
|
stream_flags = PA_STREAM_INTERPOLATE_TIMING | PA_STREAM_NOT_MONOTONIC | PA_STREAM_AUTO_TIMING_UPDATE | PA_STREAM_ADJUST_LATENCY | PA_STREAM_START_CORKED;
|
||||||
|
|
||||||
// Connect stream to the default audio output sink
|
// Connect stream to the default audio output sink
|
||||||
pa_cvolume_set(&cv, sample_specifications.channels, pvolume);
|
pa_cvolume_set(&cv, sample_specifications.channels, pvolume);
|
||||||
//pa_cvolume_set(&cv, 1, 0);
|
|
||||||
|
|
||||||
pa_cvolume_set_balance(&cv, &channel_map, pan);
|
pa_cvolume_set_balance(&cv, &channel_map, pan);
|
||||||
|
|
||||||
assert(pa_stream_connect_playback(stream, devname, &buffer_attr, stream_flags, &cv, NULL) == 0);
|
assert(pa_stream_connect_playback(stream, devname, &buffer_attr, stream_flags, &cv, NULL) == 0);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Wait for the stream to be ready
|
// Wait for the stream to be ready
|
||||||
for(;;) {
|
for(;;) {
|
||||||
pa_stream_state_t stream_state = pa_stream_get_state(stream);
|
pa_stream_state_t stream_state = pa_stream_get_state(stream);
|
||||||
|
|||||||
@@ -6,6 +6,7 @@
|
|||||||
#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"
|
||||||
@@ -17,6 +18,19 @@
|
|||||||
|
|
||||||
#define DEFAULT_UPDATE_RATE 240.0
|
#define DEFAULT_UPDATE_RATE 240.0
|
||||||
#define SIM_CHECK_RATE 1.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)
|
||||||
{
|
{
|
||||||
@@ -170,27 +184,13 @@ int showstats(SimData* simdata)
|
|||||||
|
|
||||||
int clilooper(SimDevice* devices, int numdevices, Parameters* p, SimData* simdata, SimMap* simmap)
|
int clilooper(SimDevice* devices, int numdevices, Parameters* p, SimData* simdata, SimMap* simmap)
|
||||||
{
|
{
|
||||||
|
|
||||||
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);
|
|
||||||
|
|
||||||
|
|
||||||
struct pollfd mypoll = { STDIN_FILENO, POLLIN|POLLPRI };
|
struct pollfd mypoll = { STDIN_FILENO, POLLIN|POLLPRI };
|
||||||
double update_rate = DEFAULT_UPDATE_RATE;
|
double update_rate = DEFAULT_UPDATE_RATE;
|
||||||
char ch;
|
char ch;
|
||||||
int t=0;
|
int t=0;
|
||||||
int s=0;
|
int s=0;
|
||||||
bool go = true;
|
go2 = true;
|
||||||
while (go == true && simdata->simstatus > 1)
|
while (go2 == true && simdata->simstatus > 1)
|
||||||
{
|
{
|
||||||
simdatamap(simdata, simmap, p->sim);
|
simdatamap(simdata, simmap, p->sim);
|
||||||
showstats(simdata);
|
showstats(simdata);
|
||||||
@@ -203,15 +203,14 @@ int clilooper(SimDevice* devices, int numdevices, Parameters* p, SimData* simdat
|
|||||||
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);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if( poll(&mypoll, 1, 1000.0/DEFAULT_UPDATE_RATE) )
|
if( poll(&mypoll, 1, 1000.0/update_rate) )
|
||||||
{
|
{
|
||||||
scanf("%c", &ch);
|
scanf("%c", &ch);
|
||||||
if(ch == 'q')
|
if(ch == 'q')
|
||||||
{
|
{
|
||||||
go = false;
|
go2 = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -230,6 +229,12 @@ int clilooper(SimDevice* devices, int numdevices, Parameters* p, SimData* simdat
|
|||||||
|
|
||||||
int looper(SimDevice* devices, int numdevices, Parameters* p)
|
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));
|
||||||
@@ -245,23 +250,28 @@ int looper(SimDevice* devices, int numdevices, Parameters* p)
|
|||||||
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");
|
fprintf(stdout, "Searching for sim data... Press q to quit...\n");
|
||||||
|
|
||||||
p->simon = false;
|
p->simon = false;
|
||||||
double update_rate = SIM_CHECK_RATE;
|
double update_rate = SIM_CHECK_RATE;
|
||||||
int go = true;
|
go = true;
|
||||||
while (go == true)
|
while (go == true)
|
||||||
{
|
{
|
||||||
|
p->simon = false;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if (p->simon == false)
|
|
||||||
{
|
|
||||||
getSim(simdata, simmap, &p->simon, &p->sim);
|
getSim(simdata, simmap, &p->simon, &p->sim);
|
||||||
}
|
|
||||||
|
|
||||||
if (p->simon == true)
|
if (p->simon == true && simdata->simstatus > 1)
|
||||||
{
|
{
|
||||||
|
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);
|
clilooper(devices, numdevices, p, simdata, simmap);
|
||||||
}
|
}
|
||||||
if (p->simon == true)
|
if (p->simon == true)
|
||||||
@@ -271,7 +281,9 @@ int looper(SimDevice* devices, int numdevices, Parameters* p)
|
|||||||
sleep(2);
|
sleep(2);
|
||||||
}
|
}
|
||||||
|
|
||||||
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')
|
||||||
@@ -280,6 +292,7 @@ int looper(SimDevice* devices, int numdevices, Parameters* p)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fprintf(stdout, "\n");
|
fprintf(stdout, "\n");
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
|
|||||||
Submodule src/monocoque/simulatorapi/simapi updated: c77e96339c...f8c4a167dd
Reference in New Issue
Block a user