org.robokind.api.common.utils.Utils类的使用及代码示例

x33g5p2x  于2022-02-01 转载在 其他  
字(9.8k)|赞(0)|评价(0)|浏览(101)

本文整理了Java中org.robokind.api.common.utils.Utils类的一些代码示例,展示了Utils类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Utils类的具体详情如下:
包路径:org.robokind.api.common.utils.Utils
类名称:Utils

Utils介绍

暂无

代码示例

代码示例来源:origin: org.robokind/org.robokind.api.motion

private static long validateInterval(long interval){
  return Utils.bound(interval, 1, Integer.MAX_VALUE-1);
}

代码示例来源:origin: org.robokind/org.robokind.impl.motion.dynamixel

private static int nextPacket(byte[] data, int offset){
  if(offset >= data.length-5){
    return -1;
  }
  do{
    if(Utils.unsign(data[offset]) == 0xff 
        && Utils.unsign(data[offset+1]) == 0xff){
      return offset;
    }
  }while(++offset < data.length-5);
  return -1;
}

代码示例来源:origin: org.robokind/org.robokind.impl.motion.dynamixel

public static byte[] getReadCommand(int rs485Addr, int i2cAddr, int reg, int readLen){
    int packetLength = 6;
    byte[] bytes = new byte[10];
    bytes[0] = (byte)0xff;
    bytes[1] = (byte)0xff;
    bytes[2] = (byte)rs485Addr;
    bytes[3] = (byte)packetLength;
    bytes[4] = (byte)2;
    bytes[5] = (byte)readLen;
    bytes[6] = (byte)(i2cAddr << 1);
    bytes[7] = (byte)reg;
    bytes[8] = (byte)((i2cAddr << 1)|1);
    bytes[9] = Utils.checksum(bytes, 2, bytes.length-3, true);
    return bytes;
  }
}

代码示例来源:origin: org.robokind/org.robokind.impl.motion.dynamixel

return null;
int first = Utils.unsign(data[offset]);
int second = Utils.unsign(data[offset+1]);
if(first != 0xff || second != 0xff){
  theLogger.log(Level.INFO, 
int receivedId = Utils.unsign(data[offset+2]);
packet.myLength = Utils.unsign(data[offset+3])-1;
if(packet.myLength > data.length - (offset+5)){
  theLogger.log(Level.INFO, 
System.arraycopy(data, offset+4, packet.myData, 0, packet.myLength);
packet.myErrorFlag = (packet.myLength != packet.myData.length);
byte chkCalc = Utils.checksum(packet.myData, 0, packet.myData.length, true,
    (byte)receivedId, (byte)(packet.myLength+1));
byte chkRec = data[offset+4+packet.myLength];

代码示例来源:origin: org.robokind/org.robokind.extern.utils.apache_commons_configuration

return Color.decode(colStr);
}else if(len == 4){
  int r = Utils.readHex(colStr.charAt(1))*17;
  int g = Utils.readHex(colStr.charAt(1))*17;
  int b = Utils.readHex(colStr.charAt(1))*17;
  int a = Utils.readHex(colStr.charAt(1))*17;
  return new Color(r, g, b, a);
}else{
  int r = Utils.readHex(colStr.substring(1, 3));
  int g = Utils.readHex(colStr.substring(3, 5));
  int b = Utils.readHex(colStr.substring(5, 7));
  int a = Utils.readHex(colStr.substring(7, 9));
  return new Color(r, g, b, a);

代码示例来源:origin: org.robokind/org.robokind.impl.motion.dynamixel

return null;
int first = Utils.unsign(data[offset]);
int second = Utils.unsign(data[offset+1]);
if(first != 0xff || second != 0xff){
  theLogger.log(Level.INFO, 
int receivedId = Utils.unsign(data[offset+2]);
packet.myLength = Utils.unsign(data[offset+3])-2;
if(packet.myLength > data.length - (offset+6)){
  theLogger.log(Level.INFO, 
  return null;
int errorBits = Utils.unsign(data[offset+4]);
packet.myErrors = ErrorStatus.getStatusList(errorBits);
int plen = packet.myLength;
System.arraycopy(data, offset+5, packet.myData, 0, packet.myLength);
packet.myErrorFlag = (packet.myLength != packet.myData.length);
byte chkCalc = Utils.checksum(packet.myData, 0, packet.myData.length, true,
    (byte)receivedId, (byte)(packet.myLength+2),(byte)errorBits);
byte chkRec = data[offset+5+packet.myLength];

代码示例来源:origin: org.robokind/org.robokind.impl.motion.dynamixel

private static int dist(int speed, long time){
  speed = Utils.bound(speed, -1023, 1023);
  time = Math.max(time, 1);
  double rpm = (double)speed*theRXRPMConversion;
  double theta = (rpm*360.0)/(60000.0/time);
  double dist = (theta/theRXRotationRange)*theRXMaxPosition;
  return (int) dist;
}

代码示例来源:origin: org.robokind/org.robokind.impl.vision

private static int getRGB(ByteBuffer data, int offset, int channels){
    int rgb = 0;
    int val = 0;
    for(int i=0; i<3; i++){
      if(i<channels){
        val = Utils.unsign(data.get(offset+i));
      }
      int shift = (2-i)*8;
      rgb = rgb | (val << shift);
    }
    return rgb;
  }
}

代码示例来源:origin: org.robokind/org.robokind.impl.motion.dynamixel

public static byte[] writeRegisters(byte rs485Addr, byte i2cAddr, Register firstRegister, byte...data){
  byte[] bytes = new byte[8+data.length+1];
  bytes[0] = (byte)0xff;
  bytes[1] = (byte)0xff;
  bytes[2] = rs485Addr;
  bytes[3] = (byte)(4+data.length+1);
  bytes[4] = (byte)(2+data.length);
  bytes[5] = (byte)0;
  bytes[6] = (byte)(i2cAddr << 1);
  bytes[7] = firstRegister.getRegister();
  System.arraycopy(data, 0, bytes, 8, data.length);
  bytes[bytes.length-1] = Utils.checksum(bytes, 2, bytes.length-3, true);
  return bytes;
}

代码示例来源:origin: org.robokind/org.robokind.impl.motion.dynamixel

private static int calculateSpeed(int cur, int goal, long time){
  //time is in milliseconds
  //cur and goal are dynamixel values, [0, 1023]
  int dist = Math.abs(goal - cur);
  //dynamixel range of motion is 300 degrees
  double theta = dist*theRXRotationRange/theRXMaxPosition;
  time = Math.max(time, 1);
  
  //60000ms/minute, 360 deg/rotation
  double rpm = theta * (60000.0/time) / 360.0; 
  double speed = rpm/theRXRPMConversion;
  //make sure the speed is between 1 and 1023
  //0 is max speed, so minimum is 1
  return Utils.bound((int)speed, 1, 1023);
}

代码示例来源:origin: org.robokind/org.robokind.impl.vision

private static int getARGB(ByteBuffer data, int offset, int channels){
  int a = 255;
  if(channels > 3){
    a = Utils.unsign(data.get(offset));
    offset++;
  }
  return (a << 24) | getRGB(data, offset, channels);
}

代码示例来源:origin: org.robokind/org.robokind.impl.motion.dynamixel

public static byte[] readRegisters(int rs485Addr, int i2cAddr, Register firstRegister, int readLen){
  int packetLength = 6;
  byte[] bytes = new byte[10];
  bytes[0] = (byte)0xff;
  bytes[1] = (byte)0xff;
  bytes[2] = (byte)rs485Addr;
  bytes[3] = (byte)packetLength;
  bytes[4] = (byte)2;
  bytes[5] = (byte)readLen;
  bytes[6] = (byte)(i2cAddr << 1);
  bytes[7] = firstRegister.getRegister();
  bytes[8] = (byte)((i2cAddr << 1)|1);
  bytes[9] = Utils.checksum(bytes, 2, bytes.length-3, true);
  return bytes;
}

代码示例来源:origin: org.robokind/org.robokind.api.audio

public AudioPlayLoop(AudioFormat format, byte[] audio, int start, int end, 
    long startDelay, int bufferSize, Playable parent){
  if(audio == null){
    throw new NullPointerException();
  }
  myAudio = audio;
  myStopIndex = end <= -1 ? myAudio.length : end;
  myStopIndex = Math.min(myStopIndex, myAudio.length);
  myStartIndex = Utils.bound(start, 0, myStopIndex);
  myPlayIndex = myStartIndex;
  myRunningFlag = false;
  myBufferSize = bufferSize;
  myStopFlag = false;
  myParent = parent;
  myFormat = format;
  setStartDelayMillisec(startDelay);
}

代码示例来源:origin: org.robokind/org.robokind.impl.motion.dynamixel

private static void parsePacketData(int firstReg, int lastReg, byte[] data, int[] dest) {
    Register[] regs = Register.values();
    for (int i = firstReg; i <= lastReg; i++) {
      Register reg = regs[i];
      int offset = reg.getByte() - regs[firstReg].getByte();
      dest[i - firstReg] = Utils.unsign(data[offset]);
      if (reg.getLength() > 1) {
        dest[i - firstReg] += (Utils.unsign(data[offset + 1]) << 8);
      }
    }
  }
}

代码示例来源:origin: org.robokind/org.robokind.impl.motion.dynamixel

public static byte[] sendCommands(byte rs485Addr, byte i2cAddr, Command...commands) {
  byte[] bytes = new byte[7+commands.length+1];
  bytes[0] = (byte)0xff;
  bytes[1] = (byte)0xff;
  bytes[2] = rs485Addr;
  bytes[3] = (byte)(3+commands.length+1);
  bytes[4] = (byte)(1+commands.length);
  bytes[5] = (byte)0;
  bytes[6] = (byte)(i2cAddr << 1);
  int i=7;
  for(Command cmd : commands){
    bytes[i++] = cmd.getCommand();
  }
  bytes[bytes.length-1] = Utils.checksum(bytes, 2, bytes.length-3, true);
  return bytes;
}

代码示例来源:origin: org.robokind/org.robokind.api.audio

public WavBufferProcessor(WavBuffer wav, int startByte, int stopByte){
  myAudio = wav.getAudioBytes();
  myBufferSamples = theDefaultBufferSize;
  myFormat = wav.getFormat();
  myStartIndex = Utils.bound(startByte, 0, myAudio.length-1);
  myStopIndex = Utils.bound(stopByte, myStartIndex+1, myAudio.length);
  myProcIndex = myStartIndex;
  initAudioStream();
}

代码示例来源:origin: org.robokind/org.robokind.impl.motion.dynamixel

private static void addMoveCommand(
    Collection<MoveParams<DynamixelServo.Id>> params, byte[] cmd, int offset,
    DynamixelControlSettings settings){
  int jointCount = params.size();
  int paramLen = jointCount*theSyncCount;
  int dataSize = paramLen + theMoveCount;
  if(cmd.length < offset + dataSize){
    throw new IllegalArgumentException(
        "cmd byte array too short.  expected: " 
        + (offset+dataSize) + ", found: " + cmd.length);
  }
  System.arraycopy(theHeaderData, 0, cmd, offset, theHeaderData.length);
  cmd[offset+3] = (byte)(paramLen+4);
  addServosParams(params, cmd, offset+theHeaderData.length, settings);
  cmd[offset+dataSize - 1] = Utils.checksum(cmd, offset+2, paramLen+5, true);
}

代码示例来源:origin: org.robokind/org.robokind.api.audio

public void setBytePosition(long position){
  int playPos = (int)(position - myStartDelayBytes);
  int frameSize = myFormat.getFrameSize();
  double frameRate = myFormat.getFrameRate();
  double frames = position/frameSize;
  double sec = frames / frameRate;
  long msec = (long)(sec * 1000);
  if(playPos >= 0){
    myPlayIndex = Utils.bound(playPos+myStartIndex, myStartIndex, myStopIndex);
  }else{
    myPlayIndex = myStartIndex;
  }
  myElapsedPlayTime = msec;
  
}

代码示例来源:origin: org.robokind/org.robokind.impl.motion.dynamixel

private static byte[] buildMultiReadCommand(
    List<DynamixelServo.Id> ids, byte startRegister, byte byteCount) {
  byte[] data = new byte[ids.size() * MULTIREAD_BYTE_COUNT];
  for (int j = 0; j < ids.size(); j++) {
    int i = j * MULTIREAD_BYTE_COUNT;
    data[i + 0] = (byte) 0xff;
    data[i + 1] = (byte) 0xff;
    data[i + 2] = (byte) ids.get(j).getIntValue();
    data[i + 3] = (byte) 4;
    data[i + 4] = Instruction.ReadData.getByte();
    data[i + 5] = startRegister;
    data[i + 6] = byteCount;
    data[i + 7] = Utils.checksum(data, i + 2, 5, true);
  }
  return data;
}

代码示例来源:origin: org.robokind/org.robokind.api.motion

/**
 * Averages the goal positions from the MotionFrames into a single 
 * PositionMap.  The MotionFrames' start positions, timing, and 
 * FrameSources are ignored.
 * @return PositionMap with averaged goal positions from the MotionFrames
 */
@Override
public PosMap combineFrames(long time, long interval, PosMap curPos, 
Map<? extends MotionFrame<PosMap>, ? extends FrameSource<PosMap>> frames) {
  //Use a HashMap instead of a PositionMap since the sum may be greater
  //than 1.0 before averaging.
  Map<Id, Double> posSums = new HashMap();
  Map<Id, Integer> count = new HashMap();
  
  for(MotionFrame f : frames.keySet()){
    sumGoalPositions(f, posSums, count);
  }
  PosMap pos = myPositionMapFactory.getValue();
  for(Entry<Id,Double> e : posSums.entrySet()){
    Id id = e.getKey();
    double goal = e.getValue();
    double c = count.get(id);
    double avg = goal/c;
    avg = Utils.bound(avg, 0.0, 1.0);
    NormalizedDouble val = new NormalizedDouble(avg);
    pos.put(id, val);
  }
  return pos;
}

相关文章

Utils类方法