Bump to latest simapi for unix timestamp ticks. Push unix timestamp ticks to lua variable. Update test logic to test on 8000 rpms. Update example lua scripts with examples of led rpm blink.
This commit is contained in:
@@ -10,8 +10,6 @@
|
||||
-- SIMAPI_FLAG_BLACK_ORANGE = 8,
|
||||
-- SIMAPI_FLAG_ORANGE = 9
|
||||
|
||||
led_clear_all()
|
||||
|
||||
if simdata.rpm > 0 and simdata.maxrpm > 0 then
|
||||
rpmmargin = .05*simdata.maxrpm;
|
||||
rpminterval = (simdata.maxrpm-rpmmargin) / 6;
|
||||
@@ -30,7 +28,16 @@ if simdata.rpm > 0 and simdata.maxrpm > 0 then
|
||||
if litleds >= 6 then
|
||||
color = RED
|
||||
end
|
||||
if litleds >= 6 then
|
||||
|
||||
if simdata.mtick % 2 == 0 then
|
||||
set_led_range_to_color(1, litleds, color)
|
||||
else
|
||||
led_clear_all()
|
||||
end
|
||||
else
|
||||
set_led_range_to_color(1, litleds, color)
|
||||
end
|
||||
end
|
||||
|
||||
if simdata.playerflag == 0 then
|
||||
|
||||
@@ -0,0 +1,91 @@
|
||||
-- configuration
|
||||
-- set these accordingly
|
||||
right_leds_start = 7
|
||||
right_num_leds = 42
|
||||
left_leds_start = 49
|
||||
left_num_leds = 42
|
||||
--
|
||||
|
||||
max_radius = 10 -- radius is hardcoded in simapi
|
||||
proxcars = simdata.proxcars -- also hard coded in simapi
|
||||
|
||||
rightsideset = false
|
||||
leftsideset = false
|
||||
|
||||
-- right side
|
||||
litleds = 0
|
||||
i = 1
|
||||
while(i <= proxcars and rightsideset == false) do
|
||||
if simdata.pd[i].theta > 40 and simdata.pd[i].theta < 130 then
|
||||
dist = math.abs(90 - simdata.pd[i].theta)
|
||||
perct = (90 - dist)/90
|
||||
litleds = math.ceil(perct * right_num_leds)
|
||||
|
||||
color_perct = simdata.pd[i].radius/10
|
||||
yellow = math.floor(color_perct * 255)
|
||||
local rgb = (255 << 16) | (yellow << 8) | (0 << 0)
|
||||
if simdata.pd[1].theta >= 90 then
|
||||
-- car is behind
|
||||
set_led_range_to_rgb_color(right_leds_start, right_leds_start + litleds, rgb)
|
||||
else
|
||||
set_led_range_to_rgb_color(right_leds_start + (right_num_leds - litleds), right_leds_start + right_num_leds, rgb)
|
||||
end
|
||||
rightsideset = true
|
||||
end
|
||||
i = i + 1
|
||||
end
|
||||
|
||||
-- left side
|
||||
litleds = 0
|
||||
i = 1
|
||||
while(i <= proxcars and leftsideset == false) do
|
||||
if simdata.pd[i].theta > 230 and simdata.pd[i].theta < 320 then
|
||||
dist = math.abs(270 - simdata.pd[1].theta)
|
||||
perct = (90 - dist)/90
|
||||
litleds = math.ceil(perct * left_num_leds)
|
||||
|
||||
color_perct = simdata.pd[i].radius/10
|
||||
yellow = math.floor(color_perct * 255)
|
||||
local rgb = (255 << 16) | (yellow << 8) | (0 << 0)
|
||||
if simdata.pd[1].theta <= 270 then
|
||||
-- car is behind
|
||||
set_led_range_to_rgb_color(left_leds_start, left_leds_start + litleds, rgb)
|
||||
else
|
||||
set_led_range_to_rgb_color(left_leds_start + (left_num_leds - litleds), left_leds_start + left_num_leds, rgb)
|
||||
end
|
||||
leftsideset = true
|
||||
end
|
||||
i = i + 1
|
||||
end
|
||||
|
||||
|
||||
-- rpm stuff
|
||||
if simdata.rpm > 0 and simdata.maxrpm > 0 then
|
||||
rpmmargin = .05*simdata.maxrpm;
|
||||
rpminterval = (simdata.maxrpm-rpmmargin) / 6;
|
||||
|
||||
litleds = 0
|
||||
for i = 1,6 do
|
||||
if simdata.rpm >= (rpminterval * i) then
|
||||
litleds = i;
|
||||
end
|
||||
end
|
||||
|
||||
color = GREEN
|
||||
if litleds > 3 and litleds < 6 then
|
||||
color = YELLOW
|
||||
end
|
||||
if litleds >= 6 then
|
||||
color = RED
|
||||
end
|
||||
if litleds >= 6 then
|
||||
|
||||
if simdata.mtick % 2 == 0 then
|
||||
set_led_range_to_color(1, litleds, color)
|
||||
else
|
||||
led_clear_all()
|
||||
end
|
||||
else
|
||||
set_led_range_to_color(1, litleds, color)
|
||||
end
|
||||
end
|
||||
@@ -3,14 +3,29 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <math.h>
|
||||
#include <sys/time.h>
|
||||
|
||||
#include "arduinoledlua.h"
|
||||
#include "arduino.h"
|
||||
|
||||
#include "../../slog/slog.h"
|
||||
|
||||
long long ledTimeInMilliseconds(void) {
|
||||
struct timeval tv;
|
||||
|
||||
gettimeofday(&tv,NULL);
|
||||
return (((long long)tv.tv_sec)*1000)+(tv.tv_usec/1000);
|
||||
}
|
||||
|
||||
|
||||
int simdata_to_lua(lua_State *L, SimData* simdata) {
|
||||
|
||||
// make the time up now if we are running in test mode
|
||||
if(simdata->mtick == 0)
|
||||
{
|
||||
simdata->mtick = ledTimeInMilliseconds();
|
||||
}
|
||||
|
||||
lua_newtable(L);
|
||||
|
||||
lua_pushinteger(L, simdata->playerflag);
|
||||
@@ -19,6 +34,9 @@ int simdata_to_lua(lua_State *L, SimData* simdata) {
|
||||
lua_pushinteger(L, simdata->rpms);
|
||||
lua_setfield(L, -2, "rpm");
|
||||
|
||||
lua_pushinteger(L, simdata->mtick);
|
||||
lua_setfield(L, -2, "mtick");
|
||||
|
||||
lua_pushinteger(L, simdata->maxrpm);
|
||||
lua_setfield(L, -2, "maxrpm");
|
||||
|
||||
|
||||
@@ -878,6 +878,16 @@ int tester(SimDevice* devices, int numdevices)
|
||||
devices[x].update(&devices[x], simdata);
|
||||
}
|
||||
}
|
||||
for(int x = 0; x < 100; x++)
|
||||
{
|
||||
for (int x = 0; x < numdevices; x++)
|
||||
{
|
||||
if (devices[x].initialized == true)
|
||||
{
|
||||
devices[x].update(&devices[x], simdata);
|
||||
}
|
||||
}
|
||||
}
|
||||
sleep(3);
|
||||
|
||||
simdata->velocity = 0;
|
||||
|
||||
Submodule src/monocoque/simulatorapi/simapi updated: 735c7d3b88...64f1ed8b26
Reference in New Issue
Block a user