Skip to content

Commit bf3d27d

Browse files
committed
1 parent 7f2e001 commit bf3d27d

File tree

4 files changed

+16
-14
lines changed

4 files changed

+16
-14
lines changed

sonar.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ class Sonar:
1616

1717
MICROSECONDS = 1000000.0
1818
SOUND_SPEED = 34030.0
19+
ECHO_TIMEOUT = 0.1
1920

2021
def __init__(self, pi, trigger, echo):
2122
"""
@@ -44,7 +45,7 @@ def __init__(self, pi, trigger, echo):
4445
self._inited = True
4546

4647
def _cbf(self, gpio, level, tick):
47-
if gpio == self._trig:
48+
if gpio == self._trig and self._triggered == False:
4849
if level == 0: # trigger sent
4950
self._triggered = True
5051
self._high = None
@@ -57,7 +58,8 @@ def _cbf(self, gpio, level, tick):
5758
self._time = tick - self._high
5859
self._high = None
5960
self._ping = True
60-
61+
self._triggered = False
62+
print "elapsed: " + str(self._time)
6163
def read(self):
6264
"""
6365
Triggers a reading. The returned reading is the number
@@ -70,7 +72,7 @@ def read(self):
7072
self.pi.gpio_trigger(self._trig)
7173
start = time.time()
7274
while not self._ping:
73-
if (time.time()-start) > 5.0:
75+
if (time.time()-start) > self.ECHO_TIMEOUT:
7476
return 20000
7577
time.sleep(0.001)
7678
return self._time

static/js/blockly/blocks.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -802,9 +802,9 @@ Blockly.Blocks['coderbot_sonar_get_distance'] = {
802802
this.setColour(250);
803803
this.appendDummyInput()
804804
.appendField(Blockly.Msg.CODERBOT_SONAR_GET_DISTANCE)
805-
.appendField(new Blockly.FieldDropdown([[Blockly.Msg.CODERBOT_SONAR_SENSOR_1, 0],
806-
[Blockly.Msg.CODERBOT_SONAR_SENSOR_2, 1],
807-
[Blockly.Msg.CODERBOT_SONAR_SENSOR_3, 2]]), 'SONAR');
805+
.appendField(new Blockly.FieldDropdown([[Blockly.Msg.CODERBOT_SONAR_SENSOR_1, "0"],
806+
[Blockly.Msg.CODERBOT_SONAR_SENSOR_2, "1"],
807+
[Blockly.Msg.CODERBOT_SONAR_SENSOR_3, "2"]]), 'SONAR');
808808
this.setOutput(true, 'Number');
809809
this.setTooltip(Blockly.Msg.LOGIC_BOOLEAN_TOOLTIP);
810810
}

static/js/blockly/bot_en.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ Blockly.Msg.CODERBOT_AUDIO_LISTEN = "listen";
7171
Blockly.Msg.CODERBOT_AUDIO_LISTEN_MODEL_SIMPLE = "simple commands";
7272
Blockly.Msg.CODERBOT_AUDIO_LISTEN_MODEL_MEDIUM = "medium commands";
7373
Blockly.Msg.CODERBOT_AUDIO_LISTEN_MODEL_ADV = "advance commands";
74-
Blockly.Msg.CODERBOT_SONAR_GET_DISTANCE = "get distance with";
75-
Blockly.Msg.CODERBOT_SONAR_SENSOR_1 = "sonar 1";
76-
Blockly.Msg.CODERBOT_SONAR_SENSOR_2 = "sonar 2";
77-
Blockly.Msg.CODERBOT_SONAR_SENSOR_3 = "sonar 3";
74+
Blockly.Msg.CODERBOT_SONAR_GET_DISTANCE = "get distance with sonar";
75+
Blockly.Msg.CODERBOT_SONAR_SENSOR_1 = "1";
76+
Blockly.Msg.CODERBOT_SONAR_SENSOR_2 = "2";
77+
Blockly.Msg.CODERBOT_SONAR_SENSOR_3 = "3";

static/js/blockly/bot_it.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ Blockly.Msg.CODERBOT_AUDIO_LISTEN = "ascolta";
7171
Blockly.Msg.CODERBOT_AUDIO_LISTEN_MODEL_SIMPLE = "commandi semplici";
7272
Blockly.Msg.CODERBOT_AUDIO_LISTEN_MODEL_MEDIUM = "commandi medi";
7373
Blockly.Msg.CODERBOT_AUDIO_LISTEN_MODEL_ADV = "comandi avanzati";
74-
Blockly.Msg.CODERBOT_SONAR_GET_DISTANCE = "leggi distanza con";
75-
Blockly.Msg.CODERBOT_SONAR_SENSOR_1 = "sonar 1";
76-
Blockly.Msg.CODERBOT_SONAR_SENSOR_2 = "sonar 2";
77-
Blockly.Msg.CODERBOT_SONAR_SENSOR_3 = "sonar 3";
74+
Blockly.Msg.CODERBOT_SONAR_GET_DISTANCE = "leggi distanza con sonar";
75+
Blockly.Msg.CODERBOT_SONAR_SENSOR_1 = "1";
76+
Blockly.Msg.CODERBOT_SONAR_SENSOR_2 = "2";
77+
Blockly.Msg.CODERBOT_SONAR_SENSOR_3 = "3";

0 commit comments

Comments
 (0)