public void testHexEncoderWithString() { String someText = "This is some text\nwith a newline."; String hexText = Encoder.hexEncode(someText); String result = Encoder.hexDecodeToString(hexText); assertEquals(someText, result); }
@Test public void testLinearDependance() { byte[] segment = new byte[1000]; new Random().nextBytes(segment); Decoder decoder = createDecoder(segment.length, 10); byte[] packet = new byte[10 + segment.length / 10]; Encoder encoder = createEncoder(segment, 0, segment.length, 10); encoder.getPacket(packet, 0); decoder.addPacket(packet, 0); decoder.addPacket(packet, 0); assertEquals(1, decoder.getRank()); while (!decoder.isDecoded()) { byte[] packet2 = new byte[10 + segment.length / 10]; encoder.getPacket(packet2, 0); decoder.addPacket(packet2, 0); } byte[] decodedSegment = new byte[segment.length]; decoder.getSegment(decodedSegment, 0); assertArrayEquals(segment, decodedSegment); }
/** * This function is run when the robot is first started up and should be used for any * initialization code. */ public void robotInit() { black = new Jaguar(4, 1); red = new Jaguar(4, 2); leftEncoder = new Encoder(4, 5); rightEncoder = new Encoder(6, 7); left = new Joystick(1); right = new Joystick(2); gamePad = new Joystick(3); watchdog = Watchdog.getInstance(); dsLCD = DriverStationLCD.getInstance(); photoreceptorL = new DigitalInput(4, 1); photoreceptorM = new DigitalInput(4, 2); photoreceptorR = new DigitalInput(4, 3); camera = AxisCamera.getInstance(); driveMode = 0; // 0 = Tank; 1 = Arcade; 2 = Kaj driveToggle = false; cruiseControl = false; camera.writeResolution(AxisCamera.ResolutionT.k160x120); camera.writeWhiteBalance(AxisCamera.WhiteBalanceT.hold); camera.writeExposureControl(AxisCamera.ExposureT.hold); camera.writeExposurePriority(AxisCamera.ExposurePriorityT.frameRate); leftEncoder.start(); rightEncoder.start(); }
@Test public void testTooManyPackets() { byte[] segment = new byte[20000]; new Random().nextBytes(segment); Decoder decoder = createDecoder(segment.length, 20); Encoder encoder = createEncoder(segment, 0, segment.length, 20); while (!decoder.isDecoded()) { byte[] packet = new byte[20 + segment.length / 20]; encoder.getPacket(packet, 0); decoder.addPacket(packet, 0); } for (int i = 0; i < 1000; i++) { byte[] packet = new byte[20 + segment.length / 20]; encoder.getPacket(packet, 0); decoder.addPacket(packet, 0); } }
private void alternateField( NamedList docSummaries, SolrParams params, Document doc, String fieldName) { String alternateField = params.getFieldParam(fieldName, HighlightParams.ALTERNATE_FIELD); if (alternateField != null && alternateField.length() > 0) { IndexableField[] docFields = doc.getFields(alternateField); List<String> listFields = new ArrayList<String>(); for (IndexableField field : docFields) { if (field.binaryValue() == null) listFields.add(field.stringValue()); } String[] altTexts = listFields.toArray(new String[listFields.size()]); if (altTexts != null && altTexts.length > 0) { Encoder encoder = getEncoder(fieldName, params); int alternateFieldLen = params.getFieldInt(fieldName, HighlightParams.ALTERNATE_FIELD_LENGTH, 0); List<String> altList = new ArrayList<String>(); int len = 0; for (String altText : altTexts) { if (alternateFieldLen <= 0) { altList.add(encoder.encodeText(altText)); } else { altList.add( len + altText.length() > alternateFieldLen ? encoder.encodeText(new String(altText.substring(0, alternateFieldLen - len))) : encoder.encodeText(altText)); len += altText.length(); if (len >= alternateFieldLen) break; } } docSummaries.add(fieldName, altList); } } }
public static void init() { // BEGIN AUTOGENERATED CODE, SOURCE=ROBOTBUILDER ID=CONSTRUCTORS driveLeftSpeedController = new Talon(9); LiveWindow.addActuator("Drive", "Left Speed Controller", (Talon) driveLeftSpeedController); driveRightSpeedController = new Talon(8); LiveWindow.addActuator("Drive", "Right Speed Controller", (Talon) driveRightSpeedController); driveRobotDrive21 = new RobotDrive(driveLeftSpeedController, driveRightSpeedController); driveRobotDrive21.setSafetyEnabled(true); driveRobotDrive21.setExpiration(0.1); driveRobotDrive21.setSensitivity(0.5); driveRobotDrive21.setMaxOutput(1.0); driveLeftEncoder = new Encoder(2, 3, false, EncodingType.k4X); LiveWindow.addSensor("Drive", "LeftEncoder", driveLeftEncoder); driveLeftEncoder.setDistancePerPulse(1.0); driveLeftEncoder.setPIDSourceType(PIDSourceType.kRate); driveRightEncoder = new Encoder(0, 1, false, EncodingType.k4X); LiveWindow.addSensor("Drive", "RightEncoder", driveRightEncoder); driveRightEncoder.setDistancePerPulse(1.0); driveRightEncoder.setPIDSourceType(PIDSourceType.kRate); // END AUTOGENERATED CODE, SOURCE=ROBOTBUILDER ID=CONSTRUCTORS }
public void convertWavToMP3(String filepathToConvert, String convertedFilePath) { Encoder wavToMp3Converter = new Encoder(); EncodingAttributes att = new EncodingAttributes(); AudioAttributes audioAtt = new AudioAttributes(); String codecs[] = null; String formats[] = null; try { formats = wavToMp3Converter.getSupportedDecodingFormats(); } catch (EncoderException e) { e.printStackTrace(); } try { codecs = wavToMp3Converter.getAudioEncoders(); } catch (EncoderException e) { e.printStackTrace(); } int mp3CodecIndex = -1; /*for(int i=codecs.length; i>0; i--) { if(codecs[i].compareTo("") == 0) { mp3CodecIndex = i; break; } }*/ audioAtt.setVolume(255); audioAtt.setSamplingRate(new Integer(this.getWavTagReader().sampleRate)); audioAtt.setChannels(new Integer(wavTagReader.numOfChannels)); audioAtt.setBitRate( new Integer( this.wavTagReader.sampleRate * this.wavTagReader.bitsPerSample * this.wavTagReader.numOfChannels)); audioAtt.setCodec("libmp3lame"); att.setAudioAttributes(audioAtt); att.setFormat("mp3"); att.setOffset(new Float((float) 0)); att.setVideoAttributes(null); // att.setDuration(new Float((float)100)); try { wavToMp3Converter.encode( new File(filepathToConvert), new File(convertedFilePath), att, new EncoderProgressListener() { @Override public void sourceInfo(MultimediaInfo multimediaInfo) {} @Override public void progress(int i) {} @Override public void message(String s) {} }); } catch (EncoderException e) { e.getMessage(); e.getCause(); } }
public void testCompressionAndBase64EncoderWithString() { String someText = "This is some text\nwith a newline."; String b64Text = Encoder.compressAndBase64Encode(someText); String result = Encoder.decodeBase64AndDecompress(b64Text); assertEquals(someText, result); }
@Test public void test() { byte[] segment = new byte[20000]; new Random().nextBytes(segment); Decoder decoder = createDecoder(segment.length, 20); Encoder encoder = createEncoder(segment, 0, segment.length, 20); while (!decoder.isDecoded()) { byte[] packet = new byte[20 + segment.length / 20]; encoder.getPacket(packet, 0); decoder.addPacket(packet, 0); } byte[] decodedSegment = new byte[segment.length]; decoder.getSegment(decodedSegment, 0); assertArrayEquals(segment, decodedSegment); }
public void testEncodeInt64() throws IOException { final long[] input = new long[] {0L, 9223372036854775807L, -9223372036854775808L, -1L}; final byte[] expected = new byte[] { (byte) 0x00, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xfe, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0x01 }; ByteArrayOutputStream output = new ByteArrayOutputStream(expected.length); Encoder e = new Encoder(output); for (long s64 : input) { e.int64(s64); } Assert.assertArrayEquals(expected, output.toByteArray()); }
public void testEncodeUint64() throws IOException { final long[] input = new long[] {0L, 0x0123456789abcdefL, 0xfedcba9876543210L}; final byte[] expected = new byte[] { (byte) 0x00, (byte) 0xff, (byte) 0x01, (byte) 0x23, (byte) 0x45, (byte) 0x67, (byte) 0x89, (byte) 0xab, (byte) 0xcd, (byte) 0xef, (byte) 0xff, (byte) 0xfe, (byte) 0xdc, (byte) 0xba, (byte) 0x98, (byte) 0x76, (byte) 0x54, (byte) 0x32, (byte) 0x10 }; ByteArrayOutputStream output = new ByteArrayOutputStream(expected.length); Encoder e = new Encoder(output); for (long u64 : input) { e.uint64(u64); } Assert.assertArrayEquals(expected, output.toByteArray()); }
public void testEncodeInt32() throws IOException { final int[] input = new int[] {0, 2147483647, -2147483648, -1}; final byte[] expected = new byte[] { (byte) 0x00, (byte) 0xf0, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xfe, (byte) 0xf0, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0x01 }; ByteArrayOutputStream output = new ByteArrayOutputStream(expected.length); Encoder e = new Encoder(output); for (int s32 : input) { e.int32(s32); } Assert.assertArrayEquals(expected, output.toByteArray()); }
public void encode(final Object value, final Writer out) throws IOException { @SuppressWarnings("unchecked") final Map<Object, Object> map = (Map<Object, Object>) value; final Set<Map.Entry<Object, Object>> entrySet = map.entrySet(); final Iterator<Map.Entry<Object, Object>> iterator = entrySet.iterator(); Encoder lastEncoder = null; Class<?> lastType = null; out.write('{'); while (iterator.hasNext()) { try { final Map.Entry<Object, Object> entry = iterator.next(); final Object entryValue = entry.getValue(); final Class<?> type = entryValue.getClass(); final Encoder enc = type == lastType ? lastEncoder : getEncoder(type); out.write("\"" + entry.getKey().toString() + "\""); out.write(':'); enc.encode(entryValue, out); lastType = type; lastEncoder = enc; } catch (IntrospectionException ie) { throw new IOException(ie); } if (iterator.hasNext()) { out.write(','); } } out.write('}'); }
public void encode(final Object value, final Writer out) throws IOException { final Iterator<? extends Object> iterator = ((Iterable<?>) value).iterator(); Encoder lastEncoder = null; Class<?> lastType = null; out.write('['); while (iterator.hasNext()) { try { final Object instance = iterator.next(); final Class<?> type = instance.getClass(); final Encoder enc = type == lastType ? lastEncoder : getEncoder(type); enc.encode(instance, out); lastType = type; lastEncoder = enc; } catch (IntrospectionException ie) { throw new IOException(ie); } if (iterator.hasNext()) { out.write(','); } } out.write(']'); }
public static void main(String[] args) { try { BufferedImage img = ImageIO.read(new File(args[0])); BufferedImage intImg = new BufferedImage(img.getWidth(), img.getHeight(), BufferedImage.TYPE_INT_RGB); Graphics2D g2 = intImg.createGraphics(); g2.drawImage(img, null, null); Encoder enc = new Encoder(); // long startTime = System.nanoTime(); ByteBuffer frame = enc.encodeFrame(intImg, true); // long endTime = System.nanoTime(); // long time = (endTime - startTime) / 1000000; // System.out.print(String.format("Encode time %d ms\n", time)); FileOutputStream out = new FileOutputStream(args[1] + "Key.vp8"); out.getChannel().write(frame); out.close(); frame = enc.encodeFrame(intImg, false); out = new FileOutputStream(args[1] + "Inter.vp8"); out.getChannel().write(frame); out.close(); System.out.println("Success!"); } catch (IOException ex) { ex.printStackTrace(); throw new RuntimeException(ex); } }
public static void mergeDoAbc(List<Decoder> decoders, Encoder encoder) { // final long time = System.currentTimeMillis(); encoder.enablePeepHole(); for (int i = 0, n = decoders.size(); i < n; i++) { Decoder decoder = decoders.get(i); if (decoder == null) { continue; } encoder.useDecoder(i, decoder); decoder.methodInfo.decodeAll(encoder, decoder.in); decoder.metadataInfo.decodeAll(encoder, decoder.in); decoder.classInfo.decodeInstances(encoder, decoder.in); decoder.classInfo.decodeClasses(encoder, decoder.in); decoder.scriptInfo.decodeAll(encoder, decoder.in); decoder.methodBodies.decodeAll(encoder, decoder.in); encoder.endDecoder(decoder); } // final long l = System.currentTimeMillis() - time; // System.out.print("\nmerge: "); // System.out.print(l); }
public void encode(Encoder encoder) { super.encode(encoder); encoder.encodeInt(int2); encoder.encodeString(string2); encoder.encodeInt(buffer2.remaining()); encoder.encodeKnownLengthBuffer(buffer2); }
public void enable() { rightEncoder.reset(); leftEncoder.reset(); rightEncoder.start(); leftEncoder.start(); // pidRight.enable(); // pidLeft.enable(); } // end enable
public void testB64WithBigness() { String someText = LoadCatalogToString.THE_CATALOG; String b64Text = Encoder.compressAndBase64Encode(someText); String result = Encoder.decodeBase64AndDecompress(b64Text); assertEquals(someText, result); }
// starts encoders public DriveTrain() { leftEncoder.start(); rightEncoder.start(); gyro.reset(); Preferences p = Preferences.getInstance(); if (!p.containsKey("DriveTrainShootLimitVoltage")) { p.putDouble("DriveTrainShootLimitVoltage", kDefaultShootLimitVoltage); } if (!p.containsKey("DriveTrainQuickTurnP")) { p.putDouble("DriveTrainQuickTurnP", kDefaultQuickTurnProportion); } if (!p.containsKey("DriveTrainQuickTurnDeadband")) { p.putDouble("DriveTrainQuickTurnDeadband", kDefaultQuickTurnDeadband); } if (!p.containsKey("DriveTrainReverseDirection")) { p.putBoolean("DriveTrainReverseDirection", kDefaultReverseDirection); } if (!p.containsKey("LeftEncoderRatio")) { p.putDouble("LeftEncoderRatio", 4.875); } if (!p.containsKey("RightEncoderRatio")) { p.putDouble("RightEncoderRatio", 4.875); } if (!p.containsKey("Encoder_kP")) { p.putDouble("Encoder_kP", 0.05); } if (!p.containsKey("OutputMin")) { p.putDouble("OutputMin", .2); } if (!p.containsKey("DistBuffer")) { p.putDouble("DistBuffer", 1); } if (!p.containsKey("Gyro_kP")) { p.putDouble("Gyro_kP", 1 / 18); } if (!p.containsKey("AngleBuffer")) { p.putDouble("AngleBuffer", 4.5); } if (!p.containsKey("AutoDist_0")) { p.putDouble("AutoDist_0", 0.0); } if (!p.containsKey("AutoDist_1")) { p.putDouble("AutoDist_1", 0.0); } if (!p.containsKey("AutoDist_2")) { p.putDouble("AutoDist_2", 0.0); } if (!p.containsKey("AutoDist_3")) { p.putDouble("AutoDist_3", 0.0); } if (!p.containsKey("ShiftWhenTurningThreshold")) { p.putDouble("ShiftWhenTurningThreshold", 0.5); } if (!p.containsKey("ShiftWhenTurningDelay")) { p.putDouble("ShiftWhenTurningDelay", 1.5); } } // end constructor
public void write(Encoder encoder, ResolvedInclude value) throws Exception { encoder.writeString(value.getInclude()); if (value.getFile() == null) { encoder.writeBoolean(false); } else { encoder.writeBoolean(true); fileSerializer.write(encoder, value.getFile()); } }
public void disable() { setSetpoint(0.0); // pidRight.disable(); // pidLeft.disable(); leftMotor.set(0.0); rightMotor.set(0.0); rightEncoder.reset(); leftEncoder.reset(); } // end disable
// basic arcadeDrive: y=forward/backward speed, x=left/right speed public void arcadeDrive(double y, double x) { SmartDashboard.putNumber("RightEncoder", rightEncoder.get()); SmartDashboard.putNumber("LeftEncoder", leftEncoder.get()); Preferences p = Preferences.getInstance(); final boolean kReverseDirection = p.getBoolean("DriveTrainReverseDirection", false); robotDrive.setInvertedMotor(RobotDrive.MotorType.kRearLeft, kReverseDirection); robotDrive.setInvertedMotor(RobotDrive.MotorType.kRearRight, kReverseDirection); robotDrive.arcadeDrive(y, x); } // end arcadeDrive
public double getRPM() { if (Timer.getFPGATimestamp() > RPMUpdatePeriod + encoderMarkTime) { double encoderCPS = (enc.get() - encoderMarkCounts) / (Timer.getFPGATimestamp() - encoderMarkTime); encoderRPM = (encoderCPS * 60) / 16; encoderMarkCounts = enc.get(); encoderMarkTime = Timer.getFPGATimestamp(); } return encoderRPM; }
@Test public final void testNullEncode() throws IOException { Encoder encoder = createEncoder(); ByteArrayOutputStream bytes = new ByteArrayOutputStream(); try { encoder.encode(bytes, null); fail("null should throw NullPointerException"); } catch (NullPointerException expected) { } }
public void enable() { rightEncoder.reset(); leftEncoder.reset(); rightEncoder.start(); leftEncoder.start(); gyro.reset(); final boolean kReverseDirection = Preferences.getInstance().getBoolean("DriveTrainReverseDirection", false); robotDrive.setInvertedMotor(RobotDrive.MotorType.kRearLeft, kReverseDirection); robotDrive.setInvertedMotor(RobotDrive.MotorType.kRearRight, kReverseDirection); } // end enable
public void testEncodeBool() throws IOException { final boolean[] input = new boolean[] {true, false}; final byte[] expected = new byte[] {(byte) 0x01, (byte) 0x00}; ByteArrayOutputStream output = new ByteArrayOutputStream(expected.length); Encoder e = new Encoder(output); for (boolean bool : input) { e.bool(bool); } Assert.assertArrayEquals(expected, output.toByteArray()); }
public void testEncodeInt8() throws IOException { final byte[] input = new byte[] {0, 127, -128, -1}; final byte[] expected = new byte[] {(byte) 0x00, (byte) 0x7f, (byte) 0x80, (byte) 0xff}; ByteArrayOutputStream output = new ByteArrayOutputStream(expected.length); Encoder e = new Encoder(output); for (byte s8 : input) { e.int8(s8); } Assert.assertArrayEquals(expected, output.toByteArray()); }
public void testEncodeUint8() throws IOException { final short[] input = new short[] {0x00, 0x7f, 0x80, 0xff}; final byte[] expected = new byte[] {(byte) 0x00, (byte) 0x7f, (byte) 0x80, (byte) 0xff}; ByteArrayOutputStream output = new ByteArrayOutputStream(expected.length); Encoder e = new Encoder(output); for (short u8 : input) { e.uint8(u8); } Assert.assertArrayEquals(expected, output.toByteArray()); }
// END AUTOGENERATED CODE, SOURCE=ROBOTBUILDER ID=DECLARATIONS public static void init() { // BEGIN AUTOGENERATED CODE, SOURCE=ROBOTBUILDER ID=CONSTRUCTORS driveTrainLeftFront = new Talon(1, 1); LiveWindow.addActuator("Drive Train", "Left Front", (Talon) driveTrainLeftFront); driveTrainRightFront = new Talon(1, 2); LiveWindow.addActuator("Drive Train", "Right Front", (Talon) driveTrainRightFront); driveTrainLeftRear = new Talon(1, 3); LiveWindow.addActuator("Drive Train", "Left Rear", (Talon) driveTrainLeftRear); driveTrainRightRear = new Talon(1, 4); LiveWindow.addActuator("Drive Train", "Right Rear", (Talon) driveTrainRightRear); driveTrainRobotDrive = new RobotDrive( driveTrainLeftFront, driveTrainLeftRear, driveTrainRightFront, driveTrainRightRear); driveTrainRobotDrive.setSafetyEnabled(true); driveTrainRobotDrive.setExpiration(0.1); driveTrainRobotDrive.setSensitivity(0.5); driveTrainRobotDrive.setMaxOutput(1.0); driveTrainRobotDrive.setInvertedMotor(RobotDrive.MotorType.kFrontLeft, true); driveTrainRobotDrive.setInvertedMotor(RobotDrive.MotorType.kRearLeft, true); driveTrainRobotDrive.setInvertedMotor(RobotDrive.MotorType.kFrontRight, true); driveTrainRobotDrive.setInvertedMotor(RobotDrive.MotorType.kRearRight, true); armWheelsShaftMotor = new Talon(1, 5); LiveWindow.addActuator("Arm Wheels", "Shaft Motor", (Talon) armWheelsShaftMotor); platformMotor = new Talon(1, 6); LiveWindow.addActuator("Platform", "Motor", (Talon) platformMotor); platformShaftEncoder = new Encoder(1, 1, 1, 2, false, EncodingType.k4X); LiveWindow.addSensor("Platform", "Shaft Encoder", platformShaftEncoder); platformShaftEncoder.setDistancePerPulse(1.0); platformShaftEncoder.setPIDSourceParameter(PIDSourceParameter.kRate); platformShaftEncoder.start(); platformLimitSwitchFront = new DigitalInput(1, 3); LiveWindow.addSensor("Platform", "Limit Switch Front", platformLimitSwitchFront); platformLimitSwitchBack = new DigitalInput(1, 4); LiveWindow.addSensor("Platform", "Limit Switch Back", platformLimitSwitchBack); platformTestFrontTestLimitSwitch = new DigitalInput(1, 5); LiveWindow.addSensor( "Platform Test", "Front Test Limit Switch", platformTestFrontTestLimitSwitch); platformTestTestMotor = new Talon(1, 7); LiveWindow.addActuator("Platform Test", "Test Motor", (Talon) platformTestTestMotor); // END AUTOGENERATED CODE, SOURCE=ROBOTBUILDER ID=CONSTRUCTORS }