Skip to content

Commit

Permalink
Revised comments and notations
Browse files Browse the repository at this point in the history
  • Loading branch information
noqman committed Oct 22, 2024
1 parent 5703d1c commit 21b9729
Show file tree
Hide file tree
Showing 9 changed files with 74 additions and 72 deletions.
6 changes: 3 additions & 3 deletions battery.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Functions for SUMO:BIT battery input
* Function for SUMO:BIT battery input
*
* Company: Cytron Technologies Sdn Bhd
* Website: http://www.cytron.io
Expand All @@ -9,12 +9,12 @@
namespace sumobit {

/**
* Return the current battery voltage.
* Read the current battery voltage (2 d.p.).
*/
//% group="Battery"
//% weight=49
//% blockGap=8
//% blockId=sumobit_read_VIN
//% blockId=sumobit_battery_read
//% block="battery voltage"
export function readBatteryValue(): number {
let highByte: number;
Expand Down
10 changes: 5 additions & 5 deletions edge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,24 +37,24 @@ enum EdgeCompareType {
namespace sumobit {

/**
* Return the right edge sensor value (0-1023).
* Read the right edge sensor value (0-1023).
*/
//% group="Edge Sensors"
//% weight=79
//% blockGap=8
//% blockId=sumobit_read_edge_R_value
//% blockId=sumobit_edge_read_value_right
//% block="right edge sensor"
export function readEdgeRValue(): number {
return pins.analogReadPin(EDGE_R_PIN);
}

/**
* Return the left edge sensor value (0-1023).
* Read the left edge sensor value (0-1023).
*/
//% group="Edge Sensors"
//% weight=78
//% blockGap=8
//% blockId=sumobit_read_edge_L_value
//% blockId=sumobit_edge_read_value_left
//% block="left edge sensor"
export function readEdgeLValue(): number {
return pins.analogReadPin(EDGE_L_PIN);
Expand All @@ -70,7 +70,7 @@ namespace sumobit {
//% group="Edge Sensors"
//% weight=77
//% blockGap=40
//% blockId=sumobit_compare_edge_value
//% blockId=sumobit_edge_compare_value
//% block="%side edge sensor %compareType %threshold"
//% threshold.min=0 threshold.max=1023
export function compareEdge(side: EdgeSide, compareType: EdgeCompareType, threshold: number,): boolean {
Expand Down
12 changes: 8 additions & 4 deletions main.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
// I2C Adress
/**
* Board initialization and helper function.
*/

// I2C slave address for RP2040
const I2C_ADDRESS = 0x09;

// Register addresses.
// I2C register addresses
const REG_ADD_REVISION = 0;
const REG_ADD_SRV1_POS = 1;
const REG_ADD_SRV1_SPEED = 2;
Expand Down Expand Up @@ -40,14 +44,14 @@ const REG_VIN_R2 = 34;
const REG_ADD_DIP = 35;
const REG_ADD_RESET = 36;

// Software pullup for the opponent sensors
pins.setPull(DigitalPin.P16, PinPullMode.PullUp)
pins.setPull(DigitalPin.P15, PinPullMode.PullUp)
pins.setPull(DigitalPin.P14, PinPullMode.PullUp)
pins.setPull(DigitalPin.P13, PinPullMode.PullUp)
pins.setPull(DigitalPin.P12, PinPullMode.PullUp)



/**
* Blocks for SUMO:BIT.
*/
Expand All @@ -56,7 +60,7 @@ pins.setPull(DigitalPin.P12, PinPullMode.PullUp)
//% groups=['DC Motors', 'Servos' , 'Mode', 'Motor Current','Opponent Sensors' , 'Edge Sensors', 'RGB LED']
namespace sumobit {

// Stop all motor at start
// Stop all motor.
brakeMotor(MotorChannel.MR);
brakeMotor(MotorChannel.ML);

Expand Down
6 changes: 3 additions & 3 deletions mode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ namespace sumobit {


/**
* Return the current mode number(0-15).
* Read the current mode number(0-15).
*/
//% group="Mode"
//% weight=69
//% blockGap=8
//% blockId=sumobit_read_mode_value
//% blockId=sumobit_mode_read_value
//% block="mode"
export function readModeValue(): number {
return sumobit.i2cRead(REG_ADD_DIP);
Expand All @@ -40,7 +40,7 @@ namespace sumobit {
//% group="Mode"
//% weight=68
//% blockGap=40
//% blockId=sumobit_check_mode_value
//% blockId=sumobit_mode_compare_value
//% block="mode %modevalue"
//% modevalue.min=0 modevalue.max=15
export function checkMode(modevalue: number): boolean {
Expand Down
11 changes: 6 additions & 5 deletions motor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@ export enum MotorChannel {

/**
* Stop motor
* @param motor Motorchannel eg: Motor.M1, Motor.M2
* @param motor Motorchannel eg: Motor.M1
*/
//% group="DC Motors"
//% weight=98
//% blockGap=8
//% blockId=sumobit_brake_motor
//% blockId=sumobit_motor_brake
//% block="brake motor %motor"
export function brakeMotor(motor: MotorChannel): void {
switch (motor) {
Expand All @@ -65,16 +65,17 @@ export enum MotorChannel {


/**
* Run the motor forward or backward (Speed = 0-255).
* Run the motor forward or backward.
* (Speed = 0-255) (Acceleration = 0-9).
* @param motor Motor channel.
* @param direction Motor direction.
* @param speed Motor speed (0-255). eg: 128
* @param speed Motor speed (PWM). eg: 128
* @param accelaration Acceleration factor (0-9). eg: 0
*/
//% group="DC Motors"
//% weight=99
//% blockGap=8
//% blockId=sumobit_run_motor
//% blockId=sumobit_motor_run
//% accel.fieldOptions.label="Acceleration Factor"
//% block="run %motor motor %direction at %speed speed || with %accelaration acceleration factor"
//% inlineInputMode=inline
Expand Down
17 changes: 8 additions & 9 deletions motorcurrent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ enum CompareType {

namespace sumobit {

//
let bgFunctionCreated = false;

// Event type.
Expand All @@ -57,12 +56,12 @@ namespace sumobit {


/**
* Return Right Motor current value.
* Read the right motor current value (2 d.p.).
*/
//% group="Motor Current"
//% weight=59
//% blockGap=8
//% blockId=sumobit_read_m1_current_value
//% blockId=sumobit_current_read_m1
//% block="right motor current"
export function readM1CurrentValue(): number {
let highByte: number;
Expand All @@ -73,12 +72,12 @@ namespace sumobit {
}

/**
* Return motor 2 current value.
* Read the left motor current value (2 d.p.).
*/
//% group="Motor Current"
//% weight=58
//% blockGap=8
//% blockId=sumobit_read_m2_current_value
//% blockId=sumobit_current_read_m2
//% block="left motor current"
export function readM2CurrentValue(): number {
let highByte: number;
Expand All @@ -91,13 +90,13 @@ namespace sumobit {


/**
* Compare the motor current value (0.00-20.00) and returns the result (true/false).
* Compare the motor current value (0.00-20.00) with a threshold value and returns the result (true/false).
* @param threshold The current DIP position. eg: 14.00
*/
//% group="Motor Current"
//% weight=57
//% blockGap=40
//% blockId=sumobit_compare_current_value
//% blockId=sumobit_current_compare_value
//% block="%motor current %compareType %threshold"
//% threshold.min=0.00 threshold.max=15.00 REG_ADD_AN1_HIGH
//% blockHidden=true
Expand Down Expand Up @@ -132,7 +131,7 @@ namespace sumobit {


/**
* Compare the motor current value with a certain value and do something when true.
* Compare the motor current value with a threshold value and do something when true.
* @param motor M1, M2 or Both.
* @param compareType More than or less than.
* @param threshold The value to compare with. eg: 7.00
Expand All @@ -141,7 +140,7 @@ namespace sumobit {
//% group="Motor Current"
//% weight=56
//% blockGap=40
//% blockId=sumobit_motorcurrent_event
//% blockId=sumobit_current_event
//% block="on %motor current %compareType %threshold"
//% threshold.min=0.00 threshold.max=15.00
export function onEvent(motor: CompareSelect, compareType: CompareType, threshold: number, handler: Action): void {
Expand Down
52 changes: 26 additions & 26 deletions opponent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
* Email: [email protected]
*******************************************************************************/

enum SensorPosition {

enum SensorSelection1 {
//% block="left"
Left2 = 0,

Expand All @@ -21,15 +22,9 @@ enum SensorPosition {

//% block="right"
Right2 = 4,

//% block="all"
All = 5,

//% block="none"
None = 6
}

enum Sensor {
enum SensorSelection2 {
//% block="left"
Left2 = 0,

Expand All @@ -44,11 +39,13 @@ enum Sensor {

//% block="right"
Right2 = 4,
}



//% block="all"
All = 5,

//% block="none"
None = 6
}

namespace sumobit {

Expand All @@ -60,18 +57,18 @@ namespace sumobit {
//% blockGap=8
//% blockId=sumobit_maker_object_read_digital
//% block="%sensor Opponent sensor"
export function OppSensorValue(sensor: Sensor): number {
export function OppSensorValue(sensor: SensorSelection1): number {

switch (sensor) {
case Sensor.Left2:
case SensorSelection1.Left2:
return pins.digitalReadPin(DigitalPin.P16);
case Sensor.Left1:
case SensorSelection1.Left1:
return pins.digitalReadPin(DigitalPin.P15);;
case Sensor.Center:
case SensorSelection1.Center:
return pins.digitalReadPin(DigitalPin.P14);
case Sensor.Right1:
case SensorSelection1.Right1:
return pins.digitalReadPin(DigitalPin.P13);
case Sensor.Right2:
case SensorSelection1.Right2:
return pins.digitalReadPin(DigitalPin.P12);

}
Expand All @@ -87,7 +84,7 @@ namespace sumobit {
//% blockId=sumobit_maker_object_detect_opponent
//% block="%position sensor detect opponent"
//% position.fieldEditor="gridpicker" position.fieldOptions.columns=5
export function OppSensorDetection(position: SensorPosition): boolean {
export function OppSensorDetection(position: SensorSelection2): boolean {



Expand All @@ -98,37 +95,37 @@ namespace sumobit {
let R = OppSensorValue(4);

switch (position) {
case SensorPosition.None:
case SensorSelection2.None:
if (L == 1 && FL == 1 && FC == 1 && FR == 1 && R == 1)
return true;
else return false;

case SensorPosition.Left2:
case SensorSelection2.Left2:
if (L == 0 && FL == 1 && FC == 1 && FR == 1 && R == 1)
return true;
else return false;

case SensorPosition.Left1:
case SensorSelection2.Left1:
if (L == 1 && FL == 0 && FC == 1 && FR == 1 && R == 1)
return true;
else return false;

case SensorPosition.Center:
case SensorSelection2.Center:
if (L == 1 && FL == 1 && FC == 0 && FR == 1 && R == 1)
return true;
else return false;

case SensorPosition.Right1:
case SensorSelection2.Right1:
if (L == 1 && FL == 1 && FC == 1 && FR == 0 && R == 1)
return true;
else return false;

case SensorPosition.Right2:
case SensorSelection2.Right2:
if (L == 1 && FL == 1 && FC == 1 && FR == 1 && R == 0)
return true;
else return false;

case SensorPosition.All:
case SensorSelection2.All:
if (L == 0 && FL == 0 && FC == 0 && FR == 0 && R == 0)
return true;
else return false;
Expand All @@ -138,15 +135,18 @@ namespace sumobit {
}

/**
* Opp sensor combination
* Compare the toggle values with the current sensor states.
* Returns true if ALL match. (LOW = obstacle detacted).
*/
//% group="Opponent Sensors"
//% weight=87
//% blockId=sumobit_maker_object_compare_expected_with_sensor
//% block="L$TogL FL$TogFL FC$TogFC FR$TogFR R$TogR"
//% TogL.shadow="toggleHighLow" TogFL.shadow="toggleHighLow" TogFC.shadow="toggleHighLow" TogFR.shadow="toggleHighLow" TogR.shadow="toggleHighLow"
//% inlineInputMode=inline
export function OppSensorCombinationBoolean(TogL: boolean, TogFL: boolean, TogFC: boolean, TogFR: boolean, TogR: boolean): boolean {
let sensorValues = [

OppSensorValue(0), // L
OppSensorValue(1), // FL
OppSensorValue(2), // FC
Expand Down
Loading

0 comments on commit 21b9729

Please sign in to comment.