예제 #1
0
 /**
  * Request/reply: Motor power. <br>
  * <br>
  * On some robots, the motor power can be turned on and off from software. To do so, send a
  * PLAYER_POSITION1D_MOTOR_POWER request with the format given below, and with the appropriate
  * state (zero for motors off and non-zero for motors on). Null response. <br>
  * <br>
  * Be VERY careful with this command! You are very likely to start the robot running across the
  * room at high speed with the battery charger still attached.
  *
  * @param state 0 for off, 1 for on
  */
 public void setMotorPower(int state) {
   try {
     sendHeader(PLAYER_MSGTYPE_REQ, PLAYER_POSITION1D_REQ_MOTOR_POWER, 4);
     XdrBufferEncodingStream xdr = new XdrBufferEncodingStream(4);
     xdr.beginEncoding(null, 0);
     xdr.xdrEncodeByte((byte) state);
     xdr.endEncoding();
     os.write(xdr.getXdrData(), 0, xdr.getXdrLength());
     xdr.close();
     os.flush();
   } catch (IOException e) {
     throw new PlayerException("[Position1D] : Couldn't request MOTOR_POWER: " + e.toString(), e);
   } catch (OncRpcException e) {
     throw new PlayerException(
         "[Position1D] : Error while XDR-encoding POWER request: " + e.toString(), e);
   }
 }
예제 #2
0
 /**
  * The position1D interface accepts new positions and/or velocities for the robot's motors
  * (drivers may support position control, speed control or both). <br>
  * <br>
  * See the player_position1d_cmd_vel structure from player.h
  *
  * @param pp1dcv a PlayerPosition1dCmdVel structure holding the required data
  */
 public void setVelocity(PlayerPosition1dCmdVel pp1dcv) {
   try {
     sendHeader(PLAYER_MSGTYPE_CMD, PLAYER_POSITION1D_CMD_VEL, 8);
     XdrBufferEncodingStream xdr = new XdrBufferEncodingStream(8);
     xdr.beginEncoding(null, 0);
     xdr.xdrEncodeFloat(pp1dcv.getVel());
     xdr.xdrEncodeByte(pp1dcv.getState());
     xdr.endEncoding();
     os.write(xdr.getXdrData(), 0, xdr.getXdrLength());
     xdr.close();
     os.flush();
   } catch (IOException e) {
     throw new PlayerException(
         "[Position1D] : Couldn't send velocity command: " + e.toString(), e);
   } catch (OncRpcException e) {
     throw new PlayerException(
         "[Position1D] : Error while XDR-encoding position command: " + e.toString(), e);
   }
 }
예제 #3
0
 /**
  * The position1D interface accepts new positions and/or velocities for the robot's motors
  * (drivers may support position control, speed control or both). <br>
  * <br>
  * See the player_position1d_cmd_pos structure from player.h
  *
  * @param pos position data [m] or [rad]
  * @param vel velocity at which to move to the position [m/s] or [rad/s]
  * @param state motor state (zero is either off or locked, depending on the driver)
  */
 public void setPosition(float pos, float vel, int state) {
   try {
     sendHeader(PLAYER_MSGTYPE_CMD, PLAYER_POSITION1D_CMD_POS, 12);
     XdrBufferEncodingStream xdr = new XdrBufferEncodingStream(12);
     xdr.beginEncoding(null, 0);
     xdr.xdrEncodeFloat(pos);
     xdr.xdrEncodeFloat(vel);
     xdr.xdrEncodeByte((byte) state);
     xdr.endEncoding();
     os.write(xdr.getXdrData(), 0, xdr.getXdrLength());
     xdr.close();
     os.flush();
   } catch (IOException e) {
     throw new PlayerException(
         "[Position1D] : Couldn't send position command: " + e.toString(), e);
   } catch (OncRpcException e) {
     throw new PlayerException(
         "[Position1D] : Error while XDR-encoding position command: " + e.toString(), e);
   }
 }