-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c4793ae
commit 39acaa5
Showing
7 changed files
with
132 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,3 +3,4 @@ | |
/cmake-build-release | ||
/cmake-build-release-visual-studio | ||
/.idea | ||
/experiments |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Submodule rl_tools
updated
8 files
+1 −1 | .github/workflows/zoo.yml | |
+1 −1 | serve.sh | |
+4 −3 | static/extrack_ui/Explorer.js | |
+7 −2 | static/extrack_ui/ShowRun.js | |
+12 −1 | static/extrack_ui/TrajectoryPlayer.js | |
+5 −3 | static/extrack_ui/Zoo.js | |
+42 −9 | static/extrack_ui/index.html | |
+10 −2 | tools/index_experiments_static.sh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
namespace rl_tools{ | ||
template<typename DEVICE, typename SPEC> | ||
std::string json(DEVICE& device, const MyPendulum<SPEC>& env, const typename MyPendulum<SPEC>::Parameters& parameters){ | ||
return "{}"; | ||
} | ||
|
||
template<typename DEVICE, typename SPEC> | ||
std::string json(DEVICE& device, const MyPendulum<SPEC>& env, const typename MyPendulum<SPEC>::Parameters& parameters, const typename MyPendulum<SPEC>::State& state){ | ||
std::string json = "{"; | ||
json += "\"theta\":" + std::to_string(state.theta) + ","; | ||
json += "\"theta_dot\":" + std::to_string(state.theta_dot); | ||
json += "}"; | ||
return json; | ||
} | ||
template <typename DEVICE, typename SPEC> | ||
std::string get_ui(DEVICE& device, MyPendulum<SPEC>& env){ | ||
// just the body of `function render(ctx, state, action) {` (so that it can be easily processed by `new Function("ctx", "state", "action", body)` | ||
std::string ui = R"RL_TOOLS_LITERAL( | ||
ctx.clearRect(0, 0, ctx.canvas.width, ctx.canvas.height); | ||
const centerX = ctx.canvas.width / 2; | ||
const centerY = ctx.canvas.height / 2; | ||
const canvasWidth = ctx.canvas.width; | ||
const pendulumLength = canvasWidth * 0.2; | ||
const bobRadius = canvasWidth * 0.02; | ||
const pivotRadius = canvasWidth * 0.01; | ||
// Draw the Pendulum | ||
const adjustedTheta = state.theta - Math.PI; | ||
const pendulumX = centerX + pendulumLength * Math.sin(adjustedTheta); | ||
const pendulumY = centerY + pendulumLength * Math.cos(adjustedTheta); | ||
ctx.beginPath(); | ||
ctx.moveTo(centerX, centerY); | ||
ctx.lineTo(pendulumX, pendulumY); | ||
ctx.lineWidth = canvasWidth * 0.008; | ||
ctx.strokeStyle = 'black'; | ||
ctx.stroke(); | ||
ctx.beginPath(); | ||
ctx.arc(pendulumX, pendulumY, bobRadius, 0, 2 * Math.PI); | ||
ctx.fillStyle = '#7DB9B6'; | ||
ctx.fill(); | ||
ctx.stroke(); | ||
ctx.beginPath(); | ||
ctx.arc(centerX, centerY, pivotRadius, 0, 2 * Math.PI); | ||
ctx.fillStyle = 'black'; | ||
ctx.fill(); | ||
ctx.stroke(); | ||
// Draw torque arc | ||
const torqueMagnitude = -Math.max(-1, Math.min(action[0], 1)); | ||
const arrowRadius = canvasWidth * 0.08; | ||
const magnitudeRadians = (Math.PI * 2 / 3 * torqueMagnitude); | ||
const startAngle = Math.PI / 2 + (torqueMagnitude > 0 ? 0 : magnitudeRadians); | ||
const endAngle = Math.PI / 2 + (torqueMagnitude < 0 ? 0 : magnitudeRadians); | ||
ctx.beginPath(); | ||
ctx.arc(centerX, centerY, arrowRadius, startAngle, endAngle); | ||
ctx.strokeStyle = 'black'; | ||
ctx.lineWidth = canvasWidth * 0.008; | ||
ctx.stroke(); | ||
// Draw arrowhead | ||
const arrowAngle = torqueMagnitude > 0 ? endAngle : startAngle; | ||
const arrowHeadAngularOffset = torqueMagnitude * Math.PI/180*20 | ||
const arrowX = centerX + arrowRadius * Math.cos(arrowAngle + arrowHeadAngularOffset); | ||
const arrowY = centerY + arrowRadius * Math.sin(arrowAngle + arrowHeadAngularOffset); | ||
const headlen = canvasWidth * 0.04 * Math.min(Math.abs(torqueMagnitude)*2, 1); | ||
const angleOffset = Math.PI / 6; | ||
const rotationAngle = Math.PI / 2 + (torqueMagnitude > 0 ? 0 : Math.PI); | ||
ctx.beginPath(); | ||
ctx.moveTo(arrowX, arrowY); | ||
ctx.lineTo( | ||
arrowX - headlen * Math.cos(arrowAngle + arrowHeadAngularOffset/2 - angleOffset + rotationAngle), | ||
arrowY - headlen * Math.sin(arrowAngle + arrowHeadAngularOffset/2 - angleOffset + rotationAngle) | ||
); | ||
ctx.lineTo( | ||
arrowX - headlen * Math.cos(arrowAngle + arrowHeadAngularOffset/2 + angleOffset + rotationAngle), | ||
arrowY - headlen * Math.sin(arrowAngle + arrowHeadAngularOffset/2 + angleOffset + rotationAngle) | ||
); | ||
ctx.lineTo(arrowX, arrowY); | ||
ctx.fillStyle = 'black'; | ||
ctx.fill(); | ||
)RL_TOOLS_LITERAL"; | ||
return ui; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<h1>RLtools</h1> | ||
</head> | ||
<body> | ||
<a href="./external/rl_tools/static/extrack_ui?experiments=/experiments/"><b>EX</b>periement <b>TRACK</b>ing UI</a> | ||
</body> | ||
<script> | ||
window.addEventListener('load', () => { | ||
|
||
}) | ||
</script> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
set -e | ||
watch -n10 ./external/rl_tools/tools/index_experiments_static.sh experiments & | ||
python3 -m http.server $@ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters