Skip to content

Commit

Permalink
Update new test.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
noqman committed Dec 1, 2024
1 parent 060e6fa commit 129c469
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 36 deletions.
4 changes: 2 additions & 2 deletions mode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,10 @@ let oldCompareResult: boolean[] = [];
//% block="mode %mode"
//% mode.min=0 mode.max=15
//% mode.defl=7
export function checkMode(modevalue: number): boolean {
export function checkMode(mode: number): boolean {
let result = false;

if (readModeValue() === modevalue) {
if (readModeValue() === mode) {
result = true;
}
return result;
Expand Down
2 changes: 1 addition & 1 deletion robot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ let searchMillis = control.millis();
/**
* Robot search routine
* @param mode The search mode. eg: SumobitSearch.0
* @param speed Motor speed when Front Centre sensor detects opponent (0-255). eg: 120
* @param speed Motor speed while searching for opponent. eg: 120
* @param acceleration Motor acceleration factor (1-9). eg: 9
*/
//% group="Robot Kit"
Expand Down
4 changes: 2 additions & 2 deletions servo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ enum SumobitServoChannel {
//% block="servo 2"
Servo2 = 2,

//% block="all"
//% block="all servos"
All = 1000,
};

Expand All @@ -32,7 +32,7 @@ namespace sumobit{
//% weight=38
//% blockGap=8
//% blockId=sumobit_servo_disable
//% block="disable servo %servo"
//% block="disable %servo"
//% servo.defl=1
export function disableServo(servo: SumobitServoChannel): void {

Expand Down
69 changes: 38 additions & 31 deletions test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// tests go here; this will not be compiled when this package is used as a library

/**
* tests go here; this will not be compiled when this package is used as a library
*/
function inputSerialDisplay() {
serial.writeString("OPP: ")
serial.writeNumber(sumobit.oppSensorValue(SumobitSensorSelection1.Left))
Expand All @@ -9,9 +10,9 @@ function inputSerialDisplay() {
serial.writeNumber(sumobit.oppSensorValue(SumobitSensorSelection1.Right))
serial.writeString(" | ")
serial.writeString("EDGE_R: ")
serial.writeNumber(sumobit.readRightEdgeValue())
serial.writeNumber(sumobit.fetchEdgeValue(SumobitEdgeSelection.Right))
serial.writeString(" EDGE_L: ")
serial.writeNumber(sumobit.readLeftEdgeValue())
serial.writeNumber(sumobit.fetchEdgeValue(SumobitEdgeSelection.Left))
serial.writeString(" | ")
serial.writeString("")
serial.writeString("Mode: ")
Expand All @@ -22,20 +23,22 @@ function inputSerialDisplay() {
serial.writeLine("")
basic.pause(100)
}
sumobit.calibrateEdgeThreshold()
sumobit.setSpeed(100)
sumobit.calibrateEdgeThreshold(5)
sumobit.setAllRgbPixelsColor(0xff0000)
sumobit.disableServo(SumobitServoChannel.All)
basic.pause(100)
sumobit.setRgbPixelColor(0, 0x00ff00)
sumobit.setRgbPixelColor(1, sumobit.rgb(0, 0, 255))
sumobit.setRgbPixelColor(0, sumobit.rgb(0, 0, 255))
sumobit.setRgbPixelColor(1, 0x00ffff)
sumobit.setServoPosition(SumobitServoChannel.Servo1, 90, 9)
basic.pause(100)
sumobit.clearAllRgbPixels()
sumobit.countdown(SumobitCountdown.Three)
sumobit.setMotorsSpeed(100, 100, 9)
sumobit.setServoPosition(SumobitServoChannel.Servo2, 90, 9)
basic.pause(500)
sumobit.stopMotor(SumobitMotorChannel.Both)
sumobit.runMotor(SumobitMotorChannel.RightMotor, SumobitMotorDirection.Forward, 128, 9)
sumobit.runMotor(SumobitMotorChannel.RightMotor, SumobitMotorDirection.Backward, 128, 9)
sumobit.setServoPosition(SumobitServoChannel.Servo2, 180, 9)
basic.pause(300)
sumobit.stopMotor(SumobitMotorChannel.Both)
let StartVar = 1
Expand All @@ -44,27 +47,6 @@ basic.forever(function () {
inputSerialDisplay()
if (StartVar == 1) {
if (sumobit.checkMode(1)) {
sumobit.backoff(SumobitDirection.Right)
} else {

}
if (sumobit.checkMode(2)) {
sumobit.attack(0,9)
} else {

}
if (sumobit.checkMode(3)) {
if (sumobit.compareEdgeCalibrated(SumobitEdgeSelection.Right)) {
sumobit.setRgbPixelColor(1, 0xffffff)
} else if (sumobit.compareEdgeCalibrated(SumobitEdgeSelection.Left)) {
sumobit.setRgbPixelColor(0, 0xffffff)
} else {
sumobit.clearAllRgbPixels()
}
} else {

}
if (sumobit.checkMode(4)) {
if (sumobit.oppSensorDetection(SumobitSensorSelection2.Left)) {
basic.showLeds(`
# . . . .
Expand Down Expand Up @@ -110,6 +92,31 @@ basic.forever(function () {
}
} else {

}
if (sumobit.checkMode(2)) {
sumobit.attack(0, 9)
} else {

}
if (sumobit.checkMode(3)) {
if (sumobit.compareEdgeCalibrated(SumobitEdgeSelection.Right)) {
sumobit.setRgbPixelColor(1, 0xff0000)
basic.pause(500)
sumobit.backoff(SumobitDirection.Left, 50, 9)
} else if (sumobit.compareEdgeCalibrated(SumobitEdgeSelection.Left)) {
sumobit.setRgbPixelColor(0, 0xff0000)
basic.pause(500)
sumobit.backoff(SumobitDirection.Right, 50, 9)
} else {
sumobit.clearAllRgbPixels()
}
} else {

}
if (sumobit.checkMode(4)) {
sumobit.search(SumobitSearch.Normal, 50, 9)
} else {

}
}
})
})

0 comments on commit 129c469

Please sign in to comment.