public AnimationJob playFullAnimationNow(Animation anim) { long lengthMsec = anim.getLength(); return playAnimationSegmentNow(anim, 0, lengthMsec); /*"The PlayState is not implemented for the RemoteAnimationJob." To get correct "remainingTime", when using a networked animation player. Before you play an animation set the start time and stop time on the animation, * or use the play animation with time args: anim.setStartTime(0); anim.setStopTime(anim.getLength()); or animPlayer.playAnimation(anim, 0, anim.getLength()); */ /* * if (myCachedAnimPlayer != null) { // return myCachedAnimPlayer.playAnimation(anim); } else { return AnimationUtils.playAnimation(myBundleCtx, myAnimPlayerOsgiFilterString, anim); } */ }
RampedAnimationJob( BundleContext context, AnimationPlayer source, Robot.Id robotId, Animation anim, long stepLength, Long start, Long stop, int maxRampMillisec){ if(context == null || robotId == null || anim == null){ throw new NullPointerException(); }if(stepLength <= 0){ throw new IllegalArgumentException( "stepLength must be greater than zero"); } myContext = context; myLoopFlag = false; myRobotId = robotId; myAnimationListeners = new ArrayList(); mySource = source; myAnimation = anim; myStepLengthMillisec = stepLength; myMaxRampTimeMillisec = maxRampMillisec; long s = start == null ? -1 : start; long e = stop == null ? -1 : stop; myAnimationMap = anim.compileMap(s, e, myStepLengthMillisec); }
public static MotionPath readMotionPath(HierarchicalConfiguration config){ String name = XMLConfigUtils.getStringAttribute(config, MOTION_PATH_NAME, null); InterpolatorFactory factory = readInterpolatorVersion(config); MotionPath path = new MotionPath(factory); path.setName(name); HierarchicalConfiguration pointsConfig = config.configurationAt(CONTROL_POINTS); if(pointsConfig != null && !pointsConfig.isEmpty()){ path.addPoints(readControlPoints(pointsConfig)); } return path; }
ChannelsParameterSource cpSource = AnimationUtils.getChannelsParameterSource(); getLogger().debug("channelParamSource={}", cpSource); List<ChannelsParameter> chanParams = cpSource.getChannelParameters(); getLogger().debug("Test animation channels={}", chanParams); Animation anim = new Animation(); int jointNum = cp.getChannelID(); String name = cp.getChannelName(); Channel chan = new Channel(jointNum, name); getLogger().debug("Creating MotionPath for channel jointNum={}, name={}", jointNum, name); MotionPath path = new MotionPath(); path.addPoint(gotoRampMsec, defaultPosNorm.getValue()); break; case BAK_DANGER_YOGA: path.addPoint(500, defaultPosNorm.getValue()); path.addPoint(1500, 1.0); path.addPoint(2500, 0.0); path.addPoint(3500, defaultPosNorm.getValue()); break; chan.addPath(path); anim.addChannel(chan);
@Override protected boolean onResume(long time) { for(ServiceAddOn<Playable> addon : myAnimation.getAddOns()){ Playable p = addon.getAddOn(); p.resume(time); } if(mySource != null && mySource instanceof DefaultAnimationPlayer) { List<String> props = new ArrayList<String>(); if(myLoopFlag) { props.add(AnimationSignal.PROP_LOOP); } AnimationSignal signal = mySignalFactory.createAnimationSignal( mySource.getAnimationPlayerId(), AnimationSignal.EVENT_RESUME, myAnimation.getVersion().getName(), myAnimation.getVersion().getNumber(), myAnimation.hashCode(), myAnimation.getLength(), props); ((DefaultAnimationPlayer)mySource).notifyListeners(signal); } return true; } @Override
Set<SynchronizedPointGroup> syncPointGroups) throws IOException{ xs.startTag(NAMESPACE, ANIMATION); XMLUtils.writeVersionProperty(xs, a.getVersion(), ANIMATION_VERSION_TYPE); xs.startTag(NAMESPACE, CHANNELS); for(Channel channel : a.getChannels()){ writeChannel(xs, channel); writeAddOnList(xs, a.getAddOns(), file); xs.startTag(NAMESPACE, CHANNELS_PARAMETERS); if(source != null){ List<ChannelsParameter> params = source.getChannelParameters(); if(params != null){ for(ChannelsParameter param: params) {
long s = start == null ? -1 : start; long e = stop == null ? -1 : stop; myAnimationMap = anim.compileMap(s, e, stepLength); List<Channel> channels = myAnimation.getChannels(); myPreviousPositions = new Robot.RobotPositionHashMap(channels.size()); for(Channel c : channels){ continue; CompiledPath path = myAnimationMap.get(c.getId()); if(path == null){ continue; Integer id = c.getId(); double v = path.estimatePosition(0); if(id == null || !NormalizedDouble.isValid(v)){ continue;
private static MotionPath unpackMotionPath(MotionPathRecord pathRec){ String interpName = pathRec.getInterpolator().getName(); String interpNumber = pathRec.getInterpolator().getVersionNumber(); VersionProperty interp = new VersionProperty(interpName, interpNumber); InterpolatorFactory fact = InterpolatorDirectory.instance().getFactory(interp); MotionPath path = new MotionPath(fact); path.setName(pathRec.getName()); int pointCount = pathRec.getControlPoints().size(); List<Point2D> points = new ArrayList<Point2D>(pointCount); for(ControlPointRecord pr : pathRec.getControlPoints()){ points.add(unpackControlPoint(pr)); } path.addPoints(points); if(pathRec.getStartTime() != null){ path.setStartTime(pathRec.getStartTime()); } if(pathRec.getStopTime() != null){ path.setStopTime(pathRec.getStopTime()); } return path; }
private static Channel unpackChannel(ChannelRecord chanRec){ Channel chan = new Channel(chanRec.getChannelId(), chanRec.getName()); for(MotionPathRecord pathRec : chanRec.getMotionPaths()){ chan.addPath(unpackMotionPath(pathRec)); } if(chanRec.getStartTime() != null){ chan.setStartTime(chanRec.getStartTime()); } if(chanRec.getStopTime() != null){ chan.setStopTime(chanRec.getStopTime()); } return chan; }
public static Animation unpackAnimation(AnimationRecord animRec){ String name = animRec.getName(); String number = animRec.getVersionNumber(); VersionProperty animVersion = new VersionProperty(name, number); Animation anim = new Animation(animVersion); for(ChannelRecord chanRec : animRec.getChannels()){ anim.addChannel(unpackChannel(chanRec)); } if(animRec.getStartTime() != null){ anim.setStartTime(animRec.getStartTime()); } if(animRec.getStopTime() != null){ anim.setStopTime(animRec.getStopTime()); } return anim; }
private static ChannelRecord packChannel(Channel channel){ ChannelRecord chanRec = new ChannelRecord(); chanRec.setName(channel.getName()); chanRec.setChannelId(channel.getId()); chanRec.setStartTime(channel.getStartTime()); chanRec.setStopTime(channel.getStopTime()); Schema arraySchema = Schema.createArray(MotionPathRecord.SCHEMA$); List<MotionPath> pathList = channel.getMotionPaths(); GenericArray<MotionPathRecord> paths = new Array<MotionPathRecord>(pathList.size(), arraySchema); int i=0; for(MotionPath mp : pathList){ paths.add(packMotionPath(mp, i++)); } chanRec.setMotionPaths(paths); return chanRec; }
public static AnimationRecord packAnimation(Animation animation){ if(animation == null){ throw new NullPointerException(); } AnimationRecord animRec = new AnimationRecord(); animRec.setName(animation.getVersion().getName()); animRec.setVersionNumber(animation.getVersion().getNumber()); animRec.setStartTime(animation.getStartTime()); animRec.setStopTime(animation.getStopTime()); Schema arraySchema = Schema.createArray(ChannelRecord.SCHEMA$); List<Channel> chanList = animation.getChannels(); GenericArray<ChannelRecord> channels = new Array<ChannelRecord>(chanList.size(), arraySchema); for(Channel chan : chanList){ channels.add(packChannel(chan)); } animRec.setChannels(channels); return animRec; }
public static XMLConfiguration writeAnimation( Animation anim, String path, ChannelsParameterSource source, Set<SynchronizedPointGroup> syncPointGroups){ XMLConfiguration config = new XMLConfiguration(); config.setRootElementName(ANIMATION); ConfigurationNode node = config.getRootNode(); node.addChild(XMLConfigUtils.writeVersion(anim.getVersion(), ANIMATION_VERSION_TYPE)); node.addChild(writeChannels(anim.getChannels())); node.addChild(writeAddOnList(anim.getAddOns(), path)); node.addChild(writeChannelsParameters(source)); node.addChild(SyncPointGroupXML.ApacheWriter.writeSyncGroups(syncPointGroups)); return config; }
private static MotionPathRecord packMotionPath(MotionPath path, int id){ MotionPathRecord pathRec = new MotionPathRecord(); pathRec.setName(path.getName()); pathRec.setMotionPathId(id); pathRec.setStartTime(path.getStartTime()); pathRec.setStopTime(path.getStopTime()); VersionProperty interpVersion = path.getInterpolatorVersion(); pathRec.setInterpolator(packInterpolatorType(interpVersion)); Schema arraySchema = Schema.createArray(ControlPointRecord.SCHEMA$); List<Point2D> pointList = path.getControlPoints(); GenericArray<ControlPointRecord> points = new Array<ControlPointRecord>(pointList.size(), arraySchema); for(Point2D p : pointList){ points.add(packControlPoint(p)); } pathRec.setControlPoints(points); return pathRec; }
public static Animation readAnimation(HierarchicalConfiguration config){ VersionProperty version = XMLConfigUtils.readVersion(config, ANIMATION_VERSION_TYPE); Animation anim = new Animation(version); HierarchicalConfiguration channelsConfig = config.configurationAt(CHANNELS); if(channelsConfig != null && !channelsConfig.isEmpty()){ anim.addChannels(readChannels(channelsConfig)); SyncPointGroupXML.ApacheReader.readSyncPointGroupConfigs( groupsConfig); anim.setSyncGroupConfigs(groups); List<ServiceAddOn<Playable>> addons = readAddOns(addonsConfig); for(ServiceAddOn<Playable> addon : addons){ anim.addAddOn(addon);
public static ConfigurationNode writeChannel(Channel channel){ if(channel == null){ return null; } ConfigurationNode node = XMLConfigUtils.node(CHANNEL); node.addAttribute(XMLConfigUtils.node(CHANNEL_ID, channel.getId())); String name = channel.getName(); if(name != null && !name.isEmpty()){ node.addAttribute(XMLConfigUtils.node(MOTION_PATH_NAME, name)); } node.addChild(writeMotionPaths(channel.getMotionPaths())); return node; }
/** * * @param xs * @param mp * @throws IOException */ public static void writeMotionPath(XmlSerializer xs, MotionPath mp) throws IOException{ xs.startTag(NAMESPACE, MOTION_PATH); String name = mp.getName(); if(name != null && !name.isEmpty()){ xs.attribute(NAMESPACE, MOTION_PATH_NAME, name); } XMLUtils.writeVersionProperty(xs, mp.getInterpolatorVersion(), INTERPOLATION_VERSION_TYPE); writeControlPoints(xs, mp.getControlPoints()); xs.endTag(NAMESPACE, MOTION_PATH); }
public static Channel readChannel(HierarchicalConfiguration config){ Integer id = XMLConfigUtils.getIntegerAttribute(config, CHANNEL_ID, null); if(id == null){ theLogger.log(Level.WARNING, "Unable to find " + CHANNEL_ID + " attribute for Channel, using -1."); id = -1; } String name = XMLConfigUtils.getStringAttribute(config, CHANNEL_NAME, null); Channel channel = new Channel(id, name); HierarchicalConfiguration pathsConfig = config.configurationAt(MOTION_PATHS); if(pathsConfig == null || pathsConfig.isEmpty()){ return channel; } List<MotionPath> paths = readMotionPaths(pathsConfig); channel.addPaths(paths); return channel; }
/** * * @param xs * @param channel * @throws IOException */ public static void writeChannel(XmlSerializer xs, Channel channel) throws IOException{ xs.startTag(NAMESPACE, CHANNEL); xs.attribute(NAMESPACE, CHANNEL_ID, channel.getId().toString()); String name = channel.getName(); if(name != null && !name.isEmpty()){ xs.attribute(NAMESPACE, CHANNEL_NAME, name); } xs.startTag(NAMESPACE, MOTION_PATHS); for(MotionPath mp : channel.getMotionPaths()){ writeMotionPath(xs, mp); } xs.endTag(NAMESPACE, MOTION_PATHS); xs.endTag(NAMESPACE, CHANNEL); }
public static ConfigurationNode writeMotionPath(MotionPath mp){ if(mp == null){ return null; } ConfigurationNode node = XMLConfigUtils.node(MOTION_PATH); String name = mp.getName(); if(name != null && !name.isEmpty()){ node.addAttribute(XMLConfigUtils.node(MOTION_PATH_NAME, name)); } node.addChild(XMLConfigUtils.writeVersion(mp.getInterpolatorVersion(), INTERPOLATION_VERSION_TYPE)); node.addChild(writeControlPoints(mp.getControlPoints())); return node; }