Motor recuperarMotor() { Motor m = new Motor(); m.fabricante = "GM"; m.numMarcha = 5; m.potencia = 2; return m; }
public void setSpeed(OutputStream out, byte[] buf, int len) { int leftSign = 1; int rightSign = 1; int p = 2; if (buf[p] == '-') { // if input is '-', move right one place leftSign = -1; p++; } int leftPwr = 0; while ('0' <= buf[p] && buf[p] <= '9') leftPwr = leftPwr * 10 + (buf[p++] - '0'); // accumulate the decimal value if (leftPwr > H_MAX_POWER) leftPwr = H_MAX_POWER; // stay in range leftPwr = leftSign * leftPwr; // assert(buf[p] == ','); p++; if (buf[p] == '-') { rightSign = -1; p++; } int rightPwr = 0; while ('0' <= buf[p] && buf[p] <= '9') rightPwr = rightPwr * 10 + (buf[p++] - '0'); if (rightPwr > H_MAX_POWER) rightPwr = H_MAX_POWER; // stay in range rightPwr = rightSign * rightPwr; // assert(buf[p] == 0); // the buffer is null-terminated p++; leftMotor.setPower((leftPwr * 16) / H_MAX_POWER); rightMotor.setPower((rightPwr * 16) / H_MAX_POWER); writeCRLF(out, "d"); }
public static void main(String[] args) { LoggingFactory.getInstance().configure(); LoggingFactory.getInstance().setLevel(Level.DEBUG); try { // FIXME !!! - don't use Adafruit's library - do your own stepper control through "pure" // MRLComm.ino AdafruitMotorShield fruity = (AdafruitMotorShield) Runtime.createAndStart("fruity", "AdafruitMotorShield"); Runtime.createAndStart("gui01", "GUIService"); fruity.connect("COM3"); Motor motor1 = fruity.createDCMotor(4); motor1.move(0.4f); // create a 200 step stepper on adafruitsheild port 1 Stepper stepper1 = fruity.createStepper(200, 1); // FIXME - needs to be cleaned up - tear down fruity.releaseStepper(stepper1.getName()); // Runtime.createAndStart("python", "Python"); } catch (Exception e) { Logging.logError(e); } }
public void releaseDCMotor(String motorName) { if (!motors.containsKey(motorName)) { error("motor %s does not exist", motorName); } Motor m = motors.remove(motorName); m.releaseService(); deviceNameToNumber.remove(motorName); }
@Test public void testSetMotorPosition() { try { motor.setPosition(1.0); } catch (MotorPositionOutOfBounds e) { fail("The motor attempted to move out of bounds"); } assertEquals(1.0, motor.getPostion(), 0.001); }
public void move() { if (last_move_time == null || last_move_time.doubleValue() < world.time) { last_move_time = new Double(world.time); double max_dist, dist_right, dist_left, theta, x, y, dist_diff; double delta_theta, turn_radius, new_theta, new_x, new_y; Location location; Orientation orientation; orientation = orientation(); location = location(); max_dist = max_speed / world.ticks_per_second; dist_right = right_motor.output() * max_dist; dist_left = left_motor.output() * max_dist; theta = orientation.theta; x = location.x; y = location.y; old_location.x = x; old_location.y = y; dist_diff = dist_right - dist_left; // System.out.println("dist_diff: " + dist_diff); delta_theta = dist_diff / wheel_base; if (Math.abs(dist_diff) < .0001) { turn_radius = 0.0; } else { turn_radius = (dist_right / delta_theta) - (wheel_base / 2); } // System.out.println("turn_radius: " + turn_radius); new_theta = theta + delta_theta; if (turn_radius == 0.0) { // System.out.println("turn_radius == 0"); new_x = x + Math.cos(theta) * dist_left; new_y = y + Math.sin(theta) * dist_left; } else { // System.out.println("new_theta= " + new_theta + " theta= " + theta); new_x = x + ((Math.sin(new_theta) - Math.sin(theta)) * turn_radius); new_y = y - ((Math.cos(new_theta) - Math.cos(theta)) * turn_radius); } orientation.theta = new_theta; location.x = new_x; location.y = new_y; maybe_fire_guns(); } }
/** * creates a DC Motor on port 1,2,3, or 4 * * @param motorNum * @throws Exception */ public Motor createDCMotor(Integer motorNum) throws Exception { if (motorNum == null || motorNum < 1 || motorNum > 4) { error(String.format("motor number should be 1,2,3,4 not %d", motorNum)); return null; } String motorName = String.format("%s_m%d", getName(), motorNum); deviceNameToNumber.put(motorName, motorNum); Motor m = new Motor(motorName); m.startService(); motors.put(motorName, m); m.broadcastState(); m.setController(this); return m; }
@Override public boolean motorAttach( String motorName, String type, Integer pwrPin, Integer dirPin, Integer encoderPin) { ServiceInterface sw = Runtime.getService(motorName); if (!sw.isLocal()) { error("motor needs to be in same instance of mrl as controller"); return false; } Motor m = (Motor) sw; m.setController(this); m.broadcastState(); return true; }
public void run() { motor_left.resetTachoCount(); motor_left.regulateSpeed(true); Movement.motor_left.smoothAcceleration(true); int previousCommandCount = -1; while (true) { if (Movement.getCommandCount() == previousCommandCount) { try { Thread.sleep(10); } catch (InterruptedException e) { } continue; } previousCommandCount = Movement.getCommandCount(); setToAngle(ControlCentre.getTargetSteeringAngleLeft()); int new_angle = getToAngle(); if (new_angle < 10) LCD.drawString(" ", 8, 1); else if (new_angle < 100) LCD.drawString(" ", 9, 1); LCD.drawString(Integer.toString(new_angle), 7, 1); LCD.drawString("R", 11, 1); int cur_angle = getCurrentSteeringAngle(); double delta = new_angle - cur_angle; final double C = Movement.rotConstant; double turn_angle = 0; if (Math.abs(delta) < thresholdAngle / 2.0) { continue; } else if (Math.abs(delta) >= thresholdAngle / 2.0 && Math.abs(delta) < thresholdAngle) { delta = thresholdAngle * delta / Math.abs(delta); } setCurrentSteeringAngle((int) (cur_angle + delta) % 360); if (delta != 0 && Math.abs(delta) < 180) { turn_angle = C * delta; } else if (delta >= 180 && delta < 360) { turn_angle = -C * (360 - delta); } else if (delta <= -180) { turn_angle = C * (360 + delta); } else { /* No turning needed */ continue; } motor_left.rotate((int) Math.round(turn_angle)); } }
// Give a number to a arriving plane public int registerNewAproache(Airport a) { this.planeList.add(new Plane(Motor.getNowDate())); planeWaitingToLand = true; a.getTrack().setDelayToLand(); int id = planeList.get(planeList.size() - 1).setId(planeList.size() - 1); return id; }
public LegoNxtMotorActionBrick(Sprite sprite, Motor motor, int speedValue) { this.sprite = sprite; this.motorEnum = motor; this.motor = motorEnum.name(); this.speed = new Formula(speedValue); }
public LegoNxtMotorActionBrick(Sprite sprite, Motor motor, Formula speedFormula) { this.sprite = sprite; this.motorEnum = motor; this.motor = motorEnum.name(); this.speed = speedFormula; }
@Test public void testSetMotorPositionMin() { try { motor.setPosition(0.0); } catch (MotorPositionOutOfBounds e) { fail("The motor attempted to move out of bounds"); } }
public static boolean randomPlaneArriver() { if (Motor.getNowDate().getHours() < 22 && Motor.getNowDate().getHours() >= 7) { if (Motor.isWeekend()) { // random com media de 40 minutos if (new Random().nextInt(40) == 20) { return true; } else { return false; } } else { if ((Motor.getNowDate().getHours() >= 7 && Motor.getNowDate().getHours() < 10) || (Motor.getNowDate().getHours() >= 17 && Motor.getNowDate().getHours() < 19)) { // random com media de 10 minutos if (new Random().nextInt(10) == 5) { return true; } else { return false; } } else { // random com media de 20 minutos if (new Random().nextInt(20) == 10) { return true; } else { return false; } } } } return false; }
public static void main(String[] args) { Leds.set(Leds.WHITE); Display.clear(); Display.gotoXY(0, 0); Display.print("Motor Test"); WheelEncoder.setEnabled(true); DistanceSensor.setEnabled(true); int val = 0; int inc = 1; while (true) { DistanceSensor.updateLeft(); DistanceSensor.updateRight(); Motor.setLeft(val); Motor.setRight(val); Display.gotoXY(0, 1); Display.print("Val=" + val + " "); Display.gotoXY(0, 2); Display.print( "enc l=" + WheelEncoder.getLeftInc() + " r=" + WheelEncoder.getRightInc() + " "); Display.gotoXY(0, 3); Display.print( "dist l=" + DistanceSensor.getLeft() + " r=" + DistanceSensor.getRight() + " "); val += inc; if (val > 500) { val = 500; inc = -1; Leds.set(Leds.RED); } if (val < -500) { val = -500; inc = 1; Leds.set(Leds.WHITE); } Clock.delayMilliseconds(5); } }
public static void main(String[] args) { Scanner sc = new Scanner(System.in); System.out.println("업체 : "); String vendorName = sc.nextLine(); VendorID vendorID; if (vendorName.equalsIgnoreCase("LG")) vendorID = VendorID.LG; else // if(vendorName.equalsIgnoreCase("HYUNDAI")) vendorID = VendorID.HYUNDAI; ElevatorFactory factory = ElevatorFactoryFactory.getFactory(vendorID); Door door = factory.createDoor(); Motor motor = factory.createMotor(); motor.setDoor(door); door.open(); motor.move(Direction.UP); }
@Test public void testSetMotorPositoinDoesntGoOutOfBunds() { boolean outOfBounds = false; try { motor.setPosition(1.1); } catch (MotorPositionOutOfBounds e) { outOfBounds = true; } assertTrue(outOfBounds); outOfBounds = false; try { motor.setPosition(-0.1); } catch (MotorPositionOutOfBounds e) { outOfBounds = true; } assertTrue(outOfBounds); }
@Test public void testWheels() throws Exception { Car car = new Car(); car.setInsured(InsuranceType.HUS); Motor motor = new Motor(); motor.setCcm(200); car.setMotor(motor); car.setRegistered(DateUtils.addDays(new Date(), 10)); car.setLength(2000); Wheel leftFrontWheel = new Wheel(); leftFrontWheel.setPosition("LEFT_FRONT"); leftFrontWheel.setDiameter(10); car.addWheel(leftFrontWheel); Set<ConstraintViolation<Car>> violations = CustomVehicleTest.validator.validate(car); for (ConstraintViolation<Car> constraintViolation : violations) { System.out.println( constraintViolation.getPropertyPath() + ", " + constraintViolation.getMessage()); } }
public static void main(String[] args) throws IOException { Airport a = new Airport(); Motor.setStartDate(); try { CsvManager.csvManagerInit(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); System.out.println("Error to initiate Csv Manager"); } for (int i = 0; i < 3 * 30 * 24 * 60; i++) { // Step up the system Motor.stepUp(); // add new plane if (randomPlaneArriver()) { int planeNumber = a.getTower().registerNewAproache(a); a.getTower().addToLandList(planeNumber); System.out.println("Plane P" + planeNumber + " is waiting to land"); } a.getTrack().handler(a); a.getTaxiways()[Taxiway.TAXIWAY_ARRIVE].handler(a); a.getTaxiways()[Taxiway.TAXIWAY_LEAVE].handler(a); for (int j = 0; j < a.getGates().length; j++) { a.getGates()[j].handler(a); } System.out.println(" "); } for (int i = 0; i < a.getTower().planeList.size(); i++) { a.getTower().getPlaneById(i).writeLog(); } Measure.getRet().printAll(); Measure.getFreq().printFreqLog(); }
@Override public View getPrototypeView(Context context) { View prototypeView = View.inflate(context, R.layout.brick_phiro_motor_stop, null); Spinner phiroProSpinner = (Spinner) prototypeView.findViewById(R.id.brick_phiro_stop_motor_spinner); phiroProSpinner.setFocusableInTouchMode(false); phiroProSpinner.setFocusable(false); ArrayAdapter<CharSequence> motorAdapter = ArrayAdapter.createFromResource( context, R.array.brick_phiro_stop_motor_spinner, android.R.layout.simple_spinner_item); motorAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); phiroProSpinner.setAdapter(motorAdapter); phiroProSpinner.setSelection(motorEnum.ordinal()); return prototypeView; }
@Override public View getPrototypeView(Context context) { prototypeView = View.inflate(context, R.layout.brick_nxt_motor_action, null); TextView textSpeed = (TextView) prototypeView.findViewById(R.id.motor_action_speed_text_view); textSpeed.setText(String.valueOf(speed.interpretInteger(sprite))); Spinner legoSpinner = (Spinner) prototypeView.findViewById(R.id.lego_motor_action_spinner); legoSpinner.setFocusableInTouchMode(false); legoSpinner.setFocusable(false); ArrayAdapter<CharSequence> motorAdapter = ArrayAdapter.createFromResource( context, R.array.nxt_motor_chooser, android.R.layout.simple_spinner_item); motorAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); legoSpinner.setAdapter(motorAdapter); legoSpinner.setSelection(motorEnum.ordinal()); return prototypeView; }
@Override public View getView(Context context, int brickId, BaseAdapter baseAdapter) { if (animationState) { return view; } if (view == null) { alphaValue = 255; } view = View.inflate(context, R.layout.brick_nxt_motor_stop, null); view = getViewWithAlpha(alphaValue); setCheckboxView(R.id.brick_nxt_motor_stop_checkbox); final Brick brickInstance = this; checkbox.setOnCheckedChangeListener( new OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { checked = isChecked; adapter.handleCheck(brickInstance, isChecked); } }); ArrayAdapter<CharSequence> motorAdapter = ArrayAdapter.createFromResource( context, R.array.nxt_stop_motor_chooser, android.R.layout.simple_spinner_item); motorAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); Spinner motorSpinner = (Spinner) view.findViewById(R.id.stop_motor_spinner); motorSpinner.setOnItemSelectedListener(this); if (!(checkbox.getVisibility() == View.VISIBLE)) { motorSpinner.setClickable(true); motorSpinner.setEnabled(true); } else { motorSpinner.setClickable(false); motorSpinner.setEnabled(false); } motorSpinner.setAdapter(motorAdapter); motorSpinner.setSelection(motorEnum.ordinal()); return view; }
public void stop() { motor.brake(); }
public LegoNxtMotorStopBrick(Sprite sprite, Motor motor) { this.sprite = sprite; this.motorEnum = motor; this.motor = motorEnum.name(); }
@Test public void testGetMotorPosition() { assertEquals(0.0, motor.getPostion(), 0.001); }
public void increaseSpeed(int value) { motor.accelerate(value); }
public int getSpeed() { return motor.getRpm(); }
protected Object readResolve() { if (motor != null) { motorEnum = Motor.valueOf(motor); } return this; }
@Override public View getView(Context context, int brickId, BaseAdapter baseAdapter) { if (animationState) { return view; } if (view == null) { alphaValue = 255; } view = View.inflate(context, R.layout.brick_nxt_motor_action, null); view = getViewWithAlpha(alphaValue); setCheckboxView(R.id.brick_nxt_motor_action_checkbox); final Brick brickInstance = this; checkbox.setOnCheckedChangeListener( new OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { checked = isChecked; adapter.handleCheck(brickInstance, isChecked); } }); TextView textSpeed = (TextView) view.findViewById(R.id.motor_action_speed_text_view); editSpeed = (EditText) view.findViewById(R.id.motor_action_speed_edit_text); speed.setTextFieldId(R.id.motor_action_speed_edit_text); speed.refreshTextField(view); textSpeed.setVisibility(View.GONE); editSpeed.setVisibility(View.VISIBLE); editSpeed.setOnClickListener(this); ArrayAdapter<CharSequence> motorAdapter = ArrayAdapter.createFromResource( context, R.array.nxt_motor_chooser, android.R.layout.simple_spinner_item); motorAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); Spinner motorSpinner = (Spinner) view.findViewById(R.id.lego_motor_action_spinner); if (!(checkbox.getVisibility() == View.VISIBLE)) { motorSpinner.setClickable(true); motorSpinner.setEnabled(true); } else { motorSpinner.setClickable(false); motorSpinner.setEnabled(false); } motorSpinner.setAdapter(motorAdapter); motorSpinner.setOnItemSelectedListener( new OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> arg0, View arg1, int position, long arg3) { motorEnum = Motor.values()[position]; motor = motorEnum.name(); adapterView = arg0; } @Override public void onNothingSelected(AdapterView<?> arg0) { // TODO Auto-generated method stub } }); motorSpinner.setSelection(motorEnum.ordinal()); return view; }
public static void main(String[] args) { System.out.println("Início do Programa ..."); // Instanciando Iates System.out.println("Criando Iates ..."); Iate a = new Iate(1); Iate b = new Iate("Marca_b"); Iate c = new Iate("Marca_c", "Modelo_c"); Iate d = new Iate("Marca_d", "Modelo_d", 1); Iate e = new Iate("Marca_e", "Modelo_e", 1, 1.0); // Métodos b.setMarca("Marca_b"); b.getMarca(); c.setModelo("Modelo_c"); c.getModelo(); d.setNumeropassageiros(100); d.getNumeropassageiros(); e.setPreco(450.0); e.getPreco(); b.setVelocidademaxima(300); b.getVelocidademaxima(); c.setIdentificacao("Identificacao_a"); c.getIdentificacao(); // MODIFICAR: INSERÇÃO DO CADASTRO DO MOTOR Motor mot = new Motor(); mot.setMarca("Marca_mot"); mot.getMarca(); mot.setModelo("Modelo_mot"); mot.getModelo(); mot.setPotencia(450); mot.getPotencia(); mot.setTipocombustivel("gasolina"); mot.getTipocombustivel(); mot.setRpmmaxima(400); mot.getRpmmaxima(); mot.setRpm(200); mot.getRpm(); // Outros Métodos mot.cadastrar(); mot.imprimir(); mot.acelerar(); mot.acelerar(); mot.desacelerar(); b.setMotor(mot); b.getMotor(); c.setNumerotripulantes(900); c.getNumerotripulantes(); d.setNumerocabines(45); d.getNumerocabines(); e.setPiscina(true); e.isPiscina(); // MODIFICAR: INSERÇÃO DO CADASTRO DO MOTOR Motor mot2 = new Motor(); mot2.cadastrar(); mot2.imprimir(); a.setMotor2(mot2); a.getMotor2(); a.cadastrar(); a.imprimir(); a.valorDesconto(); a.pessoasPorCabine(); // Instanciando Lanchas System.out.println("Criando Lanchas ..."); Lancha l = new Lancha(1); Lancha m = new Lancha("Marca"); Lancha n = new Lancha("Marca", "Modelo"); Lancha o = new Lancha("Marca", "Modelo", 1); Lancha p = new Lancha("Marca", "Modelo", 1, 1.0); // Métodos m.setMarca("Marca_m"); m.getMarca(); n.setModelo("Modelo_n"); n.getModelo(); o.setNumeropassageiros(100); o.getNumeropassageiros(); p.setPreco(450.0); p.getPreco(); m.setVelocidademaxima(300); m.getVelocidademaxima(); n.setIdentificacao("Identificacao_a"); n.getIdentificacao(); // MODIFICAR: INSERÇÃO DO CADASTRO DO MOTOR Motor mot3 = new Motor(); mot3.cadastrar(); mot3.imprimir(); mot.acelerar(); o.setMotor(mot3); o.getMotor(); p.getTipocasco(); p.setTipocasco(40028922); m.isBanheiro(); m.setBanheiro(true); l.cadastrar(); l.imprimir(); l.valorDesconto(); System.out.println("Fim do Programa ..."); }