Skip to content

Commit

Permalink
rmoved one function
Browse files Browse the repository at this point in the history
  • Loading branch information
pelikhan committed Oct 17, 2023
1 parent ee8fcf1 commit 41ecd8b
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 24 deletions.
2 changes: 1 addition & 1 deletion robot/blocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ namespace microcode {
//% blockid="microcoderobotmotorstop"
export function motorStop() {
checkRobotDriver()
robot.motorStop()
robot.motorRun(0, 0)
}

/**
Expand Down
34 changes: 12 additions & 22 deletions robot/robotdriver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@ namespace microcode {
//% fixedInstances
export class RobotDriver {
readonly robot: robots.Robot
private running = false
/**
* Gets the latest distance returned by the se nsor
* Gets the latest distance returned by the sensor
*/
currentUltrasonicDistance: number = 100
private lastSonarValue = 0

private showConfiguration: boolean = false
private configDrift = false
private currentArmAperture = -1
Expand All @@ -25,6 +26,7 @@ namespace microcode {
private currentTurnRatio = 0
private targetTurnRatio: number = 0
private radioGroup: number
private inRadioMessageId: number = undefined

/**
* Gets the latest line sensor state
Expand All @@ -45,7 +47,6 @@ namespace microcode {

constructor(robot: robots.Robot) {
this.robot = robot
microcode.robot = this
}

private configureButtons() {
Expand Down Expand Up @@ -86,14 +87,15 @@ namespace microcode {
/**
* Starts the motor driver
*/
//% block="robot start %this"
//% block="robot %this start"
//% blockId=microcoderobotstart
//% weight=100
//% group="Configuration"
start() {
if (this.running) return

this.running = true
if (microcode.robot === this) return // already started
if (microcode.robot)
throw "Another robot has already been started."
microcode.robot = this

// configuration of common hardware
this.radioGroup = radioGroupFromDeviceSerialNumber()
Expand All @@ -109,7 +111,7 @@ namespace microcode {

// stop motors
this.setColor(0x0000ff)
this.motorStop()
this.motorRun(0, 0)
// wake up sensors
this.ultrasonicDistance()
this.lineState()
Expand All @@ -119,13 +121,11 @@ namespace microcode {
control.inBackground(() => this.backgroundWork())

// schedule after main
control.inBackground(() => {
this.showConfigurationState(true)
})
control.inBackground(() => this.showConfigurationState(true))
}

private backgroundWork() {
while (this.running) {
while (true) {
this.updateTone()
this.updateLineState()
this.updateSpeed()
Expand Down Expand Up @@ -160,8 +160,6 @@ namespace microcode {
this.robot.armOpen(this.currentArmAperture)
}

private inRadioMessageId: number = undefined

/**
* Starts the reception and transmission of robot command messages
*/
Expand Down Expand Up @@ -290,7 +288,6 @@ namespace microcode {
else led.unplot(4, 0)
}

private lastSonarValue = 0
private updateSonar() {
const dist = this.ultrasonicDistance()
if (dist > this.robot.ultrasonicMinReading) {
Expand Down Expand Up @@ -331,13 +328,6 @@ namespace microcode {
}
}

/**
* Stop motors
*/
motorStop() {
this.motorRun(0, 0)
}

private ultrasonicDistanceOnce() {
if (!this.sonar) return this.robot.ultrasonicDistance()
else {
Expand Down
1 change: 0 additions & 1 deletion robot/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ microcode.elecfreaksCuteBot.start()
//microcode.dfRobotMaqueen.start()
//microcode.dfRobotMaqueenPlusV2.start()

microcode.robot.startRadio()
microcode.setRadioGroup(2)
microcode.setMotorDrift(0)

Expand Down

0 comments on commit 41ecd8b

Please sign in to comment.