Skip to content

Commit

Permalink
Merge pull request #41 from baylessj/wasm
Browse files Browse the repository at this point in the history
Check path validity in GUI
  • Loading branch information
baylessj committed Feb 1, 2021
2 parents 9c8dc71 + 3b12262 commit 9c69dd9
Show file tree
Hide file tree
Showing 18 changed files with 3,342 additions and 52 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/memcheck.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ on: push
jobs:
memcheck:
name: memcheck
runs-on: ubuntu-20.04
runs-on: ubuntu-18.04
steps:
- uses: actions/checkout@v2
with:
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,5 @@ plz-out

**.eslintcache
coverage.info
.next
node_modules
10 changes: 5 additions & 5 deletions main/viscompat/compat.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include "squiggles.hpp"
#include "compat.hpp"
#include "squiggles.hpp"

#define K_EPSILON (1e-5)

Expand Down Expand Up @@ -27,10 +27,10 @@ VisData compute_path(double sx,
} else {
model = std::make_shared<PassthroughModel>();
}
auto spline = SplineGenerator(constraints,
model,
dt);
std::vector<ProfilePoint> path = spline.generate({ControlVector(Pose(sx, sy, syaw), sv, sa), ControlVector(Pose(gx, gy, gyaw), gv, ga)});
auto spline = SplineGenerator(constraints, model, dt);
std::vector<ProfilePoint> path =
spline.generate({ControlVector(Pose(sx, sy, syaw), sv, sa),
ControlVector(Pose(gx, gy, gyaw), gv, ga)});
VisData out;
out.size = path.size();
out.points = new VisDataPoint[path.size()];
Expand Down
8 changes: 5 additions & 3 deletions run_clang_format.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#!/bin/bash
find include/ -iname *.hpp | xargs clang-format -i -style=file
find src/ -iname *.cpp | xargs clang-format -i -style=file
find tst/ -iname *.cpp | xargs clang-format -i -style=file
find main/include/ -iname *.hpp | xargs clang-format -i -style=file
find main/src/ -iname *.cpp | xargs clang-format -i -style=file
find main/test/ -iname *.cpp | xargs clang-format -i -style=file
find main/viscompat/ -iname *.cpp | xargs clang-format -i -style=file
find wasm/ -iname *.cpp | xargs clang-format -i -style=file
18 changes: 18 additions & 0 deletions wasm/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
genrule(
name = "gen_test",
srcs = ["web_shim.cpp", "//main:squiggles_srcs"],
outs = [
"squiggles.js",
],
cmd = [
"./tools/emsdk/upstream/emscripten/emcc $SRCS -s DISABLE_EXCEPTION_CATCHING=2 -s WASM=1 -s MODULARIZE=1 -s EXTRA_EXPORTED_RUNTIME_METHODS='[\"ccall\", \"cwrap\"]' -s EXPORT_NAME=\"'squiggles'\" -s SINGLE_FILE=1 -I main/include --std=gnu++17 -o squiggles.js",
"cp squiggles.js ../../../../web/public/js/squiggles.js",
],
deps = [
# pulling in the squiggles source directly since we need to rebuild the
# library with emcc rather than gcc to link properly
"//main:squiggles_srcs",
"//main:squiggles_hdrs",
"//tools:emcc_lib",
],
)
84 changes: 84 additions & 0 deletions wasm/web_shim.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
#include "emscripten.h"
#include "squiggles.hpp"
#include <exception>

using namespace squiggles;

extern "C" {

EMSCRIPTEN_KEEPALIVE
double linvels() {
auto model = std::make_shared<TankModel>(0.4, Constraints(1.0));
return model->linear_to_wheel_vels(1.0, 1.0)[0];
}

// struct GenerateOutput {
// double x;
// double y;
// double yaw;
// double vel;
// double wheel_0;
// double wheel_1;
// double curvature;
// };

// EMSCRIPTEN_KEEPALIVE
// std::vector<GenerateOutput> generate(double sx,
// double sy,
// double syaw,
// double sv,
// double gx,
// double gy,
// double gyaw,
// double gv,
// double max_vel,
// double max_accel,
// double max_jerk,
// double track_width) {
// if (!sx) return std::vector<GenerateOutput>();
// auto constraints = Constraints(max_vel, max_accel, max_jerk);
// auto model = std::make_shared<TankModel>(track_width, constraints);
// auto spline = SplineGenerator(constraints, model, 0.1);
// auto path = spline.generate({ControlVector(Pose(sx, sy, syaw), sv, 0),
// ControlVector(Pose(gx, gy, gyaw), gv, 0)});
// std::vector<GenerateOutput> out;
// for (auto p : path) {
// out.push_back(GenerateOutput({p.vector.pose.x,
// p.vector.pose.y,
// p.vector.pose.yaw,
// p.vector.vel,
// p.wheel_velocities[0],
// p.wheel_velocities[1],
// p.curvature}));
// }
// return out;
// }

EMSCRIPTEN_KEEPALIVE
int generate(double sx,
double sy,
double syaw,
double sv,
double gx,
double gy,
double gyaw,
double gv,
double max_vel,
double max_accel,
double max_jerk,
double track_width) {
if (!sx)
return 1;
auto constraints = Constraints(max_vel, max_accel, max_jerk);
auto model = std::make_shared<TankModel>(track_width, constraints);
auto spline = SplineGenerator(constraints, model, 0.1);
// we can't catch exceptions here for some reason, relying on the web client
// to do that for us
auto path = spline.generate({ControlVector(Pose(sx, sy, syaw), sv, 0),
ControlVector(Pose(gx, gy, gyaw), gv, 0)});
// for (auto p: path) {
// printf("%s\n", p.to_string().c_str());
// }
return 0;
}
}
2 changes: 1 addition & 1 deletion web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"scripts": {
"predeploy": "npm run build",
"deploy": "gh-pages -d build",
"start": "react-scripts start",
"start": "BROWSER=none react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
Expand Down

0 comments on commit 9c69dd9

Please sign in to comment.