private Object interpretSensor(Sprite sprite) { Sensors sensor = Sensors.getSensorByValue(value); if (sensor.isObjectSensor) { return interpretObjectSensor(sensor, sprite); } else { return SensorHandler.getSensorValue(sensor); } }
/** * Draws a tile with its top left corner at the given coordinates. The tile edges have white * stripes. * * <p>The colors of the resulting images depent on getWhiteLineColor() and getEmptySpaceColor(); */ public void drawStandardTileAbsolute(int x, int y) { // draw white square over the full distance drawSquare(img, x, y, sensors.getTileSize(), getWhiteLineColor()); drawSquare(img, x + 1, y + 1, sensors.getTileSize() - 2, getWhiteLineColor()); // draws an 'inner' lightBrown2 square. drawFilledSquare(img, x + 2, y + 2, sensors.getTileSize() - 4, getEmptySpaceColor()); }
/** * Returns the light value at the given coordinate. * * @param x * @param y * @return int An integer between 0 and 1023 representing the light value. * @throws IllegalArgumentException When the x or y coordinates are not valid | * !sensors.isValid(x,y) */ public int getLightValue(int x, int y) { int correctedY = sensors.getMaxY() - y; if (sensors.isValid(x, correctedY)) { int clr = img.getRGB(x, correctedY); int lightValue = calculateLightValue(clr); // System.out.println("Lightsensor white-value: "+lightValue); return lightValue; } else { throw new IllegalArgumentException("X or Y out of bounds"); } }
/** * Basic constructor where only a Sensors object is needed. * * <p>Tiles will be found from the Sensors object * * @param sensors */ public VirtualLightSensor(Sensors sensors) { this.sensors = sensors; img = new BufferedImage(sensors.getMaxX() + 1, sensors.getMaxY() + 1, BufferedImage.TYPE_INT_RGB); setWhiteLineColor(STANDARD_WHITE_LINE_COLOR); setEmptySpaceColor(STANDARD_EMPTY_SPACE_COLOR); generateMap(); // try { // ImageIO.write(img, fileType, new File(destinationPath)); // } catch (IOException e) { // e.printStackTrace(); // } }
/** * Generates the map (an image) with the current colors. * * <p>'protected' for testing purposes. */ protected void generateMap() { for (Tile t : sensors.getTilesList()) { int barcode = t.getBarCode(); // System.out.println(barcode); drawStandardTile(t.getX(), sensors.getMaxYOfGrid() - t.getY()); if (barcode != -1) { // System.out.println("not -1"); Border northBorder = t.getBorderNorth(); if (northBorder == Border.CLOSED) { // System.out.println("North Border Closed"); drawHorizontalBarcode(t.getX(), sensors.getMaxYOfGrid() - t.getY(), barcode); } else { drawVerticalBarcode(t.getX(), sensors.getMaxYOfGrid() - t.getY(), barcode); } } } }
public Agent() { double temperature = 0; String action = null; @SuppressWarnings("resource") Scanner in = new Scanner(System.in); System.out.println("Please enter your surface temperature: "); temperature = in.nextFloat(); Sensors sensor1 = new Sensors(); sensor1.percept(temperature); double normal_temperature = 37.5; if (temperature > normal_temperature) { action = "It's hot."; } else { action = "It's cold."; } Actuators actuator1 = new Actuators(); actuator1.actions(action); }
private void handleCPPConfigRequest(CPPConfigRequestMsg msg) { Object logicalReference = msg.getLogicalReference(); String actualSource = msg.getActualSource(); boolean sourceExists = true; boolean dataTypeMatches = false; // the client already checks for duplicate mappings of logicalReferences, no need to check again // here // check to see if the source exists // this will need to be advanced text matching later try { System.out.println("logicalReference.class = " + logicalReference.getClass()); System.out.println("Found the sensor at index: " + Sensors.keywordMatcher(actualSource)); Entry<SensorType, Object> e = Sensors.getMatchedSensor(Sensors.keywordMatcher(actualSource)); if (e != null) { System.out.println("Sensor found has type: " + e.getKey() + ", " + e.getValue()); if (e.getValue() .equals(logicalReference.getClass())) { // not sure if this comparison is correct dataTypeMatches = true; System.out.println("data types matched!"); } else System.out.println("data types did not match."); } } catch (IndexOutOfBoundsException ex) { // means it couldn't find the sensor from the actualSource sourceExists = false; } // TODO send the message try { tcpSender.sendMessage( msg.getReplyAddr(), msg.getReplyPort(), new CPPConfigResponseMsg(logicalReference, actualSource, sourceExists, dataTypeMatches)); } catch (PharosException e) { e.printStackTrace(); } }
/** * Draws a tile with its top left corner at the given coordinates. The tile has L shaped white * stripes, with the corner of the L to the bottom right. */ public void drawBottomRightLTileAbsolute(int x, int y) { drawVerticalLineWithFaders( img, x + (sensors.getTileSize() / 2) - 2, y, sensors.getTileSize() / 2 + 2); drawHorizontalLineWithFaders( img, x, y + (sensors.getTileSize() / 2) - 2, (sensors.getTileSize() / 2) + 1); // Correction drawLine( img, x + (sensors.getTileSize() / 2) - 1, y + (sensors.getTileSize() / 2) - 2, x + (sensors.getTileSize() / 2), y + (sensors.getTileSize() / 2) - 2, WHITE); }
public int getRequiredResources() { int resources = Brick.NO_RESOURCES; if (leftChild != null) { resources |= leftChild.getRequiredResources(); } if (rightChild != null) { resources |= rightChild.getRequiredResources(); } if (type == ElementType.FUNCTION) { Functions functions = Functions.getFunctionByValue(value); switch (functions) { case ARDUINOANALOG: case ARDUINODIGITAL: resources |= Brick.BLUETOOTH_SENSORS_ARDUINO; break; case RASPIDIGITAL: resources |= Brick.SOCKET_RASPI; break; } } if (type == ElementType.SENSOR) { Sensors sensor = Sensors.getSensorByValue(value); switch (sensor) { case X_ACCELERATION: case Y_ACCELERATION: case Z_ACCELERATION: resources |= Brick.SENSOR_ACCELERATION; break; case X_INCLINATION: case Y_INCLINATION: resources |= Brick.SENSOR_INCLINATION; break; case COMPASS_DIRECTION: resources |= Brick.SENSOR_COMPASS; break; case LATITUDE: case LONGITUDE: case LOCATION_ACCURACY: case ALTITUDE: resources |= Brick.SENSOR_GPS; break; case FACE_DETECTED: case FACE_SIZE: case FACE_X_POSITION: case FACE_Y_POSITION: resources |= Brick.FACE_DETECTION; break; case NXT_SENSOR_1: case NXT_SENSOR_2: case NXT_SENSOR_3: case NXT_SENSOR_4: resources |= Brick.BLUETOOTH_LEGO_NXT; break; case PHIRO_FRONT_LEFT: case PHIRO_FRONT_RIGHT: case PHIRO_SIDE_LEFT: case PHIRO_SIDE_RIGHT: case PHIRO_BOTTOM_LEFT: case PHIRO_BOTTOM_RIGHT: resources |= Brick.BLUETOOTH_PHIRO; break; case DRONE_BATTERY_STATUS: case DRONE_CAMERA_READY: case DRONE_EMERGENCY_STATE: case DRONE_FLYING: case DRONE_INITIALIZED: case DRONE_NUM_FRAMES: case DRONE_RECORD_READY: case DRONE_RECORDING: case DRONE_USB_ACTIVE: case DRONE_USB_REMAINING_TIME: resources |= Brick.ARDRONE_SUPPORT; break; case NFC_TAG_ID: resources |= Brick.NFC_ADAPTER; break; default: } } if (type == ElementType.COLLISION_FORMULA) { resources |= Brick.COLLISION; } return resources; }
/** * Draws a tile at the given coordinate in the system where each tile represents 1 unit on both x * and y axis. This tile has L shaped white stripes, with the corner of the L to the bottom left. */ public void drawBottomLeftLTile(int x, int y) { drawBottomLeftLTileAbsolute(x * sensors.getTileSize(), y * sensors.getTileSize()); }
/** * Draws a tile at the given coordinate in the system where each tile represents 1 unit on both x * and y axis. This tile has L shaped white stripes, with the corner of the L to the top right. */ public void drawTopRightLTile(int x, int y) { drawTopRightLTileAbsolute(x * sensors.getTileSize(), y * sensors.getTileSize()); }
/** * Draws a tile at the given coordinate in the system where each tile represents 1 unit on both x * and y axis. This tile has a white stripe horizontally crossing it. */ public void drawHorizontallyCrossedTile(int x, int y) { drawHorizontallyCrossedTileAbsolute(x * sensors.getTileSize(), y * sensors.getTileSize()); }
/** * Draws a standard tile at the given coordinate in the system where each tile represents 1 unit * on both x and y axis. This tile has white stripes at its borders. */ public void drawStandardTile(int x, int y) { drawStandardTileAbsolute(x * sensors.getTileSize(), y * sensors.getTileSize()); }
/** * Draws a tile with its top left corner at the given coordinates. The tile has a white stripe * horizontally crossing it. */ public void drawHorizontallyCrossedTileAbsolute(int x, int y) { drawHorizontalLineWithFaders( img, x, y + (sensors.getTileSize() / 2) - 2, sensors.getTileSize()); }
/** * Draws a tile with its top left corner at the given coordinates. The tile has a white stripe * vertically crossing it. */ public void drawVerticallyCrossedTileAbsolute(int x, int y) { drawVerticalLineWithFaders(img, x + (sensors.getTileSize() / 2) - 2, y, sensors.getTileSize()); }
private com.relteq.sirius.jaxb.Sensor restoreSensor(Sensors db_sensor) throws TorqueException { com.relteq.sirius.jaxb.Sensor sensor = factory.createSensor(); sensor.setId(id2str(db_sensor.getId())); sensor.setLinkPosition(db_sensor.getLinkPosition()); sensor.setType(db_sensor.getType()); sensor.setOriginalId(db_sensor.getOriginalId()); if (null != db_sensor.getLaneNumber()) sensor.setLaneNumber(BigInteger.valueOf(db_sensor.getLaneNumber().longValue())); sensor.setHealthStatus(db_sensor.getHealthStatus()); sensor.setDisplayPosition(restorePosition(db_sensor.getDisplayGeometry())); if (null != db_sensor.getLinkId()) { com.relteq.sirius.jaxb.LinkReference lr = factory.createLinkReference(); lr.setId(id2str(db_sensor.getLinkId())); sensor.setLinkReference(lr); } sensor.setParameters(restoreParameters(db_sensor)); List<com.relteq.sirius.jaxb.Table> table_l = restoreTables(db_sensor); if (null != table_l && !table_l.isEmpty()) { sensor.setTable(table_l.get(0)); if (1 < table_l.size()) logger.warn("Sensor " + db_sensor.getId() + " has " + table_l.size() + " tables"); } return sensor; }