本文整理了Java中org.robokind.api.common.utils.Utils.bound()
方法的一些代码示例,展示了Utils.bound()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Utils.bound()
方法的具体详情如下:
包路径:org.robokind.api.common.utils.Utils
类名称:Utils
方法名:bound
暂无
代码示例来源: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 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.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.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.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.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.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;
}
代码示例来源:origin: org.robokind/org.robokind.api.motion
double val = goal.getValue();
val += velocities.get(i) * (double)interval;
val = Utils.bound(val, 0.0, 1.0);
pos.put(i, new NormalizedDouble(val));
代码示例来源:origin: org.robokind/org.robokind.impl.motion.dynamixel
public NormalizedDouble getCurrentPosition(){
if(myFeedbackVals == null){
return myDefaultPosition;
}
double min = myConfig.getMinPosition();
double max = myConfig.getMaxPosition();
Double range = max - min;
Double abs = myFeedbackVals.getCurrentPosition() - min;
Double pos = Utils.bound(abs/range, 0.0, 1.0);
return new NormalizedDouble(pos);
}
代码示例来源:origin: org.robokind/org.robokind.impl.motion.dynamixel
/**
*
* @return
*/
public NormalizedDouble getCurrentPosition() {
double min = myConfig.getMinPosition();
double max = myConfig.getMaxPosition();
Double range = max - min;
Double abs = getCurrentPositionAbs() - min;
Double pos = Utils.bound(abs/range, 0.0, 1.0);
return new NormalizedDouble(pos);
}
/**
代码示例来源:origin: org.cogchar/org.cogchar.bundle.bind.robokind
protected void updateConfig(BoneJointConfig bjc, boolean flag_hardResetGoalPosToDefault) {
double defPosVal = Utils.bound(bjc.myNormalDefaultPos, 0.0, 1.0);
myDefaultPosNorm = new NormalizedDouble(defPosVal);
myBoneProjectionRanges = bjc.myProjectionRanges;
List<BoneProjectionRange> projRanges = getBoneRotationRanges();
if(projRanges == null || projRanges.isEmpty()){
myNormalizableRange = NormalizableRange.NORMALIZED_RANGE;
} else {
BoneProjectionRange range = projRanges.get(0);
double min = range.getMinPosAngRad();
double max = range.getMaxPosAngRad();
myNormalizableRange = new DoubleRange(min, max);
}
if (flag_hardResetGoalPosToDefault) {
hardResetGoalPosToDefault();
}
}
private void hardResetGoalPosToDefault() {
代码示例来源:origin: org.robokind/org.robokind.api.speech
/**
* Creates a new VisemeBinding with the given configuration.
* @param config configuration for the VisemeBinding
*/
public VisemeBinding(VisemeBindingConfig<VisemePosition> config){
this(config.getBindingId());
for(VisemePosition pos : config.getVisemeBindings()){
int id = pos.getVisemeId();
Viseme vis = Viseme.getById(id);
double boundPos = Utils.bound(pos.getPosition(), 0.0, 1.0);
NormalizedDouble val = new NormalizedDouble(boundPos);
myVisemeValueMap.put(vis, val);
}
}
代码示例来源:origin: org.robokind/org.robokind.integration.motion_speech
private void addJoint(JointId jointId,
MotionFrame frame, double startPercent, double stopPercent){
NormalizedDouble normAbsStart = myStartPositions.get(jointId);
NormalizedDouble normAbsStop = myGoalPositions.get(jointId);
if(normAbsStart == null || normAbsStop == null){
return;
}
double absStart = normAbsStart.getValue();
double absStop = normAbsStop.getValue();
double range = absStop - absStart;
double start = startPercent*range + absStart;
start = Utils.bound(start, 0.0, 1.0);
double stop = stopPercent*range + absStart;
stop = Utils.bound(stop, 0.0, 1.0);
frame.getPreviousPositions().put(jointId, new NormalizedDouble(start));
frame.getGoalPositions().put(jointId, new NormalizedDouble(stop));
}
代码示例来源:origin: org.robokind/org.robokind.integration.motion_speech
double stopMillisec = startMillisec + moveLengthMilliSec;
stopMillisec =
Utils.bound(stopMillisec, startMillisec+1, myCurrentMoveLength);
double startPercent = startMillisec/(double)myCurrentMoveLength;
startPercent = Utils.bound(startPercent, 0.0, 1.0);
double stopPercent = stopMillisec/(double)myCurrentMoveLength;
stopPercent = Utils.bound(stopPercent, 0.0, 1.0);
代码示例来源:origin: org.robokind/org.robokind.integration.animation_motion
private void addRamping(Map<Integer,Double> curPos){
myRampedAnimationMap = (CompiledMap)myAnimationMap.clone();
double maxDif = findMaxDif(curPos);
maxDif = Utils.bound(maxDif, 0.0, 1.0);
myRampTimeMillisec = (int)(maxDif*myMaxRampTimeMillisec);
InterpolatorFactory linearFact = new LinearInterpolatorFactory();
代码示例来源:origin: org.robokind/org.robokind.api.motion
elapsed = Utils.bound(elapsed, 0L, myMoveLengthMsec);
if(elapsed == myMoveLengthMsec){
myFinsihedFlag = true;
内容来源于网络,如有侵权,请联系作者删除!