Skip to content

Commit

Permalink
Merge pull request #81 from lf-lang/pendulum-fix
Browse files Browse the repository at this point in the history
Preamble moved inside of reactor to avoid multiple definitions
  • Loading branch information
lhstrh authored Sep 12, 2023
2 parents ce353d2 + becabc0 commit 94a9e68
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 13 deletions.
24 changes: 12 additions & 12 deletions examples/C/src/modal_models/FurutaPendulum/PendulumController.lf
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,6 @@
*/
target C

preamble {=
#include <math.h>
#define PI 3.14159265
#define MIN(X, Y) (((X) < (Y)) ? (X) : (Y))
double sign(double x) {
return (x > 0.0) - (x < 0.0);
}
double restrictAngle(double theta) {
return((fmod(fabs(theta) + PI, 2 * PI) - PI) * sign(theta));
}
=}

reactor PendulumController(
h: double = 0.005, // Sample interval
w0: double = 6.3,
Expand All @@ -38,6 +26,18 @@ reactor PendulumController(
si3: double = -0.03254225945714,
si4: double = -0.05808270221773,
phi2: double = -7.0124562) {
preamble {=
#include <math.h>
#define PI 3.14159265
#define MIN(X, Y) (((X) < (Y)) ? (X) : (Y))
double sign(double x) {
return (x > 0.0) - (x < 0.0);
}
double restrictAngle(double theta) {
return((fmod(fabs(theta) + PI, 2 * PI) - PI) * sign(theta));
}
=}

input theta: double
input d_theta: double
input phi: double
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/bin/bash
set -euo pipefail
# This script compiles the generated code,
# executes it, and plots the results.
# The first argument is the name of the main reactor
Expand Down
3 changes: 2 additions & 1 deletion examples/C/src/rhythm/compile.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/bin/bash
#
set -euo pipefail

# Script to compile the code generated by lfc or by the Lingua Franca IDE
# for the programs in this directory using arguments that are suitable to the
# OS on which this is running. The OS is detected using the Posix command uname.
Expand Down
2 changes: 2 additions & 0 deletions examples/C/src/rosace/build_run_plot.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#!/bin/bash
set -euo pipefail

# This script compiles the generated code,
# executes it, and plots the results.
# The one argument is the name of the main reactor.
Expand Down

0 comments on commit 94a9e68

Please sign in to comment.