1 package com.neuronrobotics.sdk.dyio.sequencer;
4 import com.neuronrobotics.sdk.common.Log;
5 import java.io.FileInputStream;
6 import java.io.IOException;
7 import java.util.ArrayList;
9 import javax.xml.parsers.DocumentBuilder;
10 import javax.xml.parsers.DocumentBuilderFactory;
11 import javax.xml.parsers.ParserConfigurationException;
13 import org.w3c.dom.Document;
14 import org.w3c.dom.Element;
15 import org.w3c.dom.Node;
16 import org.w3c.dom.NodeList;
17 import org.xml.sax.SAXException;
19 import com.neuronrobotics.sdk.dyio.DyIO;
20 import com.neuronrobotics.sdk.dyio.peripherals.ServoChannel;
21 import com.neuronrobotics.sdk.util.ThreadUtil;
44 private boolean loop =
false;
47 private ArrayList< ISchedulerListener>
listeners =
new ArrayList< ISchedulerListener>();
50 private ArrayList< ServoOutputScheduleChannel>
outputs =
new ArrayList< ServoOutputScheduleChannel>();
106 DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
107 DocumentBuilder dBuilder;
110 dBuilder = dbFactory.newDocumentBuilder();
111 doc = dBuilder.parse(
new FileInputStream(f));
112 doc.getDocumentElement().normalize();
113 }
catch (ParserConfigurationException e) {
114 throw new RuntimeException(e);
115 }
catch (SAXException e) {
116 throw new RuntimeException(e);
117 }
catch (IOException e) {
118 throw new RuntimeException(e);
121 NodeList nList = doc.getElementsByTagName(
"ServoOutputSequenceGroup");
122 for (
int temp = 0; temp < nList.getLength(); temp++) {
124 Node nNode = nList.item(temp);
125 if (nNode.getNodeType() == Node.ELEMENT_NODE) {
126 Element eElement = (Element) nNode;
135 NodeList links = eElement.getElementsByTagName(
"ServoOutputSequence");
136 for (
int i = 0; i < links.getLength(); i++) {
138 Node lNode = links.item(i);
139 if (lNode.getNodeType() == Node.ELEMENT_NODE) {
140 Element lElement = (Element) lNode;
141 int max=Integer.parseInt(
getTagValue(
"outputMax",lElement));
142 int min=Integer.parseInt(
getTagValue(
"outputMin",lElement));
143 int channel=Integer.parseInt(
getTagValue(
"outputChannel",lElement));
144 boolean enabled =
getTagValue(
"inputEnabled",lElement).contains(
"true");
146 double inScale=Double.parseDouble(
getTagValue(
"inputScale",lElement));
147 int outCenter=Integer.parseInt(
getTagValue(
"outputCenter",lElement));
148 int inChannel=Integer.parseInt(
getTagValue(
"inputChannel",lElement));
150 String [] sdata =
getTagValue(
"data",lElement).split(
",");
151 int []data=
new int[sdata.length];
152 for(
int j=0;j<data.length;j++){
153 data[j]=Integer.parseInt(sdata[j]);
156 for(
int j=1;j<data.length-1;j++){
157 int before = data[j-1];
158 int current = data[j];
159 int after = data[j+1];
160 if(current == 0 &&before!=0 && after!=0){
161 System.out.println(
"Smoothing xml");
162 data[j]=(before+after)/2;
183 System.out.println(
"Populated Scheduler");
194 NodeList nlList= eElement.getElementsByTagName(sTag).item(0).getChildNodes();
195 Node nValue = (Node) nlList.item(0);
197 return nValue.getNodeValue();
212 System.out.println(
"Setting track length: "+
msDuration);
262 System.out.println(
"Adding DyIO channel: "+dyIOChannel);
307 throw new RuntimeException(
"The sequence paramaters are not set");
372 s.onTimeUpdate(time);
376 l.onTimeUpdate(time);
415 s+=
"<ServoOutputSequenceGroup>\n";
419 s+=
"\t<duriation>"+
msDuration+
"</duriation>\n";
425 s+=
"</ServoOutputSequenceGroup>\n";
462 setName(
"DyIO scheduler flush thread");
466 long start = System.currentTimeMillis();
471 s.sync((
int) seconds);
476 flushTime = System.currentTimeMillis()-start;
484 }
catch (InterruptedException e) {
529 private boolean run =
true;
532 long start = System.currentTimeMillis();
564 playing = (((double)(System.currentTimeMillis()-start))<(
time-
StartOffset));
565 current =((System.currentTimeMillis()-start))+
StartOffset;
590 long start = System.currentTimeMillis();
void setCachedMode(boolean mode)
void flushCache(double seconds)
boolean SetPosition(int pos)
void setPause(boolean pause)
SchedulerThread(double ms, final long so)
ArrayList< ServoOutputScheduleChannel > outputs
void addISchedulerListener(ISchedulerListener l)
void setLoopTime(int loopTime)
void removeISchedulerListener(ISchedulerListener l)
void setAudioFile(File f)
static String getTagValue(String sTag, Element eElement)
void setSt(SchedulerThread st)
void setSequenceParams(int setpoint, long StartOffset)
void setLooping(boolean b)
void setCurrentTime(long time)
ArrayList< ISchedulerListener > listeners
ArrayList< ServoOutputScheduleChannel > getOutputs()
CoreScheduler(DyIO d, File f)
CoreScheduler(DyIO d, int loopTime, int duration)
void loadFromFile(File f)
ServoOutputScheduleChannel addServoChannel(int dyIOChannel)
void play(int setpoint, long StartOffset)
void setOutputs(ArrayList< ServoOutputScheduleChannel > outputs)
void removeServoOutputScheduleChannel(ServoOutputScheduleChannel s)
void setCurrentTime(int time)
void setOutputMinMax(int outputMin, int outputMax)
void setInputCenter(int inputCenter)
void setIntervalTime(int msInterval, int totalTime)
void setData(int[] data2)
void setInputScale(double inputScale)
void setAnalogInputChannelNumber(int analogInputChannelNumber)
static void wait(int time)