This repository has been archived by the owner on Jan 16, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor code formatting and optimize robot movement
- Loading branch information
Showing
10 changed files
with
144 additions
and
79 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 |
---|---|---|
@@ -1,19 +1,19 @@ | ||
let void entry () { | ||
var number count = 0 | ||
loop count < 5 | ||
{ | ||
count = count + 1 | ||
square() | ||
} | ||
var number count = 0 | ||
loop count < 5 | ||
{ | ||
count = count + 1 | ||
square() | ||
} | ||
} | ||
|
||
let void square(){ | ||
Forward 30 cm | ||
Clock 90 | ||
Forward 300 mm | ||
Clock 90 | ||
Forward 30 cm | ||
Clock 90 | ||
Forward 300 mm | ||
Clock 90 | ||
Forward 30 cm | ||
Clock 90 | ||
Forward 300 mm | ||
Clock 90 | ||
Forward 30 cm | ||
Clock 90 | ||
Forward 300 mm | ||
Clock 90 | ||
} |
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 |
---|---|---|
@@ -1,11 +1,11 @@ | ||
let void entry () { | ||
setSpeed(200 mm) // distance per second (here 200mm/s) | ||
var number time = getTimestamp() | ||
loop time < 60000 | ||
{ | ||
var number dist = getDistance() in cm | ||
Forward dist - 25 in cm | ||
Clock 90 | ||
time = getTimestamp() | ||
} | ||
setSpeed(200 mm) // distance per second (here 200mm/s) | ||
var number time = getTimestamp() | ||
loop time < 60000 | ||
{ | ||
var number dist = getDistance() in cm | ||
Forward dist - 25 in cm | ||
Clock 90 | ||
time = getTimestamp() | ||
} | ||
} |
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
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,8 @@ | ||
let void entry () { | ||
setSpeed(10) | ||
loop getDistance() > 100 | ||
{ | ||
Forward 100 | ||
} | ||
return | ||
} |
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,16 @@ | ||
let void entry () { | ||
var number count = 0 | ||
setSpeed(10) | ||
Clock 30 | ||
loop count < 500 | ||
{ | ||
loop getDistance() < 500 | ||
{ | ||
Clock 5 | ||
} | ||
Forward 500 | ||
|
||
count = count + 1 | ||
} | ||
return | ||
} |
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
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
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 |
---|---|---|
@@ -1,44 +1,65 @@ | ||
import * as Entities from "./entities.js" | ||
import { Vector } from "./utils.js" | ||
import * as Entities from "./entities.js"; | ||
import { Vector } from "./utils.js"; | ||
|
||
export interface Scene{ | ||
size:Vector; | ||
entities:Entities.Entities[]; | ||
robot: Entities.Robot; | ||
time:number; | ||
timestamps:Array<Entities.Timestamp>; | ||
export interface Scene { | ||
size: Vector; | ||
entities: Entities.Entities[]; | ||
robot: Entities.Robot; | ||
time: number; | ||
timestamps: Array<Entities.Timestamp>; | ||
|
||
reset():void; | ||
reset(): void; | ||
} | ||
|
||
export class BaseScene{ | ||
size:Vector; | ||
entities:Entities.Entities[] = []; | ||
robot: Entities.Robot; | ||
time:number = 0; | ||
timestamps:Array<Entities.Timestamp> = []; | ||
export class BaseScene { | ||
size: Vector; | ||
entities: Entities.Entities[] = []; | ||
robot: Entities.Robot; | ||
time: number = 0; | ||
timestamps: Array<Entities.Timestamp> = []; | ||
|
||
constructor(size:Vector = new Vector(10000,10000)){ | ||
this.size = size; | ||
this.robot = new Entities.Robot(this.size.scale(0.5), new Vector(250,250), 0, 30, this) | ||
this.entities.push(new Entities.Wall(Vector.null(), this.size.projX())); | ||
this.entities.push(new Entities.Wall(Vector.null(), this.size.projY())); | ||
this.entities.push(new Entities.Wall(this.size, this.size.projY())); | ||
this.entities.push(new Entities.Wall(this.size, this.size.projX())); | ||
this.timestamps.push(new Entities.Timestamp(0, this.robot)); | ||
} | ||
constructor(size: Vector = new Vector(10000, 10000)) { | ||
this.size = size; | ||
this.robot = new Entities.Robot( | ||
this.size.scale(0.5), | ||
new Vector(250, 250), | ||
0, | ||
30, | ||
this | ||
); | ||
this.entities.push(new Entities.Wall(Vector.null(), this.size.projX())); | ||
this.entities.push(new Entities.Wall(Vector.null(), this.size.projY())); | ||
this.entities.push(new Entities.Wall(this.size, this.size.projY())); | ||
this.entities.push(new Entities.Wall(this.size, this.size.projX())); | ||
this.timestamps.push(new Entities.Timestamp(0, this.robot)); | ||
} | ||
|
||
reset(){ | ||
this.robot = new Entities.Robot(this.size.scale(0.5), new Vector(250,250), 0, 30, this) | ||
this.entities = []; | ||
this.entities.push(new Entities.Wall(Vector.null(), this.size.projX())); | ||
this.entities.push(new Entities.Wall(Vector.null(), this.size.projY())); | ||
this.entities.push(new Entities.Wall(this.size, this.size.projY())); | ||
this.entities.push(new Entities.Wall(this.size, this.size.projX())); | ||
this.timestamps = []; | ||
this.timestamps.push(new Entities.Timestamp(0, this.robot)); | ||
this.time = 0; | ||
} | ||
reset() { | ||
this.robot = new Entities.Robot( | ||
this.size.scale(0.5), | ||
new Vector(250, 250), | ||
0, | ||
30, | ||
this | ||
); | ||
this.entities = []; | ||
const X = this.size.x; | ||
const Y = this.size.y; | ||
this.entities.push(new Entities.Wall(Vector.null(), this.size.projX())); | ||
this.entities.push(new Entities.Wall(Vector.null(), this.size.projY())); | ||
this.entities.push(new Entities.Wall(this.size, this.size.projY())); | ||
this.entities.push(new Entities.Wall(this.size, this.size.projX())); | ||
this.entities.push( | ||
new Entities.Wall(new Vector(0.4 * X, Y), new Vector(0.2 * X, 0.7 * Y)) | ||
); | ||
// opposite side : | ||
this.entities.push( | ||
new Entities.Wall(new Vector(0.6 * X, 0), new Vector(0.8 * X, 0.3 * Y)) | ||
); | ||
this.timestamps = []; | ||
this.timestamps.push(new Entities.Timestamp(0, this.robot)); | ||
this.time = 0; | ||
} | ||
} | ||
|
||
// You can add new Scenes here |
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
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