Skip to content

Commit

Permalink
Issue #1446: call clap sensor sample each time a "noisy" programming …
Browse files Browse the repository at this point in the history
…block ends
  • Loading branch information
bjost2s committed Feb 4, 2023
1 parent 799d0c6 commit 081d23b
Show file tree
Hide file tree
Showing 7 changed files with 412 additions and 327 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,33 +15,46 @@
def ____drive():
global ___n, ___b, ___nl
_diffDrive(Ed.FORWARD, ___n, ___n)
Ed.ReadClapSensor()
_diffDrive(Ed.BACKWARD, ___n, ___n)
Ed.ReadClapSensor()
_diffDrive(Ed.FORWARD, ___n, Ed.DISTANCE_UNLIMITED)
_diffDrive(Ed.BACKWARD, ___n, Ed.DISTANCE_UNLIMITED)
Ed.Drive(Ed.STOP, Ed.SPEED_1, 1)
Ed.ReadClapSensor()
_diffTurn(Ed.SPIN_RIGHT, ___n, ___n)
Ed.ReadClapSensor()
_diffTurn(Ed.SPIN_LEFT, ___n, ___n)
Ed.ReadClapSensor()
_diffTurn(Ed.SPIN_RIGHT, ___n, Ed.DISTANCE_UNLIMITED)
_diffTurn(Ed.SPIN_LEFT, ___n, Ed.DISTANCE_UNLIMITED)
_diffCurve(Ed.FORWARD, ___n, ___n, ___n)
Ed.ReadClapSensor()
_diffCurve(Ed.BACKWARD, ___n, ___n, ___n)
Ed.ReadClapSensor()
_diffCurve(Ed.FORWARD, ___n, ___n, Ed.DISTANCE_UNLIMITED)
_diffCurve(Ed.BACKWARD, ___n, ___n, Ed.DISTANCE_UNLIMITED)

def ____sounds():
global ___n, ___b, ___nl
Ed.PlayTone(8000000/1000, ___n)
Ed.TimeWait(___n, Ed.TIME_MILLISECONDS)
Ed.ReadClapSensor()
Ed.PlayTone(4000000/261, 2000)
Ed.TimeWait(2000, Ed.TIME_MILLISECONDS)
Ed.ReadClapSensor()
Ed.PlayTone(4000000/293, 1000)
Ed.TimeWait(1000, Ed.TIME_MILLISECONDS)
Ed.ReadClapSensor()
Ed.PlayTone(4000000/329, 500)
Ed.TimeWait(500, Ed.TIME_MILLISECONDS)
Ed.ReadClapSensor()
Ed.PlayTone(4000000/349, 250)
Ed.TimeWait(250, Ed.TIME_MILLISECONDS)
Ed.ReadClapSensor()
Ed.PlayTone(4000000/391, 125)
Ed.TimeWait(125, Ed.TIME_MILLISECONDS)
Ed.ReadClapSensor()

def ____lights():
global ___n, ___b, ___nl
Expand All @@ -60,30 +73,34 @@ def ____move():
_motorOn(0, ___n, Ed.DISTANCE_UNLIMITED)
_motorOn(1, ___n, Ed.DISTANCE_UNLIMITED)
Ed.DriveLeftMotor(Ed.STOP, Ed.SPEED_1, 1)
Ed.ReadClapSensor()
Ed.DriveRightMotor(Ed.STOP, Ed.SPEED_1, 1)
Ed.ReadClapSensor()

____action()
___soundfile1 = Ed.TuneString(7,"c8e8g8z")
Ed.PlayTune(___soundfile1)
while (Ed.ReadMusicEnd() == Ed.MUSIC_NOT_FINISHED):
pass
Ed.ReadClapSensor()
___soundfile2 = Ed.TuneString(7,"g8e8c8z")
Ed.PlayTune(___soundfile2)
while (Ed.ReadMusicEnd() == Ed.MUSIC_NOT_FINISHED):
pass
Ed.ReadClapSensor()


def _diffCurve(direction, leftSpeed, rightSpeed, distance):
if (leftSpeed < 0):
if (leftSpeed < 0):
_leftSpeed = _shorten(-leftSpeed)
_reverseLeft = True
else:
else:
_leftSpeed = _shorten(leftSpeed)
_reverseLeft = False
if (rightSpeed < 0):
if (rightSpeed < 0):
_rightSpeed = _shorten(-rightSpeed)
_reverseRight = True
else:
else:
_rightSpeed = _shorten(rightSpeed)
_reverseRight = False
if (_leftSpeed > _rightSpeed):
Expand All @@ -93,15 +110,17 @@ def _diffCurve(direction, leftSpeed, rightSpeed, distance):
Ed.DriveLeftMotor(_getDirection(direction, _reverseLeft), _leftSpeed, Ed.DISTANCE_UNLIMITED)
Ed.DriveRightMotor(_getDirection(direction, _reverseRight), _rightSpeed, Ed.DISTANCE_UNLIMITED)
Ed.DriveLeftMotor(_getDirection(direction, _reverseLeft), _leftSpeed, distance)
if (distance != Ed.DISTANCE_UNLIMITED): Ed.Drive(Ed.STOP, 1, 1)
if (distance != Ed.DISTANCE_UNLIMITED):
Ed.Drive(Ed.STOP, 1, 1)
elif (_leftSpeed < _rightSpeed):
if (_leftSpeed == 0):
Ed.DriveLeftMotor(Ed.STOP, 0, 0)
else:
Ed.DriveRightMotor(_getDirection(direction, _reverseRight), _rightSpeed, Ed.DISTANCE_UNLIMITED)
Ed.DriveLeftMotor(_getDirection(direction, _reverseLeft), _leftSpeed, Ed.DISTANCE_UNLIMITED)
Ed.DriveRightMotor(_getDirection(direction, _reverseRight), _rightSpeed, distance)
if (distance != Ed.DISTANCE_UNLIMITED): Ed.Drive(Ed.STOP, 1, 1)
if (distance != Ed.DISTANCE_UNLIMITED):
Ed.Drive(Ed.STOP, 1, 1)
else:
if (_leftSpeed == 0):
Ed.Drive(Ed.STOP, 1, 1)
Expand All @@ -113,27 +132,38 @@ def _diffDrive(direction, speed, distance):
if speed < 0:
_reverse = True
_speed = _shorten(-speed)
else: _speed = _shorten(speed)
if (_speed == 0): Ed.Drive(Ed.STOP, 1, 1)
else: Ed.Drive(_getDirection(direction, _reverse), _speed, distance)
else:
_speed = _shorten(speed)
if (_speed == 0):
Ed.Drive(Ed.STOP, 1, 1)
else:
Ed.Drive(_getDirection(direction, _reverse), _speed, distance)

def _diffTurn(direction, speed, degree):
_reverse = False
if speed < 0:
_reverse = True
_speed = _shorten(-speed)
else: _speed = _shorten(speed)
if (_speed == 0): Ed.Drive(Ed.STOP, 1, 1)
else:
_speed = _shorten(speed)
if (_speed == 0):
Ed.Drive(Ed.STOP, 1, 1)
elif _reverse:
if direction == Ed.SPIN_RIGHT: Ed.Drive(Ed.SPIN_LEFT, _speed, degree)
else: Ed.Drive(Ed.SPIN_RIGHT, _speed, degree)
else: Ed.Drive(direction, _speed, degree)
if direction == Ed.SPIN_RIGHT:
Ed.Drive(Ed.SPIN_LEFT, _speed, degree)
else:
Ed.Drive(Ed.SPIN_RIGHT, _speed, degree)
else:
Ed.Drive(direction, _speed, degree)

def _getDirection(dir, reverse):
if reverse:
if (dir == Ed.FORWARD): return Ed.BACKWARD
else: return Ed.FORWARD
else: return dir
if (dir == Ed.FORWARD):
return Ed.BACKWARD
else:
return Ed.FORWARD
else:
return dir

def _motorOn(motor, power, distance):
_dir = Ed.FORWARD
Expand All @@ -143,10 +173,15 @@ def _motorOn(motor, power, distance):
_reverse = True
else: _power = _shorten(power)
if (motor == Ed.MOTOR_LEFT):
if (_power == 0): Ed.DriveLeftMotor(Ed.STOP, 0, 0)
else: Ed.DriveLeftMotor(_getDirection(_dir, _reverse), _power, distance)
if (_power == 0):
Ed.DriveLeftMotor(Ed.STOP, 0, 0)
else:
Ed.DriveLeftMotor(_getDirection(_dir, _reverse), _power, distance)
if (motor == Ed.MOTOR_RIGHT):
if (_power == 0): Ed.DriveRightMotor(Ed.STOP, 0, 0)
else: Ed.DriveRightMotor(_getDirection(_dir, _reverse), _power, distance)
if (_power == 0):
Ed.DriveRightMotor(Ed.STOP, 0, 0)
else:
Ed.DriveRightMotor(_getDirection(_dir, _reverse), _power, distance)

def _shorten(num): return ((num+5)/10)
def _shorten(num):
return ((num+5)/10)
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,10 @@ def ____lists():


def _abs(num):
if (num < 0): return -num
else: return num
if (num < 0):
return -num
else:
return num

def max(list):
listMax = list[0]
Expand All @@ -77,15 +79,18 @@ def _pow(base, exp):
return result

def _isPrime(num):
if num <= 1: return False
if num <= 1:
return False
newNum = num - 2
for x in range(newNum):
y = (x + 2)
if (num % y) == 0: return False
if (num % y) == 0:
return False
return True

def sum(list):
listSum = 0
listLength = len(list)
for i in range(listLength): listSum = (listSum + list[i])
for i in range(listLength):
listSum = (listSum + list[i])
return listSum
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,10 @@ def _irSeek(mode):
if (obstacleDetectionOn == True):
Ed.ObstacleDetectionBeam(Ed.OFF)
obstacleDetectionOn = False
if (mode == 0): return Ed.ReadIRData()
elif (mode == 1): return Ed.ReadRemote()
if (mode == 0):
return Ed.ReadIRData()
elif (mode == 1):
return Ed.ReadRemote()

def _obstacleDetection(mode):
global obstacleDetectionOn
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,10 @@ def _irSeek(mode):
if (obstacleDetectionOn == True):
Ed.ObstacleDetectionBeam(Ed.OFF)
obstacleDetectionOn = False
if (mode == 0): return Ed.ReadIRData()
elif (mode == 1): return Ed.ReadRemote()
if (mode == 0):
return Ed.ReadIRData()
elif (mode == 1):
return Ed.ReadRemote()

def _irSend(payload):
global obstacleDetectionOn
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,6 @@ public Void visitDriveAction(DriveAction driveAction) {
direction = "Ed.BACKWARD";
break;
}

this.sb.append(this.getBean(CodeGeneratorSetupBean.class)
.getHelperMethodGenerator()
.getHelperMethodName(EdisonMethods.DIFFDRIVE));
Expand All @@ -270,9 +269,11 @@ public Void visitDriveAction(DriveAction driveAction) {
} else {
this.sb.append("Ed.DISTANCE_UNLIMITED");
}

this.sb.append(")");

if ( driveAction.param.getDuration() != null ) {
nlIndent();
this.sb.append("Ed.ReadClapSensor()");
}
return null;
}

Expand Down Expand Up @@ -401,6 +402,10 @@ public Void visitCurveAction(CurveAction curveAction) {
curveAction.paramLeft.getDuration().getValue().accept(this);
}
this.sb.append(")");
if ( curveAction.paramLeft.getDuration() != null ) {
nlIndent();
this.sb.append("Ed.ReadClapSensor()");
}
return null;
}

Expand All @@ -421,7 +426,10 @@ public Void visitTurnAction(TurnAction turnAction) {
this.sb.append("Ed.DISTANCE_UNLIMITED");
}
this.sb.append(")");

if ( turnAction.param.getDuration() != null ) {
nlIndent();
this.sb.append("Ed.ReadClapSensor()");
}
return null;
}

Expand Down Expand Up @@ -476,6 +484,8 @@ public Void visitMotorStopAction(MotorStopAction motorStopAction) {
default:
break;
}
nlIndent();
this.sb.append("Ed.ReadClapSensor()");
return null;
}

Expand All @@ -494,6 +504,8 @@ public Void visitBinary(Binary binary) {
@Override
public Void visitMotorDriveStopAction(MotorDriveStopAction stopAction) {
this.sb.append("Ed.Drive(Ed.STOP, Ed.SPEED_1, 1)");
nlIndent();
this.sb.append("Ed.ReadClapSensor()");
return null;
}

Expand Down Expand Up @@ -629,6 +641,8 @@ public Void visitToneAction(ToneAction toneAction) {
this.sb.append("Ed.TimeWait(");
toneAction.duration.accept(this);
this.sb.append(", Ed.TIME_MILLISECONDS)");
nlIndent();
this.sb.append("Ed.ReadClapSensor()");
return null;
}

Expand All @@ -639,6 +653,8 @@ public Void visitPlayNoteAction(PlayNoteAction playNoteAction) {
this.sb.append(", ").append(playNoteAction.duration).append(")");
nlIndent();
this.sb.append("Ed.TimeWait(").append(playNoteAction.duration).append(", Ed.TIME_MILLISECONDS)");
nlIndent();
this.sb.append("Ed.ReadClapSensor()");
return null;
}

Expand Down Expand Up @@ -688,7 +704,8 @@ public Void visitPlayFileAction(PlayFileAction playFileAction) {
nlIndent();
this.sb.append("pass");
decrIndentation();

nlIndent();
this.sb.append("Ed.ReadClapSensor()");
return null;
}

Expand Down
Loading

0 comments on commit 081d23b

Please sign in to comment.