Skip to content

Commit

Permalink
Improve block descriptions
Browse files Browse the repository at this point in the history
  • Loading branch information
noqman committed Dec 1, 2024
1 parent c9bd798 commit 060e6fa
Show file tree
Hide file tree
Showing 10 changed files with 127 additions and 80 deletions.
2 changes: 1 addition & 1 deletion battery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
namespace sumobit {

/**
* Read the current battery voltage (2 d.p.).
* Get the current battery voltage (2 d.p.).
*/
//% group="Battery"
//% weight=49
Expand Down
32 changes: 19 additions & 13 deletions edge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ namespace sumobit {
let leftThreshold: number;
let rightEdgeValue: number;
let leftEdgeValue: number;

/**
* Returns the right edge sensor value (0-1023).
*/
Expand All @@ -64,15 +65,17 @@ namespace sumobit {
leftEdgeValue = pins.analogReadPin(EDGE_L_PIN);
return leftEdgeValue;
}

/**
* Returns the edge sensor value (0-1023).
* @param edge Left or right sensor. eg: SumobitEdgeSelection.Right
* @param edge Sensor to read (Left or Right). eg: SumobitEdgeSelection.Right
*/
//% group="Edge Sensors"
//% weight=77
//% blockGap=8
//% blockId=sumobit_edge_return_value
//% block="%edge edge sensor"
//% edge.defl=0
export function fetchEdgeValue(edge: SumobitEdgeSelection): number {
switch (edge) {
case SumobitEdgeSelection.Right:
Expand All @@ -83,13 +86,13 @@ namespace sumobit {
return readRightEdgeValue();
}
}

/**
* Compare the edge sensor value (0-1023) with certain value and return true
if condition is meet.
* @param EdgeSide Which side of edge sensors are to compare to. eg: 0
* @param compareType More than or less than. eg: 0
* @param threshold The value to compare with. eg: 512
*/
* Compare the edge sensor value (0-1023) with certain value and return true if condition is meet.
* @param EdgeSide Which side of edge sensors are to compare to. eg: 0
* @param compareType More than or less than. eg: 0
* @param threshold The value to compare with. eg: 512
*/
//% group="Edge Sensors"
//% weight=76
//% blockGap=40
Expand Down Expand Up @@ -126,22 +129,23 @@ if condition is meet.
return result;
}
/**
* Edge threshold auto calibration.
* @param coefficient Threshold calibration ratio. eg: 5
* Calibrate edge sensor threshold.
* @param coefficient Threshold calibration ratio (Actual value is coefficient times 0.1). eg: 5
*/
//% group="Edge Sensors"
//% weight=75
//% blockGap=8
//% blockId=sumobit_edge_calibrate_threshold
//% block="set edge sensor threshold|| coefficient:%coefficient"
//% coefficient.min=1 coefficient.max=9
//% coefficient.min=1 coefficient.max=9
//% coefficient.defl=5
export function calibrateEdgeThreshold(coefficient: number = 5): void {
rightThreshold = pins.analogReadPin(EDGE_R_PIN) * (coefficient * 0.1);
leftThreshold = pins.analogReadPin(EDGE_L_PIN) * (coefficient * 0.1);
}

/**
* Return the calibrated edge threshold in seriel monitor for troubleshooting
purpose.
* Return the calibrated edge threshold in serial monitor for troubleshooting purpose.
*/
//% group="Edge Sensors"
//% weight=74
Expand All @@ -157,13 +161,15 @@ if condition is meet.
serial.writeLine("")
}
/**
* Compare.
* Returns true if sensor detects edge.
* @param edge Sensor to read (Left or Right). eg: SumobitEdgeSelection.Right
*/
//% group="Edge Sensors"
//% weight=73
//% blockGap=8
//% blockId=sumobit_edge_compare_calibrated_value
//% block="%edge sensor detect edge"
//% edge.defl=0
export function compareEdgeCalibrated(edge: SumobitEdgeSelection): boolean {
let result = false;
switch (edge) {
Expand Down
4 changes: 2 additions & 2 deletions main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ namespace sumobit {
sumobit.i2cWrite(REG_ADD_PWM2, 0);

// Disable the servos initially
sumobit.i2cWrite(ServoChannel.Servo1, 0);
sumobit.i2cWrite(ServoChannel.Servo2, 0);
sumobit.i2cWrite(SumobitServoChannel.Servo1, 0);
sumobit.i2cWrite(SumobitServoChannel.Servo2, 0);


/**
Expand Down
14 changes: 8 additions & 6 deletions mode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@

namespace sumobit {

// Mode event source flag.
const MODE_EVENT_SOURCE = 0x01;

// Flag to indicate whether the background function has been created.
let bgFunctionCreated = false;

// Event type.
Expand All @@ -25,7 +27,7 @@ let oldCompareResult: boolean[] = [];


/**
* Read the current mode number(0-15).
* Get the current mode number(0-15).
*/
//% group="Mode"
//% weight=69
Expand All @@ -37,22 +39,22 @@ let oldCompareResult: boolean[] = [];
}

/**
* Check the current mode number (0-15) and returns the result if true.
* @param modevalue The current DIP position. eg: 7
* Returns true if the mode matches the specified value.
* @param mode The mode number to compare. eg: 7
*/
//% group="Mode"
//% weight=68
//% blockGap=40
//% blockId=sumobit_mode_compare_value
//% block="mode %modevalue"
//% modevalue.min=0 modevalue.max=15
//% block="mode %mode"
//% mode.min=0 mode.max=15
//% mode.defl=7
export function checkMode(modevalue: number): boolean {
let result = false;

if (readModeValue() === modevalue) {
result = true;
}

return result;
}

Expand Down
31 changes: 18 additions & 13 deletions motor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

// Motor direction.
enum SumobitMotorDirection {

//% block="forward"
Forward = 0,

Expand All @@ -20,7 +19,6 @@ enum SumobitMotorDirection {

// Motor channel.
enum SumobitMotorChannel {

//% block="right"
RightMotor = 0,

Expand All @@ -36,13 +34,14 @@ namespace sumobit {

/**
* Stop motor
* @param motor Motorchannel eg: SumobitMotorChannel.RightMotor
* @param motor The motor to control. eg: SumobitMotorChannel.Both
*/
//% group="DC Motors"
//% weight=98
//% blockGap=8
//% blockId=sumobit_motor_stop
//% block="stop %motor motor"
//% motor.defl=1000
export function stopMotor(motor: SumobitMotorChannel): void {
switch (motor) {
case SumobitMotorChannel.RightMotor:
Expand All @@ -66,12 +65,11 @@ namespace sumobit {


/**
* Run the motor forward or backward.
* (Speed = 0-255) (Acceleration = 1-9).
* @param motor Motor channel.
* @param direction Motor direction.
* @param speed Motor speed (PWM). eg: 128
* @param acceleration Acceleration factor (1-9). eg: 9
* Run the motor forward or backward (Speed = 0-255) (Acceleration = 1-9).
* @param motor The motor to control. eg: SumobitMotorChannel.Both
* @param direction The direction of rotation (Forward or Backward). eg: SumobitMotorDirection.Forward
* @param speed The Motor speed (PWM). eg: 120
* @param acceleration Acceleration factor, higher value results in a faster rate of speed change (1-9). eg: 9
*/
//% group="DC Motors"
//% weight=99
Expand All @@ -80,8 +78,12 @@ namespace sumobit {
//% accel.fieldOptions.label="Acceleration Factor"
//% block="run %motor motor %direction at %speed speed || with %acceleration acceleration factor"
//% inlineInputMode=inline
//% motor.defl=0
//% direction.defl=1000
//% speed.min=0 speed.max=255
//% speed.defl=120
//% acceleration.min=1 acceleration.max=9
//% acceleration.defl=9
//% expandableArgumentMode="enabled"

export function runMotor(motor: SumobitMotorChannel, direction: SumobitMotorDirection, speed: number, acceleration: number = 9): void {
Expand Down Expand Up @@ -136,19 +138,22 @@ namespace sumobit {
}

/**
* Set individual motors speed (speed = -255 to 255, negative value = reverse).
* @param leftSpeed Speed for left motor. eg: 100
* @param rightSpeed Speed for right motor. eg: 100
* @param acceleration Speed for right motor. eg: 9
* Set the speed and direction of both motors independently (speed = -255 to 255, negative value = reverse).
* @param leftSpeed The desired speed of the left motor. eg: 120
* @param rightSpeed The desired speed of the right motor. eg: 120
* @param acceleration Acceleration factor, higher value results in a faster rate of speed change (1-9). eg: 9
*/
//% group="DC Motors"
//% weight=97
//% blockGap=8
//% blockId=sumobit_motor_set_speed
//% block="set motors speed: left %leftSpeed right %rightSpeed || acceleration %acceleration "
//% leftSpeed.min=-255 leftSpeed.max=255
//% leftSpeed.defl=120
//% rightSpeed.min=-255 rightSpeed.max=255
//% rightSpeed.defl=120
//% acceleration.min=1 acceleration.max=9
//% acceleration.defl=9
//% expandableArgumentMode="enabled"
export function setMotorsSpeed(leftSpeed: number, rightSpeed: number, acceleration: number = 9): void {
let leftDir = SumobitMotorDirection.Forward;
Expand Down
2 changes: 2 additions & 0 deletions motorcurrent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@ enum SumobitMotorChannel2 {

namespace sumobit {

// Mode event source flag.
const MOTORCURRENT_EVENT_SOURCE = 0x02;

// Flag for background function creation
let bgFunctionCreated = false;

// Event type.
Expand Down
10 changes: 6 additions & 4 deletions opponent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,15 @@ namespace sumobit {


/**
* Read the opponent sensor value.
* Returns the opponent sensor value.
* @param sensor The opponent sensor to read (Left, Front Left, Center, Front Right, Right). eg: SumobitSensorSelection1.Right
*/
//% group="Opponent Sensors"
//% weight=89
//% blockGap=8
//% blockId=sumobit_maker_object_read_digital
//% block="%sensor opponent sensor"
//% sensor.defl=4
//% position.fieldEditor="gridpicker" position.fieldOptions.columns=5
export function oppSensorValue(sensor: SumobitSensorSelection1): number {

Expand Down Expand Up @@ -90,14 +92,15 @@ namespace sumobit {
}

/**
* Return true if the opponent sensor is low (Obstacle detected).
* Returns true if the opponent sensor is low (Obstacle detected).
* @param sensor The opponent sensor to read (Left, Front Left, Center, Front Right, Right). eg: SumobitSensorSelection2.Right
*/
//% group="Opponent Sensors"
//% weight=88
//% blockGap=8
//% blockId=sumobit_maker_object_detect_opponent
//% block="%position sensor detect opponent"

//% position.defl = 4
export function oppSensorDetection(position: SumobitSensorSelection2): boolean {


Expand Down Expand Up @@ -159,7 +162,6 @@ namespace sumobit {
//% TogL.shadow="toggleHighLow" TogFL.shadow="toggleHighLow" TogFC.shadow="toggleHighLow" TogFR.shadow="toggleHighLow" TogR.shadow="toggleHighLow"
//% inlineInputMode=inline
//% blockHidden=true

export function oppSensorCombinationBoolean(TogL: boolean, TogFL: boolean, TogFC: boolean, TogFR: boolean, TogR: boolean): boolean {
let sensorValues = [

Expand Down
7 changes: 3 additions & 4 deletions rgb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ namespace sumobit {

}


/**
* Set all RGB pixels to the specified color.
* @param color RGB color of the pixel.
Expand Down Expand Up @@ -104,7 +103,7 @@ namespace sumobit {
/**
* Set individual RGB pixel to a certain colour
* @param pixel The pixel number we want to change the color.
* @param color RGB color of the pixel.
* @param color The desired color in RGB format.
*/
//% group="RGB LED"
//% weight=26
Expand All @@ -114,7 +113,7 @@ namespace sumobit {
//% color.shadow="colorNumberPicker"
//% pixel.min=0 pixel.max=1
//% pixel.fieldEditor="numberdropdown"
//% pixel.fieldOptions.decompileLiterals=true
//% pixel.fieldOptions.decompileLiterals=false
//% pixel.fieldOptions.values='0,1'
//% pixel.defl='0'

Expand Down Expand Up @@ -158,7 +157,7 @@ namespace sumobit {


/**
* Convert the specified red, green, and blue channel values into an RGB color value.
* Convert the specified red, green, and blue channel values into an RGB color value.
* @param red Value of the red channel (0 - 255). eg: 255
* @param green Value of the green channel (0 - 255). eg: 255
* @param blue Value of the blue channel (0 - 255). eg: 255
Expand Down
Loading

0 comments on commit 060e6fa

Please sign in to comment.