Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#1222 Ultrasonic HC-SR04 #1223

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -137,4 +137,6 @@ public interface SC {

String OLEDSSD1306I2C = "OLEDSSD1306I2C";

String ULTRASONIC_HCSR04 = "ULTRASONIC_HCSR04";

}
4 changes: 2 additions & 2 deletions OpenRobertaRobot/src/main/resources/robotCommon.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ block:
ULTRASONIC_SENSING:
category: SENSOR
implementor: de.fhg.iais.roberta.syntax.sensor.generic.UltrasonicSensor
type: [robSensors_ultrasonic_getSample,sim_ultrasonic_getSample]
type: [robSensors_ultrasonic_getSample,sim_ultrasonic_getSample,robsensors_ultrasonic_hcsr04_getsample]
INFRARED_SENSING:
category: SENSOR
implementor: de.fhg.iais.roberta.syntax.sensor.generic.InfraredSensor
Expand Down Expand Up @@ -859,7 +859,7 @@ configuration:
TEMPERATURE: [robConf_temperature, robBrick_temperature]
TIMER: [robBrick_timer]
TOUCH: [robBrick_touch]
ULTRASONIC: [robConf_ultrasonic, robBrick_ultrasonic]
ULTRASONIC: [robConf_ultrasonic, robConf_ultrasonic_hcsr04, robBrick_ultrasonic]
WEDO: [robBrick_WeDo-Brick]
WIRELESS: [robConf_wireless]
PARTICLE: [robConf_particle]
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@

(repeat [FOREVER, BoolConst[value: true]]
Var [abstand] := SensorExpr [UltrasonicSensor [U1, DISTANCE, - EMPTY_SLOT -]]

AktionStmt [DisplayTextAction [TEXT, FunctionExpr [MathSingleFunct [ROUND, [Var [abstand]]]]]]WaitTimeStmt[time: NumConst[value: 1000]]
)

Var [abstand] := SensorExpr [UltrasonicSensor [U2, DISTANCE, - EMPTY_SLOT -]]


Var [abstand] := SensorExpr [UltrasonicSensor [U3, DISTANCE, - EMPTY_SLOT -]]

Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@

(repeat [FOREVER, BoolConst[value: true]]
Var [abstand] := SensorExpr [UltrasonicSensor [U1, DISTANCE, - EMPTY_SLOT -]]

AktionStmt [DisplayTextAction [TEXT, FunctionExpr [MathSingleFunct [ROUND, [Var [abstand]]]]]]WaitTimeStmt[time: NumConst[value: 1000]]
)

Var [abstand] := SensorExpr [UltrasonicSensor [U2, DISTANCE, - EMPTY_SLOT -]]


Var [abstand] := SensorExpr [UltrasonicSensor [U3, DISTANCE, - EMPTY_SLOT -]]

Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@

(repeat [FOREVER, BoolConst[value: true]]
Var [abstand] := SensorExpr [UltrasonicSensor [U1, DISTANCE, - EMPTY_SLOT -]]

AktionStmt [DisplayTextAction [TEXT, FunctionExpr [MathSingleFunct [ROUND, [Var [abstand]]]]]]WaitTimeStmt[time: NumConst[value: 1000]]
)

Var [abstand] := SensorExpr [UltrasonicSensor [U2, DISTANCE, - EMPTY_SLOT -]]


Var [abstand] := SensorExpr [UltrasonicSensor [U3, DISTANCE, - EMPTY_SLOT -]]

Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Sensors:
[]
Actors:
[UsedActor [U1, ULTRASONIC], UsedActor [, DISPLAY], UsedActor [U2, ULTRASONIC], UsedActor [U3, ULTRASONIC]]
Methods:
[GET_ULTARSONIC_SAMPLE, ROUND]
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Sensors:
[]
Actors:
[UsedActor [U1, ULTRASONIC], UsedActor [, DISPLAY], UsedActor [U2, ULTRASONIC], UsedActor [U3, ULTRASONIC]]
Methods:
[GET_ULTARSONIC_SAMPLE, ROUND]
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Sensors:
[]
Actors:
[UsedActor [U1, ULTRASONIC], UsedActor [, DISPLAY], UsedActor [U2, ULTRASONIC], UsedActor [U3, ULTRASONIC]]
Methods:
[GET_ULTARSONIC_SAMPLE, ROUND]
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#define _GNU_SOURCE

#include "MicroBit.h"
#include "NEPODefs.h"
#include <list>
#include <array>
#include <stdlib.h>
MicroBit _uBit;


double getUltarsonicSample(double factor, MicroBitPin trigPin, MicroBitPin echoPin);

double ___abstand;

int main()
{
_uBit.init();
___abstand = 0;

while ( true ) {
___abstand = getUltarsonicSample(58, _uBit.io.P8, _uBit.io.P2);
_uBit.display.scroll(ManagedString(round(___abstand)));
_uBit.sleep(1000);
_uBit.sleep(_ITERATION_SLEEP_TIMEOUT);
}
___abstand = getUltarsonicSample(58, _uBit.io.P9, _uBit.io.P7);
___abstand = (_uBit.io.P2.readPulseHigh() * 0.017);
release_fiber();
}

double getUltarsonicSample(double factor, MicroBitPin trigPin, MicroBitPin echoPin) {
trigPin.setDigitalValue(1);
_uBit.sleep(25);
trigPin.setDigitalValue(0);

return ((double)_uBit.io.P2.readPulseHigh()) / factor;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#define _GNU_SOURCE

#include "MicroBit.h"
#include "NEPODefs.h"
#include <list>
#include <array>
#include <stdlib.h>
MicroBit _uBit;


double getUltarsonicSample(double factor, MicroBitPin trigPin, MicroBitPin echoPin);

double ___abstand;

int main()
{
_uBit.init();
___abstand = 0;

while ( true ) {
___abstand = getUltarsonicSample(58, _uBit.io.P8, _uBit.io.P2);
_uBit.display.scroll(ManagedString(round(___abstand)));
_uBit.sleep(1000);
_uBit.sleep(_ITERATION_SLEEP_TIMEOUT);
}
___abstand = getUltarsonicSample(58, _uBit.io.P9, _uBit.io.P7);
___abstand = (_uBit.io.P2.readPulseHigh() * 0.017);
release_fiber();
}

double getUltarsonicSample(double factor, MicroBitPin trigPin, MicroBitPin echoPin) {
trigPin.setDigitalValue(1);
_uBit.sleep(25);
trigPin.setDigitalValue(0);

return ((double)_uBit.io.P2.readPulseHigh()) / factor;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#define _GNU_SOURCE

#include "MicroBit.h"
#include "NEPODefs.h"
#include <list>
#include <array>
#include <stdlib.h>
MicroBit _uBit;


double getUltarsonicSample(double factor, MicroBitPin trigPin, MicroBitPin echoPin);

double ___abstand;

int main()
{
_uBit.init();
___abstand = 0;

while ( true ) {
___abstand = getUltarsonicSample(58, _uBit.io.P8, _uBit.io.P2);
_uBit.display.scroll(ManagedString(round(___abstand)));
_uBit.sleep(1000);
_uBit.sleep(_ITERATION_SLEEP_TIMEOUT);
}
___abstand = getUltarsonicSample(58, _uBit.io.P9, _uBit.io.P7);
___abstand = (_uBit.io.P2.readPulseHigh() * 0.017);
release_fiber();
}

double getUltarsonicSample(double factor, MicroBitPin trigPin, MicroBitPin echoPin) {
trigPin.setDigitalValue(1);
_uBit.sleep(25);
trigPin.setDigitalValue(0);

return ((double)_uBit.io.P2.readPulseHigh()) / factor;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<export xmlns="http://de.fhg.iais.roberta.blockly"><program><block_set xmlns="http://de.fhg.iais.roberta.blockly" robottype="calliope" xmlversion="3.1" description="" tags=""><instance x="384" y="50"><block type="robControls_start" id="rLis%0[zgo({imw{KpU4" intask="true" deletable="false"><mutation declare="true"></mutation><field name="DEBUG"></field><statement name="ST"><block type="robGlobalVariables_declare" id="x{{e`,XOhY/Hs%C0Kwzm" intask="true" deletable="false" movable="false"><mutation next="false" declaration_type="Number"></mutation><field name="VAR">abstand</field><field name="TYPE">Number</field><value name="VALUE"><block type="math_number" id="p8+G{3~z.e`DVHt)VEyo" intask="true"><field name="NUM">0</field></block></value></block></statement></block><block type="robControls_loopForever" id="JDZ{gETgi2ZRBxwuila0" intask="true"><statement name="DO"><block type="variables_set" id="bB5u+:dMsdXKAM_aO~95" intask="true"><mutation datatype="Number"></mutation><field name="VAR">abstand</field><value name="VALUE"><block type="robSensors_ultrasonic_getSample" id="#oo1?lDL=y)@SwT/1QG)" intask="true"><mutation mode="DISTANCE"></mutation><field name="MODE">DISTANCE</field><field name="SENSORPORT">U1</field><field name="SLOT"></field></block></value></block><block type="mbedActions_display_text" id="KhbK)x0!T[[~g]|XDQS8" intask="true"><field name="TYPE">TEXT</field><value name="OUT"><block type="math_round" id="q-[7IZo*H5s|zO0Ee9=^" intask="true"><field name="OP">ROUND</field><value name="NUM"><block type="variables_get" id="Ux:n789b@|^XZ2f;E=,A" intask="true"><mutation datatype="Number"></mutation><field name="VAR">abstand</field></block></value></block></value></block><block type="robControls_wait_time" id="?0b97zM.tr3p@ot,!d]T" intask="true"><value name="WAIT"><block type="math_number" id="_r]@(Jaa,rk%AM]O;?`D" intask="true"><field name="NUM">1000</field></block></value></block></statement></block><block type="variables_set" id="=Y_7XQ2~*U]p:[AV!{}t" intask="true"><mutation datatype="Number"></mutation><field name="VAR">abstand</field><value name="VALUE"><block type="robSensors_ultrasonic_getSample" id="wjn(WF!B)!j,_[ko;7G~" intask="true"><mutation mode="DISTANCE"></mutation><field name="MODE">DISTANCE</field><field name="SENSORPORT">U2</field><field name="SLOT"></field></block></value></block><block type="variables_set" id="h7~fQcv_SP%x`v(GEU|Z" intask="true"><mutation datatype="Number"></mutation><field name="VAR">abstand</field><value name="VALUE"><block type="robSensors_ultrasonic_getSample" id="c(|pt*+PfApbD[JnDI-3" intask="true"><mutation mode="DISTANCE"></mutation><field name="MODE">DISTANCE</field><field name="SENSORPORT">U3</field><field name="SLOT"></field></block></value></block></instance></block_set></program><config><block_set xmlns="http://de.fhg.iais.roberta.blockly" robottype="calliope" xmlversion="3.1" description="" tags=""><instance x="1104" y="40"><block type="robConf_ultrasonic_hcsr04" id="cI*AYI1F5Z_Zx;TE:Z3W" intask="true"><field name="NAME">U1</field><field name="FACTOR">58</field><field name="TRIG">C17</field><field name="ECHO">C16</field></block></instance><instance x="-34" y="120"><block type="robConf_key" id="~wk*JZQvB.fj=I`N#NWp" intask="true" deletable="false"><field name="NAME">B</field><field name="PIN1">B</field></block></instance><instance x="197" y="162"><block type="robConf_sound" id="e:4V0FcDx%9,.7xO,Ns@" intask="true" deletable="false"><field name="NAME">_S</field></block></instance><instance x="197" y="190"><block type="robConf_light" id="9Ktt(7_4+XmKC0]5Zha?" intask="true" deletable="false"><field name="NAME">_L</field></block></instance><instance x="80" y="211"><block type="robConf_gyro" id="lIT?C5y|(7FWCQIUn~pc" intask="true" deletable="false"><field name="NAME">_G</field></block></instance><instance x="80" y="239"><block type="robConf_compass" id="O%Oi0Tq`hGEvrgHGPYY=" intask="true" deletable="false"><field name="NAME">_C</field></block></instance><instance x="250" y="250"><block type="robConf_robot" id="robot" intask="false" deletable="false"><field name="ROBOT">undefined</field></block></instance><instance x="1104" y="209"><block type="robConf_ultrasonic_hcsr04" id="E%{`vd#|{ke5gcGBmcs3" intask="true"><field name="NAME">U2</field><field name="FACTOR">58</field><field name="TRIG">C10</field><field name="ECHO">C11</field></block></instance><instance x="-34" y="270"><block type="robConf_key" id="Kbp:=x@[email protected]~NH|1|e" intask="true" deletable="false"><field name="NAME">A</field><field name="PIN1">A</field></block></instance><instance x="80" y="268"><block type="robConf_accelerometer" id="#(ufvG,s^FcqI,aFn/A{" intask="true" deletable="false"><field name="NAME">_A</field></block></instance><instance x="80" y="378"><block type="robConf_temperature" id="0y].dnS)P)~Jjzeu3/0C" intask="true" deletable="false"><field name="NAME">_T</field></block></instance><instance x="-34" y="422"><block type="robConf_rgbled" id="lgi%C3,J!smR:eP0aal_" intask="true" deletable="false"><field name="NAME">_R</field></block></instance><instance x="1100" y="385"><block type="robConf_ultrasonic" id="?d=~1mSy0`aasZwfLO2X" intask="true"><field name="NAME">U3</field><field name="PIN1">1</field></block></instance><instance x="-34" y="450"><block type="robConf_buzzer" id="}%d2_68IJd*7Oy{qrMR," intask="true" deletable="false"><field name="NAME">_B</field></block></instance></block_set></config></export>
Loading