From d47bc36cf97d1960e7655a179abe1bbb179c6f55 Mon Sep 17 00:00:00 2001 From: Beate Jost Date: Wed, 14 Aug 2024 17:23:56 +0200 Subject: [PATCH] Issue #1656: adopt simulation to new camera configuration --- .../fhg/iais/roberta/components/Project.java | 55 +++++++---- .../simulationLogic/robot.sensors.js | 2 +- .../simulation/simulationLogic/robot.txt4.js | 2 +- .../simulationLogic/robot.sensors.ts | 61 +++++++----- .../simulation/simulationLogic/robot.txt4.ts | 97 +++++++++++-------- .../resources/txt4/configuration.default.xml | 16 ++- 6 files changed, 137 insertions(+), 96 deletions(-) diff --git a/OpenRobertaRobot/src/main/java/de/fhg/iais/roberta/components/Project.java b/OpenRobertaRobot/src/main/java/de/fhg/iais/roberta/components/Project.java index 23b7a389d6..e9b752fdc8 100644 --- a/OpenRobertaRobot/src/main/java/de/fhg/iais/roberta/components/Project.java +++ b/OpenRobertaRobot/src/main/java/de/fhg/iais/roberta/components/Project.java @@ -1,8 +1,10 @@ package de.fhg.iais.roberta.components; import java.util.ArrayList; +import java.util.Collection; import java.util.Collections; import java.util.HashMap; +import java.util.LinkedHashMap; import java.util.List; import java.util.Map; @@ -19,11 +21,11 @@ import de.fhg.iais.roberta.bean.IProjectBean; import de.fhg.iais.roberta.bean.NNBean; import de.fhg.iais.roberta.blockly.generated.BlockSet; -import de.fhg.iais.roberta.blockly.generated.Instance; import de.fhg.iais.roberta.factory.RobotFactory; import de.fhg.iais.roberta.inter.mode.action.ILanguage; import de.fhg.iais.roberta.robotCommunication.RobotCommunicator; import de.fhg.iais.roberta.syntax.configuration.ConfigurationComponent; +import de.fhg.iais.roberta.syntax.configuration.ConfigurationComponentNode; import de.fhg.iais.roberta.transformer.Jaxb2ConfigurationAst; import de.fhg.iais.roberta.transformer.Jaxb2ProgramAst; import de.fhg.iais.roberta.typecheck.NepoInfo; @@ -328,35 +330,46 @@ public Builder setConfigurationXml(String configurationXml) { public Builder setConfigurationAst(ConfigurationAst configurationAst) { this.project.configuration = configurationAst; this.project.configurationJSON = new JSONObject(); - JSONObject sensorsJSON = new JSONObject(); - JSONObject actuatorsJSON = new JSONObject(); try { this.project.configurationJSON.put("TRACKWIDTH", configurationAst.getTrackWidth()); this.project.configurationJSON.put("WHEELDIAMETER", configurationAst.getWheelDiameter()); - for ( ConfigurationComponent sensor : configurationAst.getSensors() ) { - JSONObject propJSON = new JSONObject(); - propJSON.put("TYPE", sensor.componentType); - for ( String prop : sensor.getComponentProperties().keySet() ) { - propJSON.put(prop, sensor.getComponentProperties().get(prop)); - } - sensorsJSON.put(sensor.userDefinedPortName, propJSON); - } - for ( ConfigurationComponent actuator : configurationAst.getActors() ) { - JSONObject propJSON = new JSONObject(); - propJSON.put("TYPE", actuator.componentType); - for ( String prop : actuator.getComponentProperties().keySet() ) { - propJSON.put(prop, actuator.getComponentProperties().get(prop)); - } - actuatorsJSON.put(actuator.userDefinedPortName, propJSON); - } - this.project.configurationJSON.put("SENSORS", sensorsJSON); - this.project.configurationJSON.put("ACTUATORS", actuatorsJSON); + this.project.configurationJSON.put("SENSORS", configurationAst2JSON(configurationAst.getSensors())); + this.project.configurationJSON.put("ACTUATORS", configurationAst2JSON(configurationAst.getActors())); } catch ( JSONException e ) { throw new DbcException("exception when generating the configuration ", e); } return this; } + private static JSONObject configurationAst2JSON(Collection configurationAst) { + JSONObject compJSON = new JSONObject(); + for ( ConfigurationComponent component : configurationAst ) { + JSONObject propJSON = new JSONObject(); + propJSON.put("TYPE", component.componentType); + for ( String prop : component.getComponentProperties().keySet() ) { + propJSON.put(prop, component.getComponentProperties().get(prop)); + } + if ( component instanceof ConfigurationComponentNode ) { + LinkedHashMap> subComponentLists = component.getSubComponents(); + for ( String subComponentList : subComponentLists.keySet() ) { + JSONObject sub = new JSONObject(); + List subList = subComponentLists.get(subComponentList); + for ( ConfigurationComponent subComp : subList ) { + JSONObject subPropJSON = new JSONObject(); + subPropJSON.put("TYPE", subComp.componentType); + for ( String prop : subComp.getComponentProperties().keySet() ) { + subPropJSON.put(prop, subComp.getComponentProperties().get(prop)); + } + sub.put(subComp.userDefinedPortName, subPropJSON); + } + propJSON.put("SUBCOMPONENTS", sub); + } + } + compJSON.put(component.userDefinedPortName, propJSON); + } + return compJSON; + } + public Builder setProgramAst(ProgramAst programAst) { this.project.program = programAst; return this; diff --git a/OpenRobertaServer/staticResources/js/app/simulation/simulationLogic/robot.sensors.js b/OpenRobertaServer/staticResources/js/app/simulation/simulationLogic/robot.sensors.js index d622b2f307..2e55507d62 100644 --- a/OpenRobertaServer/staticResources/js/app/simulation/simulationLogic/robot.sensors.js +++ b/OpenRobertaServer/staticResources/js/app/simulation/simulationLogic/robot.sensors.js @@ -1,3 +1,3 @@ -var __extends=this&&this.__extends||function(){var t=function(i,e){return t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,i){t.__proto__=i}||function(t,i){for(var e in i)Object.prototype.hasOwnProperty.call(i,e)&&(t[e]=i[e])},t(i,e)};return function(i,e){if("function"!=typeof e&&null!==e)throw new TypeError("Class extends value "+String(e)+" is not a constructor or null");function s(){this.constructor=i}t(i,e),i.prototype=null===e?Object.create(e):(s.prototype=e.prototype,new s)}}();define(["require","exports","robot.base.mobile","interpreter.constants","simulation.math","util.roberta","robot.actuators","simulation.objects","blockly","volume-meter","simulation.roberta"],(function(t,i,e,s,r,a,n,h,o,l,d){Object.defineProperty(i,"__esModule",{value:!0}),i.Txt4CameraSensor=i.CameraSensor=i.OdometrySensor=i.SoundSensorBoolean=i.SoundSensor=i.VolumeMeterSensor=i.TemperatureSensor=i.Rob3rtaInfraredSensor=i.CalliopeLightSensor=i.CompassSensor=i.GestureSensor=i.MbotButton=i.MicrobitPins=i.Pins=i.TouchKeys=i.EV3Keys=i.Keys=i.GyroSensorExt=i.GyroSensor=i.OpticalSensor=i.LightSensor=i.NXTColorSensor=i.ColorSensor=i.RobotinoTouchSensor=i.TapSensor=i.TouchSensor=i.EdisonInfraredSensors=i.RobotinoInfraredSensors=i.ThymioInfraredSensors=i.InfraredSensors=i.MbotInfraredSensor=i.Txt4InfraredSensors=i.ThymioLineSensors=i.LineSensor=i.EdisonInfraredSensor=i.ThymioInfraredSensor=i.InfraredSensor=i.UltrasonicSensor=i.DistanceSensor=i.Timer=void 0;var p=function(){function t(t){this.time=[],this.labelPriority=14;for(var i=0;i"+(a.round(this.time[i],1)+" s")+""}return t},t.prototype.reset=function(){for(var t in this.time)this.time[t]=0},t.prototype.updateAction=function(t,i,e){if(e){for(var s in this.time)this.time[s]+=i;var r=t.interpreter.getRobotBehaviour().getActionState("timer",!0);if(r)for(var a=1;a<=this.time.length;a++)r[a]&&"reset"==r[a]&&(this.time[a-1]=0)}},t.prototype.updateSensor=function(t,i,e,s,r,a,n){s.timer=s.timer||[];for(var h=0;h"+a.round(this.distance/3,0)+" cm"},i.prototype.updateSensor=function(i,e,s,r,a,n,h){t.prototype.updateSensor.call(this,i,e,s,r,a,n,h);var o=this.distance/3;r.ultrasonic=r.ultrasonic||{},r.ultrasonic[this.port]={},o"+a.round(this.distance/3,0)+" cm":"
"+a.round(this.distance/3,0)+" cm
"},i.prototype.updateSensor=function(i,e,s,r,a,n,h){t.prototype.updateSensor.call(this,i,e,s,r,a,n,h);var o=this.distance/3;r.infrared=r.infrared||{},r.infrared[this.port]={},this.relative?o"+a.round(t,0)+" %"},i.prototype.updateSensor=function(i,e,s,r,n,h,o){t.prototype.updateSensor.call(this,i,e,s,r,n,h,o);var l=this.distance/3;r.infrared=r.infrared||{},r.infrared.distance=r.infrared.distance?r.infrared.distance:{},l"+(this.distance/3"},i.prototype.updateSensor=function(i,e,s,r,a,n,h){t.prototype.updateSensor.call(this,i,e,s,r,a,n,h);var o=this.distance/3;r.infrared=r.infrared||{},r.infrared[this.port]=r.infrared[this.port]?r.infrared[this.port]:{},r.infrared[this.port].obstacle=o
"+this.line+"
"+this.light+"
"},t.prototype.updateSensor=function(t,i,e,s,n,h,o){var l=e,d={rx:0,ry:0,x:this.x,y:this.y};r.transform(l.pose,d),s.infrared=s.infrared||{};var p=this;!function(t,i){for(var e=0,r=0,o=0,l=n.getImageData(Math.round(i.x-p.radius),Math.round(i.y-p.radius),p.diameter,p.diameter),d=h.getImageData(Math.round(i.x-p.radius),Math.round(i.y-p.radius),p.diameter,p.diameter),u=0;u<=l.data.length;u+=4)if(255===d.data[u+3])for(var c=u;c=0&&(e+=l.data[u],r+=l.data[u+1],o+=l.data[u+2]);var y=l.data.length/4-4,b=((e/=y)+(r/=y)+(o/=y))/3/2.55;p.line=b<50,p.light=a.round(b,0),s.infrared.light=s.infrared.light?s.infrared.light:{},s.infrared.light=p.light,s.infrared.line=s.infrared.line?s.infrared.line:{},s.infrared.line=p.line}(0,{x:d.rx,y:d.ry})},t}();i.LineSensor=x;var g=function(){function t(t){this.drawPriority=4,this.left=new x({x:t.x,y:t.y-3},3),this.right=new x({x:t.x,y:t.y+3},3)}return t.prototype.getLabel=function(){return"
"+this.left.line+"
"+this.left.light+"
"+this.right.line+"
"+this.right.light+"
"},t.prototype.updateSensor=function(t,i,e,s,r,a,n,h){this.left.updateSensor(t,i,e,s,r,a,n),this.right.updateSensor(t,i,e,s,r,a,n),this.left.line=this.left.line?1:0,this.right.line=this.right.line?1:0,s.infrared.light={},s.infrared.light.left=this.left.light,s.infrared.light.right=this.right.light,s.infrared.line={},s.infrared.line.left=this.left.line,s.infrared.line.right=this.right.line},t.prototype.draw=function(t,i){this.left.draw(t,i),this.right.draw(t,i)},t}();i.ThymioLineSensors=g;var v=function(){function t(t,i){this.drawPriority=4,this.port=t,this.left=new x({x:i.x,y:i.y-3},3),this.right=new x({x:i.x,y:i.y+3},3)}return t.prototype.getLabel=function(){return"
"+this.left.line+"
"+this.right.line+"
"},t.prototype.updateSensor=function(t,i,e,s,r,a,n,h){this.left.updateSensor(t,i,e,s,r,a,n),this.right.updateSensor(t,i,e,s,r,a,n),s.infrared={},s.infrared[this.port]={},s.infrared[this.port].left=this.left.line,s.infrared[this.port].right=this.right.line},t.prototype.draw=function(t,i){this.left.draw(t,i),this.right.draw(t,i)},t}();i.Txt4InfraredSensors=v;var M=function(){function t(t,i){this.right={value:0},this.left={value:0},this.drawPriority=4,this.rx=0,this.ry=0,this.dx=5,this.dy=8,this.r=1.5,this.x=i.x,this.y=i.y,this.port=t,this.labelPriority=Number(this.port.replace("ORT_",""))}return t.prototype.draw=function(t,i){t.save(),t.fillStyle="#333",t.rect(this.x,this.y-this.dy/2,this.dx,this.dy),t.fill(),t.beginPath(),t.lineWidth=.1,t.arc(this.x+this.dx/2,this.y-this.dy/4,this.r,0,2*Math.PI),t.fillStyle=this.left.value?"black":"white",t.fill(),t.strokeStyle="black",t.stroke(),t.lineWidth=.5,t.beginPath(),t.lineWidth=.1,t.arc(this.x+this.dx/2,this.y+this.dy/4,this.r,0,2*Math.PI),t.fillStyle=this.right.value?"black":"white",t.fill(),t.strokeStyle="black",t.stroke(),t.beginPath(),t.fillStyle="#555555",t.fillText(String(this.port.replace("ORT_","")),this.x+2,this.y+12),t.restore()},t.prototype.getLabel=function(){return"
"+this.left.value+"
"+this.right.value+"
"},t.prototype.updateSensor=function(t,i,e,s,a,n,h){var o=e,l={rx:0,ry:0,x:this.x+this.dx/2,y:this.y-this.dy/4},d={rx:0,ry:0,x:this.x+this.dx/2,y:this.y+this.dy/4};r.transform(o.pose,l),r.transform(o.pose,d),s.infrared=s.infrared||{},s.infrared[this.port]={};var p=this;function u(t,i){for(var e=0,r=0,h=0,o=a.getImageData(Math.round(i.x-3),Math.round(i.y-3),6,6),l=n.getImageData(Math.round(i.x-3),Math.round(i.y-3),6,6),d=0;d<=o.data.length;d+=4)if(255===l.data[d+3])for(var u=d;u";return this.infraredSensorArray.forEach((function(i){return t+=i.getLabel()})),t},t.prototype.updateSensor=function(t,i,e,s,r,a,n){this.infraredSensorArray.forEach((function(h){return h.updateSensor(t,i,e,s,r,a,n)}))},t}();i.InfraredSensors=S;var m=function(t){function i(){return null!==t&&t.apply(this,arguments)||this}return __extends(i,t),i.prototype.configure=function(){this.infraredSensorArray[0]=new b("0",24*Math.cos(-Math.PI/4),24*Math.sin(-Math.PI/4),-Math.PI/4,14,o.Msg.FRONT_LEFT),this.infraredSensorArray[1]=new b("1",26*Math.cos(-Math.PI/8),26*Math.sin(-Math.PI/8),-Math.PI/8,14,o.Msg.FRONT_LEFT_MIDDLE),this.infraredSensorArray[2]=new b("2",26,0,0,14,o.Msg.FRONT_MIDDLE),this.infraredSensorArray[3]=new b("3",26*Math.cos(Math.PI/8),26*Math.sin(Math.PI/8),Math.PI/8,14,o.Msg.FRONT_RIGHT_MIDDLE),this.infraredSensorArray[4]=new b("4",24*Math.cos(Math.PI/4),24*Math.sin(Math.PI/4),Math.PI/4,14,o.Msg.FRONT_RIGHT),this.infraredSensorArray[5]=new b("5",-9,-13,Math.PI,14,o.Msg.BACK_LEFT),this.infraredSensorArray[6]=new b("6",-9,13,Math.PI,14,o.Msg.BACK_RIGHT)},i}(S);i.ThymioInfraredSensors=m;var I=function(t){function i(){return null!==t&&t.apply(this,arguments)||this}return __extends(i,t),i.prototype.configure=function(){this.infraredSensorArray[0]=new y("1",68*Math.cos(0),68*Math.sin(0),0,30,!1),this.infraredSensorArray[1]=new y("2",68*Math.cos(2*-Math.PI/9),68*Math.sin(2*-Math.PI/9),2*-Math.PI/9,30,!1),this.infraredSensorArray[2]=new y("3",68*Math.cos(4*-Math.PI/9),68*Math.sin(4*-Math.PI/9),4*-Math.PI/9,30,!1),this.infraredSensorArray[3]=new y("4",68*Math.cos(6*-Math.PI/9),68*Math.sin(6*-Math.PI/9),6*-Math.PI/9,30,!1),this.infraredSensorArray[4]=new y("5",68*Math.cos(8*-Math.PI/9),68*Math.sin(8*-Math.PI/9),8*-Math.PI/9,30,!1),this.infraredSensorArray[9]=new y("9",68*Math.cos(2*Math.PI/9),68*Math.sin(2*Math.PI/9),2*Math.PI/9,30,!1),this.infraredSensorArray[8]=new y("8",68*Math.cos(4*Math.PI/9),68*Math.sin(4*Math.PI/9),4*Math.PI/9,30,!1),this.infraredSensorArray[7]=new y("7",68*Math.cos(6*Math.PI/9),68*Math.sin(6*Math.PI/9),6*Math.PI/9,30,!1),this.infraredSensorArray[6]=new y("6",68*Math.cos(8*Math.PI/9),68*Math.sin(8*Math.PI/9),8*Math.PI/9,30,!1)},i}(S);i.RobotinoInfraredSensors=I;var B=function(t){function i(){return null!==t&&t.apply(this,arguments)||this}return __extends(i,t),i.prototype.configure=function(){this.infraredSensorArray[1]=new f("LEFT",17,-8,0,3,o.Msg.LEFT),this.infraredSensorArray[0]=new f("FRONT",18,0,0,3,o.Msg.SLOT_FRONT),this.infraredSensorArray[2]=new f("RIGHT",17,8,0,3,o.Msg.RIGHT)},i}(S);i.EdisonInfraredSensors=B;var E=function(){function t(t,i,e,s){this.color="#FF69B4",this.rx=0,this.ry=0,this.value=!1,this.drawPriority=4,this.port=t,this.labelPriority=Number(this.port.replace("ORT_","")),this.x=i,this.y=e,this.color=s||this.color}return t.prototype.draw=function(t,i){t.save(),t.shadowBlur=5,t.shadowColor="black",t.fillStyle=i.chassis.geom.color,this.value?t.fillStyle="red":t.fillStyle=i.chassis.geom.color,t.fillRect(i.chassis.frontLeft.x-3.5,i.chassis.frontLeft.y,3.5,-i.chassis.frontLeft.y+i.chassis.frontRight.y),t.restore()},t.prototype.getLabel=function(){return"
"+this.value+"
"},t.prototype.updateSensor=function(t,i,e,s,r,a,n){s.touch=s.touch||{},s.touch[this.port]=this.value=e.chassis.frontLeft.bumped||e.chassis.frontRight.bumped},t}();i.TouchSensor=E;var P=function(){function t(){}return t.prototype.updateSensor=function(t,i,e,s,r,a,n){s.touch=s.touch||{};var h=e.chassis.frontLeft.bumped||e.chassis.frontRight.bumped||e.chassis.backLeft.bumped||e.chassis.backRight.bumped;s.touch=h?1:0},t}();i.TapSensor=P;var _=function(){function t(){this.bumped=!1,this.drawPriority=4}return t.prototype.getLabel=function(){return"
"+this.bumped+"
"},t.prototype.updateSensor=function(t,i,e,s,r,a,n){s.touch=s.touch||{},s.touch=this.bumped=e.chassis.bumpedAngle.length>0},t}();i.RobotinoTouchSensor=_;var R=function(){function t(t,i,e,s,r,a){this.color="grey",this.colorValue="NONE",this.lightValue=0,this.rgb=[0,0,0],this.rx=0,this.ry=0,this.drawPriority=6,this.port=t,this.labelPriority=Number(this.port.replace("ORT_","")),this.x=i,this.y=e,this.theta=s,this.r=r,this.color=a||this.color}return t.prototype.draw=function(t,i){t.save(),t.beginPath(),t.arc(this.x,this.y,this.r,0,2*Math.PI),t.fillStyle=this.color,t.fill(),t.strokeStyle="black",t.stroke(),t.translate(this.x,this.y),t.beginPath(),t.fillStyle="#555555",t.fillText(this.port,-12,4),t.restore()},t.prototype.getLabel=function(){return"
 
"+a.round(this.lightValue,0)+" %
"},t.prototype.updateSensor=function(t,i,e,s,n,h){s.color=s.color||{},s.light=s.light||{},s.color[this.port]={},s.light[this.port]={},r.transform(e.pose,this);var o=0,l=0,d=0,p=Math.round(this.rx-3),u=Math.round(this.ry-3);try{for(var c=n.getImageData(p,u,6,6),y=h.getImageData(p,u,6,6),b=0;b<=c.data.length;b+=4)if(255===y.data[b+3])for(var f=b;f
"+a.round(this.lightValue,0)+" %
"},i}(R);i.LightSensor=O;var D=function(t){function i(i,e,s,r,a,n,h){var o=t.call(this,e.replace("DI","").toString(),s,r,a,n)||this;return o.name=i,o}return __extends(i,t),i.prototype.getLabel=function(){return"
"+this.light+"
"+!this.light+"
"},i.prototype.draw=function(t,i){t.save(),t.beginPath(),t.arc(this.x,this.y,this.r,0,2*Math.PI),t.fillStyle=this.color,t.fill(),t.strokeStyle="black",t.stroke(),t.translate(this.x,this.y),t.beginPath(),t.fillStyle="#555555",t.fillText(this.name,8,4),t.restore()},i.prototype.updateSensor=function(i,e,r,a,n,h){t.prototype.updateSensor.call(this,i,e,r,a,n,h),this.lightValue=this.lightValue>50?100:0,this.light=0!=this.lightValue,this.color=0==this.lightValue?"black":"white",a.optical=a.optical||{},a.optical[this.name]={},a.optical[this.name][s.OPENING]=this.light,a.optical[this.name][s.CLOSING]=!this.light},i}(O);i.OpticalSensor=D;var A=function(){function t(){this.angleValue=0,this.rateValue=0}return t.prototype.getLabel=function(){return"
"+a.round(this.angleValue,0)+" °
"},t.prototype.reset=function(){this.angleValue=0,this.rateValue=0},t.prototype.updateAction=function(t,i,e){},t.prototype.updateSensor=function(t,i,e,s,r,a,n){},t}();i.GyroSensor=A;var T=function(t){function i(i,e,s,r){var a=t.call(this)||this;return a.color="#000000",a.port=i,a.x=e,a.y=s,a.theta=r,a}return __extends(i,t),i.prototype.getLabel=function(){return"
"+a.round(this.angleValue,0)+" °
"},i.prototype.updateAction=function(t,i,e){var s=t.interpreter.getRobotBehaviour().getActionState("gyroReset",!1);s&&s[this.port]&&(t.interpreter.getRobotBehaviour().getActionState("gyroReset",!0),this.reset())},i.prototype.updateSensor=function(t,i,e,s,a,n,h){s.gyro=s.gyro||{},s.gyro[this.port]={},this.angleValue+=r.toDegree(e.thetaDiff),s.gyro[this.port].angle=this.angleValue,this.rateValue=i*r.toDegree(e.thetaDiff),s.gyro[this.port].rate=this.rateValue},i}(A);i.GyroSensorExt=T;var w=function(){function t(){this.keys={}}return t.prototype.getLabel=function(){return""},t}();i.Keys=w;var N=function(t){function i(i,e){var s=t.call(this)||this;for(var r in i)s.keys[i[r].name]=i[r];return s}return __extends(i,t),i.prototype.updateSensor=function(t,i,e,s,r,a,n){for(var h in s.buttons={},s.buttons.any=!1,s.buttons.Reset=!1,this.keys)s.buttons[h]=!0===this.keys[h].value,s.buttons.any=s.buttons.any||this.keys[h].value},i}(w);i.EV3Keys=N;var k=function(t){function i(i,e,s){var r=t.call(this)||this;for(var a in r.color2Keys={},r.$touchLayer=$("#robotLayer"),r.isDown=!1,r.id=e,r.$touchLayer=s||r.$touchLayer,i)r.keys[i[a].port]=i[a];return i.forEach((function(t){t.touchColors.forEach((function(i){r.color2Keys[i]=[t.port]}))})),r.addMouseEvents(e),r}return __extends(i,t),i.prototype.handleMouseDown=function(t){var i=this;t&&!t.startX&&a.extendMouseEvent(t,d.SimulationRoberta.Instance.scale,this.$touchLayer);var e=t;if(this.lastMousePosition={x:e.startX,y:e.startY},void 0!==this.uCtx){var s=this.uCtx.getImageData(this.lastMousePosition.x,this.lastMousePosition.y,1,1).data;this.lastMouseColor=a.RGBAToHexA([s[0],s[1],s[2],s[3]])}this.isDown=!0;var r=this.color2Keys[this.lastMouseColor];r&&r.length>0&&(this.$touchLayer.data("hovered",!0),this.$touchLayer.css("cursor","pointer"),t.stopImmediatePropagation(),r.forEach((function(t){i.keys[t].value=!0})))},i.prototype.handleMouseMove=function(t){t&&!t.startX&&a.extendMouseEvent(t,d.SimulationRoberta.Instance.scale,this.$touchLayer);var i=t;if(this.lastMousePosition={x:i.startX,y:i.startY},void 0!==this.uCtx){var e=this.uCtx.getImageData(this.lastMousePosition.x,this.lastMousePosition.y,1,1).data;this.lastMouseColor=a.RGBAToHexA([e[0],e[1],e[2],e[3]])}var s=this.color2Keys[this.lastMouseColor];s&&s.length>0&&(this.$touchLayer.data("hovered",!0),this.$touchLayer.css("cursor","pointer"),t.stopImmediatePropagation())},i.prototype.handleMouseOutUp=function(t){for(var i in this.keys)this.keys[i].value=!1;this.isDown=!1},i.prototype.updateSensor=function(t,i,e,s,r,a,n){for(var h in void 0===this.uCtx&&(this.uCtx=r),s.buttons={},this.keys)s.buttons[h]=!0===this.keys[h].value},i.prototype.addMouseEvents=function(t){this.$touchLayer.on("mousedown.R"+t+" touchstart.R"+t,this.handleMouseDown.bind(this)),this.$touchLayer.on("mousemove.R"+t+" touchmove.R"+t,this.handleMouseMove.bind(this)),this.$touchLayer.on("mouseup.R"+t+" touchend.R"+t+" mouseout.R"+t+" touchcancel.R"+t,this.handleMouseOutUp.bind(this))},i}(w);i.TouchKeys=k;var C=function(t){function i(i,e,s,r){var a=t.call(this,i,e)||this,n=$("#mbedButtons");return a.transP=s,a.groundP=r,i.forEach((function(t){if("TOUCH"!==t.type){var i=1023;n.append('"),"DIGITAL_PIN"===t.type&&(i=1),n.append(''),n.append('
'),j($("#sliderPin"+t.port),$("#rangePin"+t.port),a.keys[t.port],"typeValue",{min:0,max:i})}})),a}return __extends(i,t),i.prototype.draw=function(t,i){for(var e in this.keys){var s=this.keys[e];switch(s.type){case"TOUCH":s.value&&(t.fillStyle=s.color,t.beginPath(),t.arc(s.x,s.y,s.r,0,2*Math.PI),t.fill(),this.groundP&&(t.fillStyle="red",t.beginPath(),t.arc(this.groundP.x,this.groundP.y,25,0,2*Math.PI),t.fill()));break;case"DIGITAL_PIN":t.fillStyle=s.color,t.beginPath(),t.save();var r=s.x+this.transP.x,a=s.y+this.transP.y;t.translate(r,a),t.save(),t.rotate(Math.PI/2),t.font="bold 100px Roboto",t.fillText("< ",0,0),t.restore(),t.font="20px Courier",t.fillText("⊓",-16,16),t.fillText(s.typeValue,50,16),t.restore();break;case"ANALOG_PIN":t.fillStyle=s.color,t.beginPath(),t.save();r=s.x+this.transP.x,a=s.y+this.transP.y;t.translate(r,a),t.save(),t.rotate(Math.PI/2),t.font="bold 100px Roboto",t.fillText("< ",0,0),t.restore(),t.font="20px Courier",t.fillText("∿",-16,16),t.fillText(s.typeValue,50,16),t.restore()}}},i.prototype.updateSensor=function(t,i,e,s,r,a,n){for(var h in void 0===this.uCtx&&(this.uCtx=r),this.keys)s["pin"+h]={},s["pin"+h].pressed=!0===this.keys[h].value,s["pin"+h].analog=s["pin"+h].digital=this.keys[h].typeValue},i}(k);i.Pins=C;var U=function(t){function i(){return null!==t&&t.apply(this,arguments)||this}return __extends(i,t),i.prototype.draw=function(t,i){for(var e in this.keys){var s=this.keys[e];switch(s.type){case"TOUCH":s.value&&(t.fillStyle=s.color,t.beginPath(),t.fillStyle="green",t.beginPath(),t.fillRect(s.x,s.y,s.r,s.r),t.fill(),t.fillStyle="red",t.beginPath(),t.arc(this.groundP.x,this.groundP.y,36,0,2*Math.PI),t.fill());break;case"DIGITAL_PIN":t.fillStyle=s.color,t.beginPath(),t.save();var r=s.x+this.transP.x,a=s.y+this.transP.y;t.translate(r,a),t.save(),t.rotate(Math.PI/2),t.font="bold 100px Roboto",t.fillText("< ",0,0),t.restore(),t.font="20px Courier",t.fillText("⊓",-16,16),t.fillText(s.typeValue,50,16),t.restore();break;case"ANALOG_PIN":t.fillStyle=s.color,t.beginPath(),t.save();r=s.x+this.transP.x,a=s.y+this.transP.y;t.translate(r,a),t.save(),t.rotate(Math.PI/2),t.font="bold 100px Roboto",t.fillText("< ",0,0),t.restore(),t.font="20px Courier",t.fillText("∿",-16,16),t.fillText(s.typeValue,50,16),t.restore()}}},i}(C);i.MicrobitPins=U;var G=function(t){function i(i,e){return t.call(this,i,e,$("#brick"+e))||this}return __extends(i,t),i.prototype.handleMouseDown=function(t){var i=this;t&&!t.startX&&a.extendMouseEvent(t,1,this.$touchLayer);var e=t;this.lastMousePosition={x:e.startX,y:e.startY};var s=this.$touchLayer.get(0).getContext("2d").getImageData(this.lastMousePosition.x,this.lastMousePosition.y,1,1).data;this.lastMouseColor=a.RGBAToHexA([s[0],s[1],s[2],s[3]]),this.isDown=!0;var r=this.color2Keys[this.lastMouseColor];r&&r.length>0&&(this.$touchLayer.data("hovered",!0),this.$touchLayer.css("cursor","pointer"),t.stopImmediatePropagation(),r.forEach((function(t){i.keys[t].value=!0})))},i.prototype.handleMouseMove=function(t){t&&!t.startX&&a.extendMouseEvent(t,1,this.$touchLayer);var i=t;this.lastMousePosition={x:i.startX,y:i.startY};var e=this.color2Keys[this.lastMouseColor],s=this.$touchLayer.get(0).getContext("2d").getImageData(this.lastMousePosition.x,this.lastMousePosition.y,1,1).data;this.lastMouseColor=a.RGBAToHexA([s[0],s[1],s[2],s[3]]),e&&e.length>0?(this.$touchLayer.data("hovered",!0),this.$touchLayer.css("cursor","pointer"),t.stopImmediatePropagation()):this.$touchLayer.data().hovered?this.$touchLayer.data("hovered",!1):this.$touchLayer.css("cursor","move")},i.prototype.updateSensor=function(t,i,e,s,r,a,n){for(var h in s.buttons={},this.keys)s.buttons[h]=!0===this.keys[h].value},i}(k);i.MbotButton=G;var F=function(){function t(){this.gesture={up:!0},this.labelPriority=10,$("#mbedButtons").append('");var t=this;$("#mbedButtons>.simbtn").on("click",(function(i){var e=$(this);$("#mbedButtons>.simbtn").each((function(){this.id==e[0].id?$(this).addClass("active"):$(this).removeClass("active")})),t.gesture={},t.gesture[i.currentTarget.id]=!0}))}return t.prototype.getLabel=function(){return"
"+o.Msg["SENSOR_GESTURE_"+Object.getOwnPropertyNames(this.gesture)[0].toUpperCase()]+"
"},t.prototype.updateSensor=function(t,i,e,s,r,a,n){s.gesture={};var h=Object.getOwnPropertyNames(this.gesture)[0];s.gesture[h]=this.gesture[h]},t}();i.GestureSensor=F;var V=function(){function t(){this.degree=0,this.labelPriority=11,$("#mbedButtons").append('
'),j($("#sliderCompass"),$("#rangeCompass"),this,"degree",{min:0,max:360})}return t.prototype.getLabel=function(){return"
"+this.degree+" °
"},t.prototype.updateSensor=function(t,i,e,s,r,a,n){s.compass={},s.compass.angle=this.degree},t}();i.CompassSensor=V;var H=function(){function t(t){this.dx=60,this.dy=60,this.lightLevel=0,this.x=342,this.y=546,this.labelPriority=12,t&&(this.x=t.x,this.y=t.y,this.dx=t.w,this.dy=t.h),$("#mbedButtons").append('
'),j($("#sliderLight"),$("#rangeLight"),this,"lightLevel",{min:0,max:100})}return t.prototype.draw=function(t,i){t.save(),t.beginPath(),t.fillStyle="#ffffff",t.globalAlpha=this.lightLevel/500,t.rect(this.x-this.dx/2,this.y+this.dy/2,5*this.dx,-5*this.dy),t.fill(),t.globalAlpha=1,t.restore()},t.prototype.getLabel=function(){return"
"+this.lightLevel+" %
"},t.prototype.updateSensor=function(t,i,e,s,r,a,n){s.light={},s.light.ambientlight=this.lightLevel},t}();i.CalliopeLightSensor=H;var X=function(){function t(){this.dx=60,this.dy=60,this.lightLevel=0,this.x=342,this.y=546,this.labelPriority=12,$("#mbedButtons").append('
'),j($("#sliderLight"),$("#rangeLight"),this,"lightLevel",{min:0,max:1023})}return t.prototype.getLabel=function(){return"
"+this.lightLevel+"
"},t.prototype.updateSensor=function(t,i,e,s,r,a,n){s.light={},s.light.ambientlight=this.lightLevel,s.light.reflected=this.lightLevel},t}();i.Rob3rtaInfraredSensor=X;var K=function(){function t(){this.degree=20,this.labelPriority=13,$("#mbedButtons").append('
'),j($("#sliderTemperature"),$("#rangeTemperature"),this,"degree",{min:-15,max:75})}return t.prototype.getLabel=function(){return"
"+this.degree+" °
"},t.prototype.updateSensor=function(t,i,e,s,r,a,n){s.temperature={},s.temperature.value=this.degree},t}();i.TemperatureSensor=K;var q=function(){function t(t){this.labelPriority=16,this.volume=0,void 0===window.navigator.mediaDevices&&(window.navigator.mediaDevices={}),this.webAudio=t.webAudio,window.navigator.mediaDevices.getUserMedia=navigator.mediaDevices.getUserMedia||navigator.webkitGetUserMedia||navigator.mozGetUserMedia;var i=this;try{navigator.mediaDevices.getUserMedia({audio:{mandatory:{googEchoCancellation:"false",googAutoGainControl:"false",googNoiseSuppression:"false",googHighpassFilter:"false"},optional:[]}}).then((function(t){var e=i.webAudio.context.createMediaStreamSource(t);i.sound=l.createAudioMeter(i.webAudio.context),e.connect(i.sound)}),(function(){console.log("Sorry, but there is no microphone available on your system")}))}catch(t){console.log("Sorry, but there is no microphone available on your system")}}return t.prototype.getLabel=function(){return"
"+a.round(this.volume,0)+" %
"},t.prototype.updateSensor=function(t,i,e,s,r,n,h){this.volume=this.sound?a.round(100*this.sound.volume,0):0,s.sound={},s.sound.volume=this.volume},t}();i.VolumeMeterSensor=q;var Y=function(t){function i(i,e){var s=t.call(this,i)||this;return s.theta=0,s.x=0,s.y=0,s.port=e,s.labelPriority=Number(s.port.replace("ORT_","")),s}return __extends(i,t),i.prototype.getLabel=function(){return"
"+a.round(this.volume,0)+" %
"},i.prototype.updateSensor=function(t,i,e,s,r,n,h){this.volume=this.sound?a.round(100*this.sound.volume,0):0,s.sound={},s.sound[this.port]={},s.sound[this.port].volume=this.volume},i}(q);i.SoundSensor=Y;var W=function(t){function i(){return null!==t&&t.apply(this,arguments)||this}return __extends(i,t),i.prototype.getLabel=function(){return"
"+(this.volume>25?"true":"false")+"
"},i.prototype.updateSensor=function(i,e,s,r,a,n,h){t.prototype.updateSensor.call(this,i,e,s,r,a,n,h),r.sound.volume=this.volume>25},i}(q);function j(t,i,e,s,r){t.on("mousedown touchstart",(function(t){t.stopPropagation()})),t.on("input change",(function(r){r.preventDefault(),i.val(t.val()),e[s]=Number(t.val()),r.stopPropagation()})),i.on("change",(function(a){a.preventDefault();var n=Number(i.val());i.valid()?(nr.max&&(n=r.max),i.val(n),t.val(n),e[s]=n):i.val(t.val()),a.stopPropagation()})),i.val(e[s]),t.val(e[s]),$("#mbed-form").validate(),i.rules("add",{messages:{required:!1,number:!1}})}i.SoundSensorBoolean=W;var Q=function(){function t(){this.x=0,this.y=0,this.theta=0,this.labelPriority=7}return t.prototype.getLabel=function(){var t="
";return t+="
"+a.round(this.x,1)+" cm
",t+="
"+a.round(this.y,1)+" cm
",t+="
"+a.round(this.theta,0)+" °
"},t.prototype.reset=function(){this.x=0,this.y=0,this.theta=0},t.prototype.updateSensor=function(t,i,e,a,n,h,o){a.odometry=a.odometry||{},this.theta+=r.toDegree(e.thetaDiff),a.odometry[s.THETA]=this.theta,this.x+=e.chassis.xDiff/3,a.odometry[s.X]=this.x,this.y+=e.chassis.yDiff/3,a.odometry[s.Y]=this.y},t.prototype.updateAction=function(t,i,e){if(e){var r=t.interpreter.getRobotBehaviour().getActionState("odometry",!0);if(r&&r.reset)switch(r.reset){case s.X:this.x=0;break;case s.Y:this.y=0;break;case s.THETA:this.theta=0;break;case"all":this.reset()}}},t}();i.OdometrySensor=Q;var z=function(){function t(t,i){this.MAX_MARKER_DIST_SQR=202500,this.MAX_CAM_Y=Math.sqrt(this.MAX_MARKER_DIST_SQR),this.MAX_BLOB_DIST_SQR=this.MAX_MARKER_DIST_SQR,this.LINE_RADIUS=60,this.markerEnabled=!0,this.lineEnabled=!0,this.colorEnabled=!0,this.AOV=2*Math.PI/5,this.listOfMarkersFound=[],this.bB={x:0,y:0,w:0,h:0},this.labelPriority=8,this.THRESHOLD=126,this.drawPriority=1,this.x=t.x,this.y=t.y,this.theta=t.theta,this.AOV=i}return t.prototype.updateAction=function(t,i,e){if(e){var s=t.interpreter.getRobotBehaviour().getActionState("colourBlob",!0);s&&(this.colourBlob=s)}this.colourBlob={minHue:0,maxHue:240,minSat:90,maxSat:110,minVal:90,maxVal:110}},t.prototype.draw=function(t,i){t.save(),t.beginPath(),t.strokeStyle="#0000ff",t.beginPath(),t.arc(this.x,this.y,this.MAX_CAM_Y,Math.PI/5,-Math.PI/5,!0),t.arc(this.x,this.y,this.LINE_RADIUS,-Math.PI/5,+Math.PI/5,!1),t.closePath(),t.stroke(),t.restore()},t.prototype.getLabel=function(){var t="";if(this.lineEnabled&&(t+="
"+a.round(this.line,2)+"
"),this.markerEnabled){t+="
";for(var i=0;i[",t+=a.round(e.xDist,0),t+=", ",t+=a.round(e.yDist,0),t+=", ",t+=a.round(e.zDist,0),t+="] cm"}}return t},t.prototype.reset=function(){},t.prototype.updateSensor=function(t,i,a,n,h,o,l,d){var p=this,u=a;r.transform(u.pose,this);var c=new e.Pose(this.rx,this.ry,this.theta),y=(a.pose.theta-this.AOV/2+2*Math.PI)%(2*Math.PI),b=(a.pose.theta+this.AOV/2+2*Math.PI)%(2*Math.PI);if(this.markerEnabled){this.listOfMarkersFound=[],d.filter((function(t){if(t.sqrDist=r.getDistance(c,t),t.sqrDist<=p.MAX_MARKER_DIST_SQR){for(var i=[{x:t.x-c.x,y:t.y-c.y},{x:t.x+t.w-c.x,y:t.y-c.y},{x:t.x+t.w-c.x,y:t.y+t.h-c.y},{x:t.x-c.x,y:t.y+t.h-c.y}],e=!0,s=0;sy&&ab&&(a>y||ae&&(e+=2*Math.PI,im)if(x.x>0){this.bB.x=Math.min(x.x,g.x)+this.rx,this.bB.y=Math.min(x.y,g.y)+this.ry,this.bB.w=Math.max(Math.max(x.x,g.x),this.LINE_RADIUS)+this.rx-this.bB.x+1,this.bB.h=-this.bB.y+Math.max(Math.max(x.y,g.y))+this.ry+1,this.constrainBB(h);var B=this.bB&&h.getImageData(this.bB.x,this.bB.y,this.bB.w,this.bB.h),E=this.bB&&o.getImageData(this.bB.x,this.bB.y,this.bB.w,this.bB.h);if(B)for(f=0;f0;f--){var L;P=this.LINE_RADIUS*this.LINE_RADIUS-(f+this.bB.y-this.ry)*(f+this.bB.y-this.ry),_=4*((L=Math.round(-Math.sqrt(P)-(this.bB.x-this.rx)))+f*B.width)-4;if((A=(D=this.getPixelData(E,_,B,I)).redPix)!==(I=D.redPixOld)){(R=Math.atan2(f+this.bB.y-this.ry,L+this.bB.x-this.rx))<=0&&(R+=2*Math.PI),v<=0&&(v+=2*Math.PI),M<=0&&(M+=2*Math.PI),this.line=(R-v)/(M-v)-.5;break}I=A}}else if(x.y<0){this.bB.x=Math.min(Math.min(x.x,g.x),this.LINE_RADIUS)+this.rx,this.bB.w=Math.max(x.x,g.x)+this.rx-this.bB.x+1,this.bB.y=Math.min(Math.min(x.y,g.y),-this.LINE_RADIUS)+this.ry,this.bB.h=Math.max(x.y,g.y)+this.ry-this.bB.y+1,this.constrainBB(h);B=this.bB&&h.getImageData(this.bB.x,this.bB.y,this.bB.w+1,this.bB.h+1),E=this.bB&&o.getImageData(this.bB.x,this.bB.y,this.bB.w+1,this.bB.h+1);if(B)for(f=0;f=0;f--){var O,D,A;P=this.LINE_RADIUS*this.LINE_RADIUS-(f+this.bB.x-this.rx)*(f+this.bB.x-this.rx),_=4*(f+(O=Math.round(Math.sqrt(P)-this.bB.y+this.ry)-1)*B.width)-4;if((A=(D=this.getPixelData(E,_,B,I)).redPix)!==(I=D.redPixOld)){R=Math.atan2(O+this.bB.y-this.ry,f+this.bB.x-this.rx);this.line=(R-v)/(M-v)-.5;break}I=A}}n.camera={},n.camera[s.LINE]=this.line}},t.prototype.getPixelData=function(t,i,e,s){if(255===t.data[i+3])for(var r=i;rthis.THRESHOLD?255:0},t.prototype.checkVisibility=function(t,i,e){for(var s,a={x1:this.rx,y1:this.ry,x2:i.x,y2:i.y},o=0;o=this.colourBlob.minHue&&t[0]<=this.colourBlob.maxHue&&t[1]>=this.colourBlob.minSat&&t[1]<=this.colourBlob.maxSat&&t[2]>=this.colourBlob.minVal&&t[2]<=this.colourBlob.maxVal)},t.prototype.constrainBB=function(t){this.bB.x=this.bB.x<0?0:this.bB.x,this.bB.y=this.bB.y<0?0:this.bB.y,(this.bB.x+this.bB.w>t.canvas.width&&(this.bB.w=t.canvas.width-this.bB.x,this.bB.w<1)||this.bB.y+this.bB.h>t.canvas.height&&(this.bB.h=t.canvas.width-this.bB.y,this.bB.h<1))&&(this.bB=null)},t}();i.CameraSensor=z;var Z=function(t){function i(i,e,s){var r=t.call(this,i,e)||this;return r.MAX_CAM_Y=150,r.MAX_BLOB_DIST_SQR=r.MAX_MARKER_DIST_SQR,r.LINE_RADIUS=45,r.THRESHOLD=175,r.p={x:0,y:0,rx:0,ry:0},r.rect={p1:r.p,p2:r.p,p3:r.p,p4:r.p},r.BLOBSIZE=s,r}return __extends(i,t),i.prototype.draw=function(i,e){t.prototype.draw.call(this,i,e),i.save(),i.rotate(-e.pose.theta),i.translate(-e.pose.x,-e.pose.y),i.beginPath(),i.strokeStyle="#00ffff",i.moveTo(this.rect.p1.rx,this.rect.p1.ry),i.lineTo(this.rect.p2.rx,this.rect.p2.ry),i.lineTo(this.rect.p3.rx,this.rect.p3.ry),i.lineTo(this.rect.p4.rx,this.rect.p4.ry),i.lineTo(this.rect.p1.rx,this.rect.p1.ry),i.stroke(),i.restore()},i.prototype.updateSensor=function(t,i,a,n,h,o,l,p){var u=a;r.transform(u.pose,this);new e.Pose(this.rx,this.ry,this.theta);var c=(a.pose.theta-this.AOV/2+2*Math.PI)%(2*Math.PI),y=(a.pose.theta+this.AOV/2+2*Math.PI)%(2*Math.PI);if(n[s.CAMERA]={},this.lineEnabled){var b=function(t,i,e){this.line=100*(t+i),this.lineWidth=Math.abs(Math.round(100*(t-i)));var s=[0,0,0];e.forEach((function(t){s[0]+=t[0],s[1]+=t[1],s[2]+=t[2]})),this.lineColor=[Math.round(s[0]/e.length),Math.round(s[1]/e.length),Math.round(s[2]/e.length)]};this.line=-1,this.lineWidth=0,this.lineColor=[];var f={x:this.LINE_RADIUS*Math.cos(c),y:this.LINE_RADIUS*Math.sin(c)},x={x:this.LINE_RADIUS*Math.cos(y),y:this.LINE_RADIUS*Math.sin(y)},g=Math.atan2(f.y,f.x),v=Math.atan2(x.y,x.x),M=Math.abs(x.y-f.y),S=Math.abs(x.x-f.x),m=void 0,I=void 0,B=void 0,E=[];if(this.bB={h:0,w:0,x:0,y:0},M>S)if(f.x>0){this.bB.x=Math.min(f.x,x.x)+this.rx,this.bB.y=Math.min(f.y,x.y)+this.ry,this.bB.w=Math.max(Math.max(f.x,x.x),this.LINE_RADIUS)+this.rx-this.bB.x+1,this.bB.h=-this.bB.y+Math.max(Math.max(f.y,x.y))+this.ry+1,this.constrainBB(h);var P=this.bB&&h.getImageData(this.bB.x,this.bB.y,this.bB.w,this.bB.h),_=this.bB&&o.getImageData(this.bB.x,this.bB.y,this.bB.w,this.bB.h);if(P)for(var R=0;R0;R--){var A;L=this.LINE_RADIUS*this.LINE_RADIUS-(R+this.bB.y-this.ry)*(R+this.bB.y-this.ry),O=4*((A=Math.round(-Math.sqrt(L)-(this.bB.x-this.rx)))+R*P.width)-4;if((N=(w=this.getPixelData(_,O,P,m)).redPix)!==(m=w.redPixOld))if((D=Math.atan2(R+this.bB.y-this.ry,A+this.bB.x-this.rx))<=0&&(D+=2*Math.PI),g<=0&&(g+=2*Math.PI),v<=0&&(v+=2*Math.PI),null==I)I=(D-g)/(v-g)-.5;else if(null==B){b.call(this,I,B=(D-g)/(v-g)-.5,E);break}void 0!==I&&E.push(w.pixColor),m=N}}else if(f.y<0){this.bB.x=Math.min(Math.min(f.x,x.x),this.LINE_RADIUS)+this.rx,this.bB.w=Math.max(f.x,x.x)+this.rx-this.bB.x+1,this.bB.y=Math.min(Math.min(f.y,x.y),-this.LINE_RADIUS)+this.ry,this.bB.h=Math.max(f.y,x.y)+this.ry-this.bB.y+1,this.constrainBB(h);P=this.bB&&h.getImageData(this.bB.x,this.bB.y,this.bB.w+1,this.bB.h+1),_=this.bB&&o.getImageData(this.bB.x,this.bB.y,this.bB.w+1,this.bB.h+1);if(P)for(R=0;R0;R--){var T,w,N;L=this.LINE_RADIUS*this.LINE_RADIUS-(R+this.bB.x-this.rx)*(R+this.bB.x-this.rx),O=4*(R+(T=Math.round(Math.sqrt(L)-this.bB.y+this.ry)-1)*P.width)-4;if((N=(w=this.getPixelData(_,O,P,m)).redPix)!==(m=w.redPixOld)){D=Math.atan2(T+this.bB.y-this.ry,R+this.bB.x-this.rx);if(null==I)I=(D-g)/(v-g)-.5;else if(null==B){b.call(this,I,B=(D-g)/(v-g)-.5,E);break}}void 0!==I&&E.push(w.pixColor),m=N}}n[s.CAMERA][s.LINE]={},n[s.CAMERA][s.LINE][s.INFO]=[this.line,this.lineWidth],n[s.CAMERA][s.LINE][s.COLOR]=this.lineColor,n[s.CAMERA][s.LINE][s.NUMBER]=0===this.lineWidth?0:1}if(this.colorEnabled){this.color=[];var k=this.AOV*this.BLOBSIZE/100;c=(-k/2+2*Math.PI)%(2*Math.PI),y=(k/2+2*Math.PI)%(2*Math.PI);var C=this.LINE_RADIUS+(this.MAX_CAM_Y-this.LINE_RADIUS)*(100-this.BLOBSIZE)/200,U=C+(this.MAX_CAM_Y-this.LINE_RADIUS)*this.BLOBSIZE/100,G=(f={x:C*Math.cos(c),y:C*Math.sin(c)},x={x:C*Math.cos(y),y:C*Math.sin(y)},{x:U*Math.cos(c),y:U*Math.sin(c)}),F={x:U*Math.cos(y),y:U*Math.sin(y)};this.bB={h:0,w:0,x:0,y:0};var V={x:f.x,y:f.y,rx:0,ry:0};r.transform(u.pose,V),this.rect.p1=V,V={x:G.x,y:G.y,rx:0,ry:0},r.transform(u.pose,V),this.rect.p2=V,V={x:F.x,y:F.y,rx:0,ry:0},r.transform(u.pose,V),this.rect.p3=V,V={x:x.x,y:x.y,rx:0,ry:0},r.transform(u.pose,V),this.rect.p4=V,this.bB.x=Math.min(this.rect.p1.rx,this.rect.p2.rx,this.rect.p3.rx,this.rect.p4.rx),this.bB.y=Math.min(this.rect.p1.ry,this.rect.p2.ry,this.rect.p3.ry,this.rect.p4.ry),this.bB.w=Math.max(this.rect.p1.rx,this.rect.p2.rx,this.rect.p3.rx,this.rect.p4.rx)-this.bB.x,this.bB.h=Math.max(this.rect.p1.ry,this.rect.p2.ry,this.rect.p3.ry,this.rect.p4.ry)-this.bB.y,this.constrainBB(h);P=this.bB&&h.getImageData(this.bB.x,this.bB.y,this.bB.w,this.bB.h),_=this.bB&&o.getImageData(this.bB.x,this.bB.y,this.bB.w,this.bB.h);var H=$("#objectLayer")[0].getContext("2d",{willReadFrequently:!0});H.restore(),H.save();var X=d.SimulationRoberta.Instance.scale,K=void 0;try{K=this.bB&&H.getImageData(Math.round(this.bB.x*X),Math.round(this.bB.y*X),Math.round(this.bB.w*X),Math.round(this.bB.h*X))}catch(t){}var q=0,Y=0,W=0,j=K?K.data.length/P.data.length:0;if(P){for(R=0;R
"+a.round(this.line,0)+"
"+this.lineWidth+"
 
 
'),t},i.prototype.getPixelData=function(t,i,e,s){if(255===t.data[i+3])for(var r=i;r"+(a.round(this.time[i],1)+" s")+""}return t},t.prototype.reset=function(){for(var t in this.time)this.time[t]=0},t.prototype.updateAction=function(t,i,e){if(e){for(var s in this.time)this.time[s]+=i;var r=t.interpreter.getRobotBehaviour().getActionState("timer",!0);if(r)for(var a=1;a<=this.time.length;a++)r[a]&&"reset"==r[a]&&(this.time[a-1]=0)}},t.prototype.updateSensor=function(t,i,e,s,r,a,n){s.timer=s.timer||[];for(var h=0;h"+a.round(this.distance/3,0)+" cm"},i.prototype.updateSensor=function(i,e,s,r,a,n,h){t.prototype.updateSensor.call(this,i,e,s,r,a,n,h);var o=this.distance/3;r.ultrasonic=r.ultrasonic||{},r.ultrasonic[this.port]={},o"+a.round(this.distance/3,0)+" cm":"
"+a.round(this.distance/3,0)+" cm
"},i.prototype.updateSensor=function(i,e,s,r,a,n,h){t.prototype.updateSensor.call(this,i,e,s,r,a,n,h);var o=this.distance/3;r.infrared=r.infrared||{},r.infrared[this.port]={},this.relative?o"+a.round(t,0)+" %"},i.prototype.updateSensor=function(i,e,s,r,n,h,o){t.prototype.updateSensor.call(this,i,e,s,r,n,h,o);var l=this.distance/3;r.infrared=r.infrared||{},r.infrared.distance=r.infrared.distance?r.infrared.distance:{},l"+(this.distance/3"},i.prototype.updateSensor=function(i,e,s,r,a,n,h){t.prototype.updateSensor.call(this,i,e,s,r,a,n,h);var o=this.distance/3;r.infrared=r.infrared||{},r.infrared[this.port]=r.infrared[this.port]?r.infrared[this.port]:{},r.infrared[this.port].obstacle=o
"+this.line+"
"+this.light+"
"},t.prototype.updateSensor=function(t,i,e,s,n,h,o){var l=e,d={rx:0,ry:0,x:this.x,y:this.y};r.transform(l.pose,d),s.infrared=s.infrared||{};var p=this;!function(t,i){for(var e=0,r=0,o=0,l=n.getImageData(Math.round(i.x-p.radius),Math.round(i.y-p.radius),p.diameter,p.diameter),d=h.getImageData(Math.round(i.x-p.radius),Math.round(i.y-p.radius),p.diameter,p.diameter),u=0;u<=l.data.length;u+=4)if(255===d.data[u+3])for(var c=u;c=0&&(e+=l.data[u],r+=l.data[u+1],o+=l.data[u+2]);var y=l.data.length/4-4,b=((e/=y)+(r/=y)+(o/=y))/3/2.55;p.line=b<50,p.light=a.round(b,0),s.infrared.light=s.infrared.light?s.infrared.light:{},s.infrared.light=p.light,s.infrared.line=s.infrared.line?s.infrared.line:{},s.infrared.line=p.line}(0,{x:d.rx,y:d.ry})},t}();i.LineSensor=x;var g=function(){function t(t){this.drawPriority=4,this.left=new x({x:t.x,y:t.y-3},3),this.right=new x({x:t.x,y:t.y+3},3)}return t.prototype.getLabel=function(){return"
"+this.left.line+"
"+this.left.light+"
"+this.right.line+"
"+this.right.light+"
"},t.prototype.updateSensor=function(t,i,e,s,r,a,n,h){this.left.updateSensor(t,i,e,s,r,a,n),this.right.updateSensor(t,i,e,s,r,a,n),this.left.line=this.left.line?1:0,this.right.line=this.right.line?1:0,s.infrared.light={},s.infrared.light.left=this.left.light,s.infrared.light.right=this.right.light,s.infrared.line={},s.infrared.line.left=this.left.line,s.infrared.line.right=this.right.line},t.prototype.draw=function(t,i){this.left.draw(t,i),this.right.draw(t,i)},t}();i.ThymioLineSensors=g;var v=function(){function t(t,i){this.drawPriority=4,this.port=t,this.left=new x({x:i.x,y:i.y-3},3),this.right=new x({x:i.x,y:i.y+3},3)}return t.prototype.getLabel=function(){return"
"+this.left.line+"
"+this.right.line+"
"},t.prototype.updateSensor=function(t,i,e,s,r,a,n,h){this.left.updateSensor(t,i,e,s,r,a,n),this.right.updateSensor(t,i,e,s,r,a,n),s.infrared={},s.infrared[this.port]={},s.infrared[this.port].left=this.left.line,s.infrared[this.port].right=this.right.line},t.prototype.draw=function(t,i){this.left.draw(t,i),this.right.draw(t,i)},t}();i.Txt4InfraredSensors=v;var M=function(){function t(t,i){this.right={value:0},this.left={value:0},this.drawPriority=4,this.rx=0,this.ry=0,this.dx=5,this.dy=8,this.r=1.5,this.x=i.x,this.y=i.y,this.port=t,this.labelPriority=Number(this.port.replace("ORT_",""))}return t.prototype.draw=function(t,i){t.save(),t.fillStyle="#333",t.rect(this.x,this.y-this.dy/2,this.dx,this.dy),t.fill(),t.beginPath(),t.lineWidth=.1,t.arc(this.x+this.dx/2,this.y-this.dy/4,this.r,0,2*Math.PI),t.fillStyle=this.left.value?"black":"white",t.fill(),t.strokeStyle="black",t.stroke(),t.lineWidth=.5,t.beginPath(),t.lineWidth=.1,t.arc(this.x+this.dx/2,this.y+this.dy/4,this.r,0,2*Math.PI),t.fillStyle=this.right.value?"black":"white",t.fill(),t.strokeStyle="black",t.stroke(),t.beginPath(),t.fillStyle="#555555",t.fillText(String(this.port.replace("ORT_","")),this.x+2,this.y+12),t.restore()},t.prototype.getLabel=function(){return"
"+this.left.value+"
"+this.right.value+"
"},t.prototype.updateSensor=function(t,i,e,s,a,n,h){var o=e,l={rx:0,ry:0,x:this.x+this.dx/2,y:this.y-this.dy/4},d={rx:0,ry:0,x:this.x+this.dx/2,y:this.y+this.dy/4};r.transform(o.pose,l),r.transform(o.pose,d),s.infrared=s.infrared||{},s.infrared[this.port]={};var p=this;function u(t,i){for(var e=0,r=0,h=0,o=a.getImageData(Math.round(i.x-3),Math.round(i.y-3),6,6),l=n.getImageData(Math.round(i.x-3),Math.round(i.y-3),6,6),d=0;d<=o.data.length;d+=4)if(255===l.data[d+3])for(var u=d;u";return this.infraredSensorArray.forEach((function(i){return t+=i.getLabel()})),t},t.prototype.updateSensor=function(t,i,e,s,r,a,n){this.infraredSensorArray.forEach((function(h){return h.updateSensor(t,i,e,s,r,a,n)}))},t}();i.InfraredSensors=S;var m=function(t){function i(){return null!==t&&t.apply(this,arguments)||this}return __extends(i,t),i.prototype.configure=function(){this.infraredSensorArray[0]=new b("0",24*Math.cos(-Math.PI/4),24*Math.sin(-Math.PI/4),-Math.PI/4,14,o.Msg.FRONT_LEFT),this.infraredSensorArray[1]=new b("1",26*Math.cos(-Math.PI/8),26*Math.sin(-Math.PI/8),-Math.PI/8,14,o.Msg.FRONT_LEFT_MIDDLE),this.infraredSensorArray[2]=new b("2",26,0,0,14,o.Msg.FRONT_MIDDLE),this.infraredSensorArray[3]=new b("3",26*Math.cos(Math.PI/8),26*Math.sin(Math.PI/8),Math.PI/8,14,o.Msg.FRONT_RIGHT_MIDDLE),this.infraredSensorArray[4]=new b("4",24*Math.cos(Math.PI/4),24*Math.sin(Math.PI/4),Math.PI/4,14,o.Msg.FRONT_RIGHT),this.infraredSensorArray[5]=new b("5",-9,-13,Math.PI,14,o.Msg.BACK_LEFT),this.infraredSensorArray[6]=new b("6",-9,13,Math.PI,14,o.Msg.BACK_RIGHT)},i}(S);i.ThymioInfraredSensors=m;var I=function(t){function i(){return null!==t&&t.apply(this,arguments)||this}return __extends(i,t),i.prototype.configure=function(){this.infraredSensorArray[0]=new y("1",68*Math.cos(0),68*Math.sin(0),0,30,!1),this.infraredSensorArray[1]=new y("2",68*Math.cos(2*-Math.PI/9),68*Math.sin(2*-Math.PI/9),2*-Math.PI/9,30,!1),this.infraredSensorArray[2]=new y("3",68*Math.cos(4*-Math.PI/9),68*Math.sin(4*-Math.PI/9),4*-Math.PI/9,30,!1),this.infraredSensorArray[3]=new y("4",68*Math.cos(6*-Math.PI/9),68*Math.sin(6*-Math.PI/9),6*-Math.PI/9,30,!1),this.infraredSensorArray[4]=new y("5",68*Math.cos(8*-Math.PI/9),68*Math.sin(8*-Math.PI/9),8*-Math.PI/9,30,!1),this.infraredSensorArray[9]=new y("9",68*Math.cos(2*Math.PI/9),68*Math.sin(2*Math.PI/9),2*Math.PI/9,30,!1),this.infraredSensorArray[8]=new y("8",68*Math.cos(4*Math.PI/9),68*Math.sin(4*Math.PI/9),4*Math.PI/9,30,!1),this.infraredSensorArray[7]=new y("7",68*Math.cos(6*Math.PI/9),68*Math.sin(6*Math.PI/9),6*Math.PI/9,30,!1),this.infraredSensorArray[6]=new y("6",68*Math.cos(8*Math.PI/9),68*Math.sin(8*Math.PI/9),8*Math.PI/9,30,!1)},i}(S);i.RobotinoInfraredSensors=I;var B=function(t){function i(){return null!==t&&t.apply(this,arguments)||this}return __extends(i,t),i.prototype.configure=function(){this.infraredSensorArray[1]=new f("LEFT",17,-8,0,3,o.Msg.LEFT),this.infraredSensorArray[0]=new f("FRONT",18,0,0,3,o.Msg.SLOT_FRONT),this.infraredSensorArray[2]=new f("RIGHT",17,8,0,3,o.Msg.RIGHT)},i}(S);i.EdisonInfraredSensors=B;var E=function(){function t(t,i,e,s){this.color="#FF69B4",this.rx=0,this.ry=0,this.value=!1,this.drawPriority=4,this.port=t,this.labelPriority=Number(this.port.replace("ORT_","")),this.x=i,this.y=e,this.color=s||this.color}return t.prototype.draw=function(t,i){t.save(),t.shadowBlur=5,t.shadowColor="black",t.fillStyle=i.chassis.geom.color,this.value?t.fillStyle="red":t.fillStyle=i.chassis.geom.color,t.fillRect(i.chassis.frontLeft.x-3.5,i.chassis.frontLeft.y,3.5,-i.chassis.frontLeft.y+i.chassis.frontRight.y),t.restore()},t.prototype.getLabel=function(){return"
"+this.value+"
"},t.prototype.updateSensor=function(t,i,e,s,r,a,n){s.touch=s.touch||{},s.touch[this.port]=this.value=e.chassis.frontLeft.bumped||e.chassis.frontRight.bumped},t}();i.TouchSensor=E;var P=function(){function t(){}return t.prototype.updateSensor=function(t,i,e,s,r,a,n){s.touch=s.touch||{};var h=e.chassis.frontLeft.bumped||e.chassis.frontRight.bumped||e.chassis.backLeft.bumped||e.chassis.backRight.bumped;s.touch=h?1:0},t}();i.TapSensor=P;var _=function(){function t(){this.bumped=!1,this.drawPriority=4}return t.prototype.getLabel=function(){return"
"+this.bumped+"
"},t.prototype.updateSensor=function(t,i,e,s,r,a,n){s.touch=s.touch||{},s.touch=this.bumped=e.chassis.bumpedAngle.length>0},t}();i.RobotinoTouchSensor=_;var R=function(){function t(t,i,e,s,r,a){this.color="grey",this.colorValue="NONE",this.lightValue=0,this.rgb=[0,0,0],this.rx=0,this.ry=0,this.drawPriority=6,this.port=t,this.labelPriority=Number(this.port.replace("ORT_","")),this.x=i,this.y=e,this.theta=s,this.r=r,this.color=a||this.color}return t.prototype.draw=function(t,i){t.save(),t.beginPath(),t.arc(this.x,this.y,this.r,0,2*Math.PI),t.fillStyle=this.color,t.fill(),t.strokeStyle="black",t.stroke(),t.translate(this.x,this.y),t.beginPath(),t.fillStyle="#555555",t.fillText(this.port,-12,4),t.restore()},t.prototype.getLabel=function(){return"
 
"+a.round(this.lightValue,0)+" %
"},t.prototype.updateSensor=function(t,i,e,s,n,h){s.color=s.color||{},s.light=s.light||{},s.color[this.port]={},s.light[this.port]={},r.transform(e.pose,this);var o=0,l=0,d=0,p=Math.round(this.rx-3),u=Math.round(this.ry-3);try{for(var c=n.getImageData(p,u,6,6),y=h.getImageData(p,u,6,6),b=0;b<=c.data.length;b+=4)if(255===y.data[b+3])for(var f=b;f
"+a.round(this.lightValue,0)+" %
"},i}(R);i.LightSensor=O;var D=function(t){function i(i,e,s,r,a,n,h){var o=t.call(this,e.replace("DI","").toString(),s,r,a,n)||this;return o.name=i,o}return __extends(i,t),i.prototype.getLabel=function(){return"
"+this.light+"
"+!this.light+"
"},i.prototype.draw=function(t,i){t.save(),t.beginPath(),t.arc(this.x,this.y,this.r,0,2*Math.PI),t.fillStyle=this.color,t.fill(),t.strokeStyle="black",t.stroke(),t.translate(this.x,this.y),t.beginPath(),t.fillStyle="#555555",t.fillText(this.name,8,4),t.restore()},i.prototype.updateSensor=function(i,e,r,a,n,h){t.prototype.updateSensor.call(this,i,e,r,a,n,h),this.lightValue=this.lightValue>50?100:0,this.light=0!=this.lightValue,this.color=0==this.lightValue?"black":"white",a.optical=a.optical||{},a.optical[this.name]={},a.optical[this.name][s.OPENING]=this.light,a.optical[this.name][s.CLOSING]=!this.light},i}(O);i.OpticalSensor=D;var A=function(){function t(){this.angleValue=0,this.rateValue=0}return t.prototype.getLabel=function(){return"
"+a.round(this.angleValue,0)+" °
"},t.prototype.reset=function(){this.angleValue=0,this.rateValue=0},t.prototype.updateAction=function(t,i,e){},t.prototype.updateSensor=function(t,i,e,s,r,a,n){},t}();i.GyroSensor=A;var T=function(t){function i(i,e,s,r){var a=t.call(this)||this;return a.color="#000000",a.port=i,a.x=e,a.y=s,a.theta=r,a}return __extends(i,t),i.prototype.getLabel=function(){return"
"+a.round(this.angleValue,0)+" °
"},i.prototype.updateAction=function(t,i,e){var s=t.interpreter.getRobotBehaviour().getActionState("gyroReset",!1);s&&s[this.port]&&(t.interpreter.getRobotBehaviour().getActionState("gyroReset",!0),this.reset())},i.prototype.updateSensor=function(t,i,e,s,a,n,h){s.gyro=s.gyro||{},s.gyro[this.port]={},this.angleValue+=r.toDegree(e.thetaDiff),s.gyro[this.port].angle=this.angleValue,this.rateValue=i*r.toDegree(e.thetaDiff),s.gyro[this.port].rate=this.rateValue},i}(A);i.GyroSensorExt=T;var w=function(){function t(){this.keys={}}return t.prototype.getLabel=function(){return""},t}();i.Keys=w;var N=function(t){function i(i,e){var s=t.call(this)||this;for(var r in i)s.keys[i[r].name]=i[r];return s}return __extends(i,t),i.prototype.updateSensor=function(t,i,e,s,r,a,n){for(var h in s.buttons={},s.buttons.any=!1,s.buttons.Reset=!1,this.keys)s.buttons[h]=!0===this.keys[h].value,s.buttons.any=s.buttons.any||this.keys[h].value},i}(w);i.EV3Keys=N;var k=function(t){function i(i,e,s){var r=t.call(this)||this;for(var a in r.color2Keys={},r.$touchLayer=$("#robotLayer"),r.isDown=!1,r.id=e,r.$touchLayer=s||r.$touchLayer,i)r.keys[i[a].port]=i[a];return i.forEach((function(t){t.touchColors.forEach((function(i){r.color2Keys[i]=[t.port]}))})),r.addMouseEvents(e),r}return __extends(i,t),i.prototype.handleMouseDown=function(t){var i=this;t&&!t.startX&&a.extendMouseEvent(t,d.SimulationRoberta.Instance.scale,this.$touchLayer);var e=t;if(this.lastMousePosition={x:e.startX,y:e.startY},void 0!==this.uCtx){var s=this.uCtx.getImageData(this.lastMousePosition.x,this.lastMousePosition.y,1,1).data;this.lastMouseColor=a.RGBAToHexA([s[0],s[1],s[2],s[3]])}this.isDown=!0;var r=this.color2Keys[this.lastMouseColor];r&&r.length>0&&(this.$touchLayer.data("hovered",!0),this.$touchLayer.css("cursor","pointer"),t.stopImmediatePropagation(),r.forEach((function(t){i.keys[t].value=!0})))},i.prototype.handleMouseMove=function(t){t&&!t.startX&&a.extendMouseEvent(t,d.SimulationRoberta.Instance.scale,this.$touchLayer);var i=t;if(this.lastMousePosition={x:i.startX,y:i.startY},void 0!==this.uCtx){var e=this.uCtx.getImageData(this.lastMousePosition.x,this.lastMousePosition.y,1,1).data;this.lastMouseColor=a.RGBAToHexA([e[0],e[1],e[2],e[3]])}var s=this.color2Keys[this.lastMouseColor];s&&s.length>0&&(this.$touchLayer.data("hovered",!0),this.$touchLayer.css("cursor","pointer"),t.stopImmediatePropagation())},i.prototype.handleMouseOutUp=function(t){for(var i in this.keys)this.keys[i].value=!1;this.isDown=!1},i.prototype.updateSensor=function(t,i,e,s,r,a,n){for(var h in void 0===this.uCtx&&(this.uCtx=r),s.buttons={},this.keys)s.buttons[h]=!0===this.keys[h].value},i.prototype.addMouseEvents=function(t){this.$touchLayer.on("mousedown.R"+t+" touchstart.R"+t,this.handleMouseDown.bind(this)),this.$touchLayer.on("mousemove.R"+t+" touchmove.R"+t,this.handleMouseMove.bind(this)),this.$touchLayer.on("mouseup.R"+t+" touchend.R"+t+" mouseout.R"+t+" touchcancel.R"+t,this.handleMouseOutUp.bind(this))},i}(w);i.TouchKeys=k;var C=function(t){function i(i,e,s,r){var a=t.call(this,i,e)||this,n=$("#mbedButtons");return a.transP=s,a.groundP=r,i.forEach((function(t){if("TOUCH"!==t.type){var i=1023;n.append('"),"DIGITAL_PIN"===t.type&&(i=1),n.append(''),n.append('
'),j($("#sliderPin"+t.port),$("#rangePin"+t.port),a.keys[t.port],"typeValue",{min:0,max:i})}})),a}return __extends(i,t),i.prototype.draw=function(t,i){for(var e in this.keys){var s=this.keys[e];switch(s.type){case"TOUCH":s.value&&(t.fillStyle=s.color,t.beginPath(),t.arc(s.x,s.y,s.r,0,2*Math.PI),t.fill(),this.groundP&&(t.fillStyle="red",t.beginPath(),t.arc(this.groundP.x,this.groundP.y,25,0,2*Math.PI),t.fill()));break;case"DIGITAL_PIN":t.fillStyle=s.color,t.beginPath(),t.save();var r=s.x+this.transP.x,a=s.y+this.transP.y;t.translate(r,a),t.save(),t.rotate(Math.PI/2),t.font="bold 100px Roboto",t.fillText("< ",0,0),t.restore(),t.font="20px Courier",t.fillText("⊓",-16,16),t.fillText(s.typeValue,50,16),t.restore();break;case"ANALOG_PIN":t.fillStyle=s.color,t.beginPath(),t.save();r=s.x+this.transP.x,a=s.y+this.transP.y;t.translate(r,a),t.save(),t.rotate(Math.PI/2),t.font="bold 100px Roboto",t.fillText("< ",0,0),t.restore(),t.font="20px Courier",t.fillText("∿",-16,16),t.fillText(s.typeValue,50,16),t.restore()}}},i.prototype.updateSensor=function(t,i,e,s,r,a,n){for(var h in void 0===this.uCtx&&(this.uCtx=r),this.keys)s["pin"+h]={},s["pin"+h].pressed=!0===this.keys[h].value,s["pin"+h].analog=s["pin"+h].digital=this.keys[h].typeValue},i}(k);i.Pins=C;var U=function(t){function i(){return null!==t&&t.apply(this,arguments)||this}return __extends(i,t),i.prototype.draw=function(t,i){for(var e in this.keys){var s=this.keys[e];switch(s.type){case"TOUCH":s.value&&(t.fillStyle=s.color,t.beginPath(),t.fillStyle="green",t.beginPath(),t.fillRect(s.x,s.y,s.r,s.r),t.fill(),t.fillStyle="red",t.beginPath(),t.arc(this.groundP.x,this.groundP.y,36,0,2*Math.PI),t.fill());break;case"DIGITAL_PIN":t.fillStyle=s.color,t.beginPath(),t.save();var r=s.x+this.transP.x,a=s.y+this.transP.y;t.translate(r,a),t.save(),t.rotate(Math.PI/2),t.font="bold 100px Roboto",t.fillText("< ",0,0),t.restore(),t.font="20px Courier",t.fillText("⊓",-16,16),t.fillText(s.typeValue,50,16),t.restore();break;case"ANALOG_PIN":t.fillStyle=s.color,t.beginPath(),t.save();r=s.x+this.transP.x,a=s.y+this.transP.y;t.translate(r,a),t.save(),t.rotate(Math.PI/2),t.font="bold 100px Roboto",t.fillText("< ",0,0),t.restore(),t.font="20px Courier",t.fillText("∿",-16,16),t.fillText(s.typeValue,50,16),t.restore()}}},i}(C);i.MicrobitPins=U;var G=function(t){function i(i,e){return t.call(this,i,e,$("#brick"+e))||this}return __extends(i,t),i.prototype.handleMouseDown=function(t){var i=this;t&&!t.startX&&a.extendMouseEvent(t,1,this.$touchLayer);var e=t;this.lastMousePosition={x:e.startX,y:e.startY};var s=this.$touchLayer.get(0).getContext("2d").getImageData(this.lastMousePosition.x,this.lastMousePosition.y,1,1).data;this.lastMouseColor=a.RGBAToHexA([s[0],s[1],s[2],s[3]]),this.isDown=!0;var r=this.color2Keys[this.lastMouseColor];r&&r.length>0&&(this.$touchLayer.data("hovered",!0),this.$touchLayer.css("cursor","pointer"),t.stopImmediatePropagation(),r.forEach((function(t){i.keys[t].value=!0})))},i.prototype.handleMouseMove=function(t){t&&!t.startX&&a.extendMouseEvent(t,1,this.$touchLayer);var i=t;this.lastMousePosition={x:i.startX,y:i.startY};var e=this.color2Keys[this.lastMouseColor],s=this.$touchLayer.get(0).getContext("2d").getImageData(this.lastMousePosition.x,this.lastMousePosition.y,1,1).data;this.lastMouseColor=a.RGBAToHexA([s[0],s[1],s[2],s[3]]),e&&e.length>0?(this.$touchLayer.data("hovered",!0),this.$touchLayer.css("cursor","pointer"),t.stopImmediatePropagation()):this.$touchLayer.data().hovered?this.$touchLayer.data("hovered",!1):this.$touchLayer.css("cursor","move")},i.prototype.updateSensor=function(t,i,e,s,r,a,n){for(var h in s.buttons={},this.keys)s.buttons[h]=!0===this.keys[h].value},i}(k);i.MbotButton=G;var F=function(){function t(){this.gesture={up:!0},this.labelPriority=10,$("#mbedButtons").append('");var t=this;$("#mbedButtons>.simbtn").on("click",(function(i){var e=$(this);$("#mbedButtons>.simbtn").each((function(){this.id==e[0].id?$(this).addClass("active"):$(this).removeClass("active")})),t.gesture={},t.gesture[i.currentTarget.id]=!0}))}return t.prototype.getLabel=function(){return"
"+o.Msg["SENSOR_GESTURE_"+Object.getOwnPropertyNames(this.gesture)[0].toUpperCase()]+"
"},t.prototype.updateSensor=function(t,i,e,s,r,a,n){s.gesture={};var h=Object.getOwnPropertyNames(this.gesture)[0];s.gesture[h]=this.gesture[h]},t}();i.GestureSensor=F;var V=function(){function t(){this.degree=0,this.labelPriority=11,$("#mbedButtons").append('
'),j($("#sliderCompass"),$("#rangeCompass"),this,"degree",{min:0,max:360})}return t.prototype.getLabel=function(){return"
"+this.degree+" °
"},t.prototype.updateSensor=function(t,i,e,s,r,a,n){s.compass={},s.compass.angle=this.degree},t}();i.CompassSensor=V;var H=function(){function t(t){this.dx=60,this.dy=60,this.lightLevel=0,this.x=342,this.y=546,this.labelPriority=12,t&&(this.x=t.x,this.y=t.y,this.dx=t.w,this.dy=t.h),$("#mbedButtons").append('
'),j($("#sliderLight"),$("#rangeLight"),this,"lightLevel",{min:0,max:100})}return t.prototype.draw=function(t,i){t.save(),t.beginPath(),t.fillStyle="#ffffff",t.globalAlpha=this.lightLevel/500,t.rect(this.x-this.dx/2,this.y+this.dy/2,5*this.dx,-5*this.dy),t.fill(),t.globalAlpha=1,t.restore()},t.prototype.getLabel=function(){return"
"+this.lightLevel+" %
"},t.prototype.updateSensor=function(t,i,e,s,r,a,n){s.light={},s.light.ambientlight=this.lightLevel},t}();i.CalliopeLightSensor=H;var X=function(){function t(){this.dx=60,this.dy=60,this.lightLevel=0,this.x=342,this.y=546,this.labelPriority=12,$("#mbedButtons").append('
'),j($("#sliderLight"),$("#rangeLight"),this,"lightLevel",{min:0,max:1023})}return t.prototype.getLabel=function(){return"
"+this.lightLevel+"
"},t.prototype.updateSensor=function(t,i,e,s,r,a,n){s.light={},s.light.ambientlight=this.lightLevel,s.light.reflected=this.lightLevel},t}();i.Rob3rtaInfraredSensor=X;var K=function(){function t(){this.degree=20,this.labelPriority=13,$("#mbedButtons").append('
'),j($("#sliderTemperature"),$("#rangeTemperature"),this,"degree",{min:-15,max:75})}return t.prototype.getLabel=function(){return"
"+this.degree+" °
"},t.prototype.updateSensor=function(t,i,e,s,r,a,n){s.temperature={},s.temperature.value=this.degree},t}();i.TemperatureSensor=K;var q=function(){function t(t){this.labelPriority=16,this.volume=0,void 0===window.navigator.mediaDevices&&(window.navigator.mediaDevices={}),this.webAudio=t.webAudio,window.navigator.mediaDevices.getUserMedia=navigator.mediaDevices.getUserMedia||navigator.webkitGetUserMedia||navigator.mozGetUserMedia;var i=this;try{navigator.mediaDevices.getUserMedia({audio:{mandatory:{googEchoCancellation:"false",googAutoGainControl:"false",googNoiseSuppression:"false",googHighpassFilter:"false"},optional:[]}}).then((function(t){var e=i.webAudio.context.createMediaStreamSource(t);i.sound=l.createAudioMeter(i.webAudio.context),e.connect(i.sound)}),(function(){console.log("Sorry, but there is no microphone available on your system")}))}catch(t){console.log("Sorry, but there is no microphone available on your system")}}return t.prototype.getLabel=function(){return"
"+a.round(this.volume,0)+" %
"},t.prototype.updateSensor=function(t,i,e,s,r,n,h){this.volume=this.sound?a.round(100*this.sound.volume,0):0,s.sound={},s.sound.volume=this.volume},t}();i.VolumeMeterSensor=q;var Y=function(t){function i(i,e){var s=t.call(this,i)||this;return s.theta=0,s.x=0,s.y=0,s.port=e,s.labelPriority=Number(s.port.replace("ORT_","")),s}return __extends(i,t),i.prototype.getLabel=function(){return"
"+a.round(this.volume,0)+" %
"},i.prototype.updateSensor=function(t,i,e,s,r,n,h){this.volume=this.sound?a.round(100*this.sound.volume,0):0,s.sound={},s.sound[this.port]={},s.sound[this.port].volume=this.volume},i}(q);i.SoundSensor=Y;var W=function(t){function i(){return null!==t&&t.apply(this,arguments)||this}return __extends(i,t),i.prototype.getLabel=function(){return"
"+(this.volume>25?"true":"false")+"
"},i.prototype.updateSensor=function(i,e,s,r,a,n,h){t.prototype.updateSensor.call(this,i,e,s,r,a,n,h),r.sound.volume=this.volume>25},i}(q);function j(t,i,e,s,r){t.on("mousedown touchstart",(function(t){t.stopPropagation()})),t.on("input change",(function(r){r.preventDefault(),i.val(t.val()),e[s]=Number(t.val()),r.stopPropagation()})),i.on("change",(function(a){a.preventDefault();var n=Number(i.val());i.valid()?(nr.max&&(n=r.max),i.val(n),t.val(n),e[s]=n):i.val(t.val()),a.stopPropagation()})),i.val(e[s]),t.val(e[s]),$("#mbed-form").validate(),i.rules("add",{messages:{required:!1,number:!1}})}i.SoundSensorBoolean=W;var Q=function(){function t(){this.x=0,this.y=0,this.theta=0,this.labelPriority=7}return t.prototype.getLabel=function(){var t="
";return t+="
"+a.round(this.x,1)+" cm
",t+="
"+a.round(this.y,1)+" cm
",t+="
"+a.round(this.theta,0)+" °
"},t.prototype.reset=function(){this.x=0,this.y=0,this.theta=0},t.prototype.updateSensor=function(t,i,e,a,n,h,o){a.odometry=a.odometry||{},this.theta+=r.toDegree(e.thetaDiff),a.odometry[s.THETA]=this.theta,this.x+=e.chassis.xDiff/3,a.odometry[s.X]=this.x,this.y+=e.chassis.yDiff/3,a.odometry[s.Y]=this.y},t.prototype.updateAction=function(t,i,e){if(e){var r=t.interpreter.getRobotBehaviour().getActionState("odometry",!0);if(r&&r.reset)switch(r.reset){case s.X:this.x=0;break;case s.Y:this.y=0;break;case s.THETA:this.theta=0;break;case"all":this.reset()}}},t}();i.OdometrySensor=Q;var Z=function(){function t(t,i){this.MAX_MARKER_DIST_SQR=202500,this.MAX_CAM_Y=Math.sqrt(this.MAX_MARKER_DIST_SQR),this.MAX_BLOB_DIST_SQR=this.MAX_MARKER_DIST_SQR,this.LINE_RADIUS=60,this.markerEnabled=!0,this.lineEnabled=!0,this.colorEnabled=!0,this.AOV=2*Math.PI/5,this.listOfMarkersFound=[],this.bB={x:0,y:0,w:0,h:0},this.labelPriority=8,this.THRESHOLD=126,this.drawPriority=1,this.x=t.x,this.y=t.y,this.theta=t.theta,this.AOV=i}return t.prototype.updateAction=function(t,i,e){if(e){var s=t.interpreter.getRobotBehaviour().getActionState("colourBlob",!0);s&&(this.colourBlob=s)}this.colourBlob={minHue:0,maxHue:240,minSat:90,maxSat:110,minVal:90,maxVal:110}},t.prototype.draw=function(t,i){t.save(),t.beginPath(),t.strokeStyle="#0000ff",t.beginPath(),t.arc(this.x,this.y,this.MAX_CAM_Y,Math.PI/5,-Math.PI/5,!0),t.arc(this.x,this.y,this.LINE_RADIUS,-Math.PI/5,+Math.PI/5,!1),t.closePath(),t.stroke(),t.restore()},t.prototype.getLabel=function(){var t="";if(this.lineEnabled&&(t+="
"+a.round(this.line,2)+"
"),this.markerEnabled){t+="
";for(var i=0;i[",t+=a.round(e.xDist,0),t+=", ",t+=a.round(e.yDist,0),t+=", ",t+=a.round(e.zDist,0),t+="] cm"}}return t},t.prototype.reset=function(){},t.prototype.updateSensor=function(t,i,a,n,h,o,l,d){var p=this,u=a;r.transform(u.pose,this);var c=new e.Pose(this.rx,this.ry,this.theta),y=(a.pose.theta-this.AOV/2+2*Math.PI)%(2*Math.PI),b=(a.pose.theta+this.AOV/2+2*Math.PI)%(2*Math.PI);if(this.markerEnabled){this.listOfMarkersFound=[],d.filter((function(t){if(t.sqrDist=r.getDistance(c,t),t.sqrDist<=p.MAX_MARKER_DIST_SQR){for(var i=[{x:t.x-c.x,y:t.y-c.y},{x:t.x+t.w-c.x,y:t.y-c.y},{x:t.x+t.w-c.x,y:t.y+t.h-c.y},{x:t.x-c.x,y:t.y+t.h-c.y}],e=!0,s=0;sy&&ab&&(a>y||ae&&(e+=2*Math.PI,im)if(x.x>0){this.bB.x=Math.min(x.x,g.x)+this.rx,this.bB.y=Math.min(x.y,g.y)+this.ry,this.bB.w=Math.max(Math.max(x.x,g.x),this.LINE_RADIUS)+this.rx-this.bB.x+1,this.bB.h=-this.bB.y+Math.max(Math.max(x.y,g.y))+this.ry+1,this.constrainBB(h);var B=this.bB&&h.getImageData(this.bB.x,this.bB.y,this.bB.w,this.bB.h),E=this.bB&&o.getImageData(this.bB.x,this.bB.y,this.bB.w,this.bB.h);if(B)for(f=0;f0;f--){var L;P=this.LINE_RADIUS*this.LINE_RADIUS-(f+this.bB.y-this.ry)*(f+this.bB.y-this.ry),_=4*((L=Math.round(-Math.sqrt(P)-(this.bB.x-this.rx)))+f*B.width)-4;if((A=(D=this.getPixelData(E,_,B,I)).redPix)!==(I=D.redPixOld)){(R=Math.atan2(f+this.bB.y-this.ry,L+this.bB.x-this.rx))<=0&&(R+=2*Math.PI),v<=0&&(v+=2*Math.PI),M<=0&&(M+=2*Math.PI),this.line=(R-v)/(M-v)-.5;break}I=A}}else if(x.y<0){this.bB.x=Math.min(Math.min(x.x,g.x),this.LINE_RADIUS)+this.rx,this.bB.w=Math.max(x.x,g.x)+this.rx-this.bB.x+1,this.bB.y=Math.min(Math.min(x.y,g.y),-this.LINE_RADIUS)+this.ry,this.bB.h=Math.max(x.y,g.y)+this.ry-this.bB.y+1,this.constrainBB(h);B=this.bB&&h.getImageData(this.bB.x,this.bB.y,this.bB.w+1,this.bB.h+1),E=this.bB&&o.getImageData(this.bB.x,this.bB.y,this.bB.w+1,this.bB.h+1);if(B)for(f=0;f=0;f--){var O,D,A;P=this.LINE_RADIUS*this.LINE_RADIUS-(f+this.bB.x-this.rx)*(f+this.bB.x-this.rx),_=4*(f+(O=Math.round(Math.sqrt(P)-this.bB.y+this.ry)-1)*B.width)-4;if((A=(D=this.getPixelData(E,_,B,I)).redPix)!==(I=D.redPixOld)){R=Math.atan2(O+this.bB.y-this.ry,f+this.bB.x-this.rx);this.line=(R-v)/(M-v)-.5;break}I=A}}n.camera={},n.camera[s.LINE]=this.line}},t.prototype.getPixelData=function(t,i,e,s){if(255===t.data[i+3])for(var r=i;rthis.THRESHOLD?255:0},t.prototype.checkVisibility=function(t,i,e){for(var s,a={x1:this.rx,y1:this.ry,x2:i.x,y2:i.y},o=0;o=this.colourBlob.minHue&&t[0]<=this.colourBlob.maxHue&&t[1]>=this.colourBlob.minSat&&t[1]<=this.colourBlob.maxSat&&t[2]>=this.colourBlob.minVal&&t[2]<=this.colourBlob.maxVal)},t.prototype.constrainBB=function(t){this.bB.x=this.bB.x<0?0:this.bB.x,this.bB.y=this.bB.y<0?0:this.bB.y,(this.bB.x+this.bB.w>t.canvas.width&&(this.bB.w=t.canvas.width-this.bB.x,this.bB.w<1)||this.bB.y+this.bB.h>t.canvas.height&&(this.bB.h=t.canvas.width-this.bB.y,this.bB.h<1))&&(this.bB=null)},t}();i.CameraSensor=Z;var z=function(t){function i(i,e,s,r){var a=t.call(this,i,e)||this;return a.MAX_CAM_Y=150,a.MAX_BLOB_DIST_SQR=a.MAX_MARKER_DIST_SQR,a.LINE_RADIUS=45,a.THRESHOLD=175,a.p={x:0,y:0,rx:0,ry:0},a.rect={p1:a.p,p2:a.p,p3:a.p,p4:a.p},a.BLOBSIZE=s,0===a.BLOBSIZE&&(a.colorEnabled=!1),0===r&&(a.lineEnabled=!1),a}return __extends(i,t),i.prototype.draw=function(i,e){(this.colorEnabled||this.lineEnabled)&&t.prototype.draw.call(this,i,e),this.colorEnabled&&(i.save(),i.rotate(-e.pose.theta),i.translate(-e.pose.x,-e.pose.y),i.beginPath(),i.strokeStyle="#00ffff",i.moveTo(this.rect.p1.rx,this.rect.p1.ry),i.lineTo(this.rect.p2.rx,this.rect.p2.ry),i.lineTo(this.rect.p3.rx,this.rect.p3.ry),i.lineTo(this.rect.p4.rx,this.rect.p4.ry),i.lineTo(this.rect.p1.rx,this.rect.p1.ry),i.stroke(),i.restore())},i.prototype.updateSensor=function(t,i,a,n,h,o,l,p){var u=a;r.transform(u.pose,this);new e.Pose(this.rx,this.ry,this.theta);var c=(a.pose.theta-this.AOV/2+2*Math.PI)%(2*Math.PI),y=(a.pose.theta+this.AOV/2+2*Math.PI)%(2*Math.PI);if(n[s.CAMERA]={},this.lineEnabled){var b=function(t,i,e){this.line=100*(t+i),this.lineWidth=Math.abs(Math.round(100*(t-i)));var s=[0,0,0];e.forEach((function(t){s[0]+=t[0],s[1]+=t[1],s[2]+=t[2]})),this.lineColor=[Math.round(s[0]/e.length),Math.round(s[1]/e.length),Math.round(s[2]/e.length)]};this.line=-1,this.lineWidth=0,this.lineColor=[];var f={x:this.LINE_RADIUS*Math.cos(c),y:this.LINE_RADIUS*Math.sin(c)},x={x:this.LINE_RADIUS*Math.cos(y),y:this.LINE_RADIUS*Math.sin(y)},g=Math.atan2(f.y,f.x),v=Math.atan2(x.y,x.x),M=Math.abs(x.y-f.y),S=Math.abs(x.x-f.x),m=void 0,I=void 0,B=void 0,E=[];if(this.bB={h:0,w:0,x:0,y:0},M>S)if(f.x>0){this.bB.x=Math.min(f.x,x.x)+this.rx,this.bB.y=Math.min(f.y,x.y)+this.ry,this.bB.w=Math.max(Math.max(f.x,x.x),this.LINE_RADIUS)+this.rx-this.bB.x+1,this.bB.h=-this.bB.y+Math.max(Math.max(f.y,x.y))+this.ry+1,this.constrainBB(h);var P=this.bB&&h.getImageData(this.bB.x,this.bB.y,this.bB.w,this.bB.h),_=this.bB&&o.getImageData(this.bB.x,this.bB.y,this.bB.w,this.bB.h);if(P)for(var R=0;R0;R--){var A;L=this.LINE_RADIUS*this.LINE_RADIUS-(R+this.bB.y-this.ry)*(R+this.bB.y-this.ry),O=4*((A=Math.round(-Math.sqrt(L)-(this.bB.x-this.rx)))+R*P.width)-4;if((N=(w=this.getPixelData(_,O,P,m)).redPix)!==(m=w.redPixOld))if((D=Math.atan2(R+this.bB.y-this.ry,A+this.bB.x-this.rx))<=0&&(D+=2*Math.PI),g<=0&&(g+=2*Math.PI),v<=0&&(v+=2*Math.PI),null==I)I=(D-g)/(v-g)-.5;else if(null==B){b.call(this,I,B=(D-g)/(v-g)-.5,E);break}void 0!==I&&E.push(w.pixColor),m=N}}else if(f.y<0){this.bB.x=Math.min(Math.min(f.x,x.x),this.LINE_RADIUS)+this.rx,this.bB.w=Math.max(f.x,x.x)+this.rx-this.bB.x+1,this.bB.y=Math.min(Math.min(f.y,x.y),-this.LINE_RADIUS)+this.ry,this.bB.h=Math.max(f.y,x.y)+this.ry-this.bB.y+1,this.constrainBB(h);P=this.bB&&h.getImageData(this.bB.x,this.bB.y,this.bB.w+1,this.bB.h+1),_=this.bB&&o.getImageData(this.bB.x,this.bB.y,this.bB.w+1,this.bB.h+1);if(P)for(R=0;R0;R--){var T,w,N;L=this.LINE_RADIUS*this.LINE_RADIUS-(R+this.bB.x-this.rx)*(R+this.bB.x-this.rx),O=4*(R+(T=Math.round(Math.sqrt(L)-this.bB.y+this.ry)-1)*P.width)-4;if((N=(w=this.getPixelData(_,O,P,m)).redPix)!==(m=w.redPixOld)){D=Math.atan2(T+this.bB.y-this.ry,R+this.bB.x-this.rx);if(null==I)I=(D-g)/(v-g)-.5;else if(null==B){b.call(this,I,B=(D-g)/(v-g)-.5,E);break}}void 0!==I&&E.push(w.pixColor),m=N}}n[s.CAMERA][s.LINE]={},n[s.CAMERA][s.LINE][s.INFO]=[this.line,this.lineWidth],n[s.CAMERA][s.LINE][s.COLOR]=this.lineColor,n[s.CAMERA][s.LINE][s.NUMBER]=0===this.lineWidth?0:1}if(this.colorEnabled){this.color=[];var k=this.AOV*this.BLOBSIZE/100;c=(-k/2+2*Math.PI)%(2*Math.PI),y=(k/2+2*Math.PI)%(2*Math.PI);var C=this.LINE_RADIUS+(this.MAX_CAM_Y-this.LINE_RADIUS)*(100-this.BLOBSIZE)/200,U=C+(this.MAX_CAM_Y-this.LINE_RADIUS)*this.BLOBSIZE/100,G=(f={x:C*Math.cos(c),y:C*Math.sin(c)},x={x:C*Math.cos(y),y:C*Math.sin(y)},{x:U*Math.cos(c),y:U*Math.sin(c)}),F={x:U*Math.cos(y),y:U*Math.sin(y)};this.bB={h:0,w:0,x:0,y:0};var V={x:f.x,y:f.y,rx:0,ry:0};r.transform(u.pose,V),this.rect.p1=V,V={x:G.x,y:G.y,rx:0,ry:0},r.transform(u.pose,V),this.rect.p2=V,V={x:F.x,y:F.y,rx:0,ry:0},r.transform(u.pose,V),this.rect.p3=V,V={x:x.x,y:x.y,rx:0,ry:0},r.transform(u.pose,V),this.rect.p4=V,this.bB.x=Math.min(this.rect.p1.rx,this.rect.p2.rx,this.rect.p3.rx,this.rect.p4.rx),this.bB.y=Math.min(this.rect.p1.ry,this.rect.p2.ry,this.rect.p3.ry,this.rect.p4.ry),this.bB.w=Math.max(this.rect.p1.rx,this.rect.p2.rx,this.rect.p3.rx,this.rect.p4.rx)-this.bB.x,this.bB.h=Math.max(this.rect.p1.ry,this.rect.p2.ry,this.rect.p3.ry,this.rect.p4.ry)-this.bB.y,this.constrainBB(h);P=this.bB&&h.getImageData(this.bB.x,this.bB.y,this.bB.w,this.bB.h),_=this.bB&&o.getImageData(this.bB.x,this.bB.y,this.bB.w,this.bB.h);var H=$("#objectLayer")[0].getContext("2d",{willReadFrequently:!0});H.restore(),H.save();var X=d.SimulationRoberta.Instance.scale,K=void 0;try{K=this.bB&&H.getImageData(Math.round(this.bB.x*X),Math.round(this.bB.y*X),Math.round(this.bB.w*X),Math.round(this.bB.h*X))}catch(t){}var q=0,Y=0,W=0,j=K?K.data.length/P.data.length:0;if(P){for(R=0;R '),this.lineEnabled&&(t+="
"+a.round(this.line,0)+"
"+this.lineWidth+"
 
'),t},i.prototype.getPixelData=function(t,i,e,s){if(255===t.data[i+3])for(var r=i;r '; + } if (this.lineEnabled) { myLabel += '
 
' + - '
 
'; } return myLabel; diff --git a/OpenRobertaWeb/src/app/simulation/simulationLogic/robot.txt4.ts b/OpenRobertaWeb/src/app/simulation/simulationLogic/robot.txt4.ts index 6b1ef99f69..616fbd65e3 100644 --- a/OpenRobertaWeb/src/app/simulation/simulationLogic/robot.txt4.ts +++ b/OpenRobertaWeb/src/app/simulation/simulationLogic/robot.txt4.ts @@ -36,48 +36,67 @@ export default class RobotTxt4 extends RobotBaseMobile { this.led = new Txt4RGBLed(this.id, { x: 0, y: 0 }, true, null, 3); let sensors: object = configuration['SENSORS']; for (const c in sensors) { - switch (sensors[c]['TYPE']) { - case 'TXT_CAMERA': - this[c] = new Txt4CameraSensor(new Pose(0, 0, 0), (2 * Math.PI) / 5, sensors[c]['COLOURSIZE']); - break; - case 'INFRARED': - this[c] = new Txt4InfraredSensors(c, { x: 14, y: 0 }); - break; - case 'ULTRASONIC': { - let mySensors = []; - let txt4 = this; - Object.keys(this).forEach((x) => { - if (txt4[x] && txt4[x] instanceof DistanceSensor) { - mySensors.push(txt4[x]); + if (sensors[c]['TYPE']) { + switch (sensors[c]['TYPE']) { + case 'TXT_CAMERA': + let resolution: Array = sensors[c]['RESOLUTION'].split('x'); + let colourSize: number = 0; + let lineWidth: number = 0; + let detectors = sensors[c]['SUBCOMPONENTS']; + for (let detector in detectors) { + if (detectors[detector]['TYPE'] && detectors[detector]['TYPE'] === 'CAMERA_COLORDETECTOR') { + let xSize: number = detectors[detector]['XEND'] - detectors[detector]['XSTART']; + let ySize: number = detectors[detector]['YEND'] - detectors[detector]['YSTART']; + colourSize = ((xSize * 100) / resolution[0] + (ySize * 100) / resolution[1]) / 2; + } + if (detectors[detector]['TYPE'] && detectors[detector]['TYPE'] === 'CAMERA_LINE') { + let min: number = detectors[detector]['MINIMUM']; + let max: number = detectors[detector]['MAXIMUM']; + lineWidth = max - min; + } } - }); - const ord = mySensors.length + 1; - const num = Object.keys(sensors).filter((port) => sensors[port]['TYPE'] == 'ULTRASONIC').length; - let position: Pose = new Pose(this.chassis.geom.x + this.chassis.geom.w, 0, 0); - if (num == 3) { - if (ord == 1) { - position = new Pose(this.chassis.geom.h / 2, -this.chassis.geom.h / 2, -Math.PI / 4); - } else if (ord == 2) { - position = new Pose(this.chassis.geom.h / 2, this.chassis.geom.h / 2, Math.PI / 4); - } - } else if (num % 2 === 0) { - switch (ord) { - case 1: - position = new Pose(this.chassis.geom.x + this.chassis.geom.w, -this.chassis.geom.h / 2, -Math.PI / 4); - break; - case 2: - position = new Pose(this.chassis.geom.x + this.chassis.geom.w, this.chassis.geom.h / 2, Math.PI / 4); - break; - case 3: - position = new Pose(this.chassis.geom.x, -this.chassis.geom.h / 2, (-3 * Math.PI) / 4); - break; - case 4: - position = new Pose(this.chassis.geom.x, this.chassis.geom.h / 2, (3 * Math.PI) / 4); - break; + // TODO add and evaluate min max line width + this[c] = new Txt4CameraSensor(new Pose(0, 0, 0), (2 * Math.PI) / 5, colourSize, lineWidth); + break; + case 'INFRARED': + this[c] = new Txt4InfraredSensors(c, { x: 14, y: 0 }); + break; + case 'ULTRASONIC': { + let mySensors = []; + let txt4 = this; + Object.keys(this).forEach((x) => { + if (txt4[x] && txt4[x] instanceof DistanceSensor) { + mySensors.push(txt4[x]); + } + }); + const ord = mySensors.length + 1; + const num = Object.keys(sensors).filter((port) => sensors[port]['TYPE'] == 'ULTRASONIC').length; + let position: Pose = new Pose(this.chassis.geom.x + this.chassis.geom.w, 0, 0); + if (num == 3) { + if (ord == 1) { + position = new Pose(this.chassis.geom.h / 2, -this.chassis.geom.h / 2, -Math.PI / 4); + } else if (ord == 2) { + position = new Pose(this.chassis.geom.h / 2, this.chassis.geom.h / 2, Math.PI / 4); + } + } else if (num % 2 === 0) { + switch (ord) { + case 1: + position = new Pose(this.chassis.geom.x + this.chassis.geom.w, -this.chassis.geom.h / 2, -Math.PI / 4); + break; + case 2: + position = new Pose(this.chassis.geom.x + this.chassis.geom.w, this.chassis.geom.h / 2, Math.PI / 4); + break; + case 3: + position = new Pose(this.chassis.geom.x, -this.chassis.geom.h / 2, (-3 * Math.PI) / 4); + break; + case 4: + position = new Pose(this.chassis.geom.x, this.chassis.geom.h / 2, (3 * Math.PI) / 4); + break; + } } + this[c] = new UltrasonicSensor(c, position.x, position.y, position.theta, 400); // see https://www.fischertechnik.de/de-de/schulen/lernmaterial/sekundarstufe-programmieren/stem-coding-competition + break; } - this[c] = new UltrasonicSensor(c, position.x, position.y, position.theta, 400); // see https://www.fischertechnik.de/de-de/schulen/lernmaterial/sekundarstufe-programmieren/stem-coding-competition - break; } } } diff --git a/RobotFischertechnik/src/main/resources/txt4/configuration.default.xml b/RobotFischertechnik/src/main/resources/txt4/configuration.default.xml index 03f091241f..2219cb441d 100644 --- a/RobotFischertechnik/src/main/resources/txt4/configuration.default.xml +++ b/RobotFischertechnik/src/main/resources/txt4/configuration.default.xml @@ -2,17 +2,15 @@ C + 320x240 USB1 - - L - 0 - 320 - 60 - 80 - 3 - 30 - 100 + + F + 135 + 185 + 95 + 145