Skip to content
This repository has been archived by the owner on Jan 16, 2024. It is now read-only.

Commit

Permalink
feat: implement STD
Browse files Browse the repository at this point in the history
  • Loading branch information
Pixselve committed Jan 3, 2024
1 parent d477b20 commit 0299c01
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 13 deletions.
8 changes: 6 additions & 2 deletions mini-mecha-code/src/compiler/arduino.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export default function compileToArduino(model: Model): string[] {
}
result.push("void loop() {");
// run main function
result.push(" main();");
result.push(" entry();");
result.push("}");
return result;
}
Expand All @@ -76,7 +76,11 @@ function evaluateFunctionDef(functionDef: DefFunction): string[] {
return [];

const params = functionDef.parameters.map((p) => `float ${p.name}`);
result.push(`float ${functionDef.name}(${params.join(", ")}) {`);
result.push(
`${functionDef.returnType === "void" ? "void" : "float"} ${
functionDef.name
}(${params.join(", ")}) {`,
);
for (const stmt of functionDef.statements) {
result.push(...evaluateStatement(stmt, 1));
}
Expand Down
53 changes: 42 additions & 11 deletions mini-mecha-code/src/compiler/std-arduino.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,46 @@
const stdArduino = `
void rotate(int angle) {
// TODO: Implement
#include <PinChangeInt.h>
#include <PinChangeIntConfig.h>
#include <EEPROM.h>
#define _NAMIKI_MOTOR\t //for Namiki 22CL-103501PG80:1
#include <fuzzy_table.h>
#include <PID_Beta6.h>
#include <MotorWheel.h>
#include <Omni4WD.h>
irqISR(irq1, isr1);
MotorWheel wheel1(3, 2, 4, 5, &irq1);
irqISR(irq2, isr2);
MotorWheel wheel2(11, 12, 14, 15, &irq2);
irqISR(irq3, isr3);
MotorWheel wheel3(9, 8, 16, 17, &irq3);
irqISR(irq4, isr4);
MotorWheel wheel4(10, 7, 18, 19, &irq4);
Omni4WD Omni(&wheel1, &wheel2, &wheel3, &wheel4);
void setup() {
TCCR1B = TCCR1B & 0xf8 | 0x01; // Pin9,Pin10 PWM 31250Hz
TCCR2B = TCCR2B & 0xf8 | 0x01; // Pin3,Pin11 PWM 31250Hz
Omni.PIDEnable(0.31, 0.01, 0, 10);
}
void rotate(float angle) {
Omni.setCarRotate(angle);
}
void forward(int distance) {
// TODO: Implement
float speed = Omni.getCarSpeedMMPS();
float timeToSleep = distance / speed;
Omni.setCarAdvance(speed);
Omni.delay(timeToSleep);
Omni.setCarStop();
}
int getDistance() {
Expand All @@ -13,16 +49,11 @@ int getDistance() {
}
int getTimestamp() {
// TODO: Implement
return 0;
return millis();
}
void setSpeed(int speed) {
// TODO: Implement
}
void setup() {
// TODO: Implement
void setSpeed(float speed) {
Omni.setCarSpeedMMPS(speed);
}
`;

Expand Down

0 comments on commit 0299c01

Please sign in to comment.