10 package com.generalrobotix.ui.view.graph;
14 import javax.vecmath.AxisAngle4d;
15 import javax.vecmath.Matrix3d;
37 private static final double LOG10 = Math.log(10);
79 timeAxisInfo_.
min = 0;
88 dataItemCount_ =
new HashMap<String, Integer >();
89 dataModelMap_ =
new HashMap<String, DataModel>();
90 attitudeDataModelMap_ =
new HashMap<String, AttitudeDataModel>();
91 dataModelArray_ =
null;
94 for (
int i = 0;
i < trendGraph_.length;
i ++) {
95 StringBuffer graphName =
new StringBuffer(
"Graph");
97 trendGraph_[
i] =
new TrendGraph(
this, graphName.toString());
102 return trendGraph_.length;
106 return trendGraph_[index];
110 if (index < 0 || index >= trendGraph_.length) {
111 throw new ArrayIndexOutOfBoundsException();
113 StringBuffer graphName =
new StringBuffer(
"Graph");
114 graphName.append(index);
115 return graphName.toString();
120 for (
int i = 0;
i < trendGraph_.length;
i ++) {
144 stepTimeCount_ = stepTime;
147 sampleCount_ = (
int)Math.floor(timeRange_ / stepTime_) + 2;
148 baseCount_ = Math.round(baseTime_ / stepTime_);
151 Iterator<DataModel> itr = dataModelMap_.values().iterator();
152 while (itr.hasNext()) {
158 Iterator<AttitudeDataModel> itr0 = attitudeDataModelMap_.values().iterator();
159 while (itr0.hasNext()) {
161 for(
int i=0;
i<3;
i++){
177 totalTime_ = totalTime;
191 timeRange_ = timeRange;
192 fixedMarkerPos_ = markerPos;
244 long totalCount = Math.round(totalTime_ / stepTime_);
245 markerFixed_ = (timeRange_ * fixedMarkerPos_ <
totalTime_);
248 baseTime_ = currentTime_ - timeRange_ *
markerPos_;
249 baseCount_ = Math.round(baseTime_ / stepTime_);
259 if (dataModelArray_ ==
null) {
268 int diff = (
int)(baseCount_ - oldBaseCount);
271 Iterator<DataModel> itr = dataModelMap_.values().iterator();
272 while (itr.hasNext()) {
276 Iterator<AttitudeDataModel> itr0 = attitudeDataModelMap_.values().iterator();
277 while (itr0.hasNext()) {
279 for(
int i=0;
i<3;
i++){
286 if(prevLogSize_ < totalCount)
288 int yet = (
int)(baseCount_ + sampleCount_ - prevLogSize_);
292 prevLogSize_ = totalCount;
295 if (diff >= sampleCount_) {
296 _getData(baseCount_, 0, sampleCount_);
298 _getData(baseCount_, sampleCount_ - diff, diff);
301 if (-diff >= sampleCount_) {
302 _getData(baseCount_, 0, sampleCount_);
322 Integer l = dataItemCount_.get(key);
324 if(key.contains(
"attitude")){
326 if(attitudeDataModel==
null){
330 ds =
new DataSeries(sampleCount_, baseCount_ * stepTime_, stepTime_ );
332 for(
int i=0;
i<4;
i++){
337 dataModelMap_.put(di.
toString(), dm);
341 dataItemCount_.put(key,
new Integer(1));
343 dataItemCount_.put(key,
new Integer(1));
346 baseCount_ * stepTime_,
350 dataModelMap_.put(key, dm);
352 dataModelArray_ =
new DataModel[dataModelMap_.size()];
353 dataModelMap_.values().toArray(dataModelArray_);
355 dataItemCount_.put(key, ++l);
356 if(key.contains(
"attitude"))
359 ds = ((
DataModel)dataModelMap_.get(key)).dataSeries;
376 Integer l = dataItemCount_.get(key);
377 dataItemCount_.put(key, --l);
378 if(key.contains(
"attitude")){
380 dataItemCount_.remove(key);
386 for(
int i=0;
i<4;
i++)
388 int size = dataModelMap_.size();
390 dataModelArray_ =
null;
393 dataModelMap_.values().toArray(dataModelArray_);
398 dataItemCount_.remove(key);
399 dataModelMap_.remove(key);
400 int size = dataModelMap_.size();
402 dataModelArray_ =
null;
405 dataModelMap_.values().toArray(dataModelArray_);
421 int eMin = (
int)Math.floor(Math.log(sMin) /
LOG10);
425 boolean found =
false;
428 for (
int i = 1;
i <= 3;
i++) {
429 step = m * Math.pow(10.0, e);
432 char[]
c =
new char[-e + 2];
435 for (
int j = 0;
j < -e;
j++) {
438 format =
new String(c);
471 double step = world_.
getDbl(
"logTimeStep", 0.001);
473 }
catch (Exception e) {
484 if(dataModelArray_ !=
null && world_ !=
null)
486 world_.
logger_.initGetData(dataModelArray_);
490 private void _getData(
long origin,
int offset,
int count){
494 world_.
logger_.getData(origin, offset, count);
497 int counter = changePos - ((
int)origin + offset);
500 if( changePos >= 0 ){
502 world_.
logger_.getData(-offset-counter, offset, count, dataModelArray_);
506 if( counter <= count ){
508 world_.
logger_.getData(-offset-counter, offset + counter, count, dataModelArray_);
514 if(refWorld ==
null){
515 for(
int h = 0; h < dataModelArray_.length; ++h){
517 double[] dbArray = ds.
getData();
518 int localOffset = (ds.
getHeadPos() + offset) % dbArray.length;
519 for (
int i = 0;
i < count; ++
i, ++localOffset){
520 if(localOffset +
i >= dbArray.length){
523 dbArray[localOffset] = Double.NaN;
528 for(
int h = 0; h < dataModelArray_.length; ++h){
529 long recNo = origin + offset;
534 double[] dbArray = ds.
getData();
535 int localOffset = (ds.
getHeadPos() + offset) % dbArray.length;
537 localDataItem.
node +
"." + localDataItem.
attribute + (localDataItem.
index >= 0 ?
"." + localDataItem.
index :
"") );
538 ArrayList<Integer> arryLength =
new ArrayList<Integer>();
539 arryLength.add(refCharacter.
position.length * 7);
540 arryLength.add(arryLength.get(0) + refCharacter.
sensorState.q.length);
541 arryLength.add(arryLength.get(1) + refCharacter.
sensorState.u.length);
543 arryLength.add( arryLength.get(2));
545 arryLength.add( arryLength.get(2) +
550 arryLength.add( arryLength.get(3));
552 arryLength.add( arryLength.get(3) +
557 arryLength.add( arryLength.get(4));
559 arryLength.add( arryLength.get(4) +
563 arryLength.add( arryLength.get(5));
565 arryLength.add( arryLength.get(5) +
569 for (
int i = 0;
i < count; ++
i, ++recNo, ++localOffset){
570 if(localOffset >= dbArray.length){
573 if(recNo < 0 || recNo >= world_.
getLogSize() || localCharacter ==
null){
574 dbArray[localOffset] = Double.NaN;
577 if (
index <= arryLength.get(0)){
580 }
else if (
index <= arryLength.get(2)){
581 if( (
index - 1) % 2 == 0 ){
582 dbArray[localOffset] = localCharacter.
sensorState.q[(
index - arryLength.get(0) - 1)/2];
584 dbArray[localOffset] = localCharacter.
sensorState.u[(
index - arryLength.get(0) - 2)/2];
586 }
else if (
index <= arryLength.get(3) && localCharacter.
sensorState.force.length > 0){
587 int dim1 = (
index - arryLength.get(2) - 1) / localCharacter.
sensorState.force[0].length ;
588 int dim2 = (
index - arryLength.get(2) - 1) % localCharacter.
sensorState.force[0].length ;
589 dbArray[localOffset] = localCharacter.
sensorState.force[dim1][dim2];
591 }
else if (
index <= arryLength.get(4) && localCharacter.
sensorState.rateGyro.length > 0){
592 int dim1 = (
index - arryLength.get(3) - 1) / localCharacter.
sensorState.rateGyro[0].length ;
593 int dim2 = (
index - arryLength.get(3) - 1) % localCharacter.
sensorState.rateGyro[0].length ;
594 dbArray[localOffset] = localCharacter.
sensorState.rateGyro[dim1][dim2];
595 }
else if (
index <= arryLength.get(5) && localCharacter.
sensorState.accel.length > 0){
596 int dim1 = (
index - arryLength.get(4) - 1) / localCharacter.
sensorState.accel[0].length ;
597 int dim2 = (
index - arryLength.get(4) - 1) % localCharacter.
sensorState.accel[0].length ;
598 dbArray[localOffset] = localCharacter.
sensorState.accel[dim1][dim2];
599 }
else if(localCharacter.
sensorState.range.length > 0) {
600 int dim1 = (
index - arryLength.get(5) - 1) / localCharacter.
sensorState.range[0].length ;
601 int dim2 = (
index - arryLength.get(5) - 1) % localCharacter.
sensorState.range[0].length ;
602 dbArray[localOffset] = localCharacter.
sensorState.range[dim1][dim2];
611 Iterator<AttitudeDataModel> it = attitudeDataModelMap_.values().iterator();
614 double[][] aa =
new double[4][];
615 int[] aapos =
new int[4];
616 int[] aaSize =
new int[4];
617 for(
int i=0;
i<4;
i++){
623 double[][] rpy = {
null,
null, null};
624 int[] rpypos =
new int[3];
625 int[] rpySize =
new int[3];
626 for(
int i=0;
i<3;
i++){
634 for (
int i = 0;
i < count;
i++) {
635 if(aa[0][aapos[0]] == Double.NaN || aa[1][aapos[1]] == Double.NaN || aa[2][aapos[2]] == Double.NaN || aa[3][aapos[3]] == Double.NaN){
636 if(rpy[0]!=null) rpy[0][rpypos[0]] = Double.NaN;
637 if(rpy[1]!=null) rpy[1][rpypos[1]] = Double.NaN;
638 if(rpy[2]!=null) rpy[2][rpypos[2]] = Double.NaN;
641 for(
int j=0;
j<4;
j++){
642 if(aapos[
j] < aaSize[
j]-1)
647 for(
int j=0;
j<3;
j++){
648 if(rpypos[
j] < rpySize[
j]-1)
659 Double time = world_.
getTime();
666 gPanel_.redraw(gPanel_.getLocation().x,gPanel_.getLocation().y,gPanel_.getSize().x,gPanel_.getSize().y,
true);
681 private void AxisAngleToRPY(
double[][] aa,
double[][] rpy,
int[] aapos,
int[] rpypos){
682 Matrix3d m =
new Matrix3d();
683 m.set(
new AxisAngle4d(aa[0][aapos[0]], aa[1][aapos[1]], aa[2][aapos[2]], aa[3][aapos[3]]));
686 double roll, pitch, yaw;
687 if ((Math.abs(m.m00)<Math.abs(m.m20)) && (Math.abs(m.m10)<Math.abs(m.m20))) {
691 }
else if (sp > 1.0) {
694 pitch = Math.asin(sp);
696 roll = Math.atan2(sp*m.m01+m.m12,
705 double sr=Math.sin(roll), cr=Math.cos(roll);
707 yaw = Math.atan2(sr*m.m11+cr*m.m12,
710 yaw = Math.atan2(-sr*m.m11-cr*m.m12,
714 yaw = Math.atan2(m.m10, m.m00);
715 double sa = Math.sin(yaw);
716 double ca = Math.cos(yaw);
717 pitch = Math.atan2(-m.m20, ca*m.m00+sa*m.m10);
718 roll = Math.atan2(sa*m.m02-ca*m.m12, -sa*m.m01+ca*m.m11);
721 if(rpy[0]!=
null) rpy[0][rpypos[0]] = roll;
722 if(rpy[1]!=
null) rpy[1][rpypos[1]] = pitch;
723 if(rpy[2]!=
null) rpy[2][rpypos[2]] = yaw;
734 axisAngleSeries[
i] = dataSeries;
738 rpySeries[
i] = dataSeries;
742 return rpySeries[0]==null && rpySeries[1]==null && rpySeries[2]==
null ;
HashMap< String, DataModel > dataModelMap_
void AxisAngleToRPY(double[][] aa, double[][] rpy, int[] aapos, int[] rpypos)
void setTotalTime(double totalTime)
void setXOffset(double xOffset)
#define null
our own NULL pointer
HashMap< String, Integer > dataItemCount_
final DataSeries dataSeries
AxisInfo getTimeAxisInfo()
CharacterStateEx get(int idx)
void worldTimeChanged(Time time)
void setAxisAngleSeries(int i, DataSeries dataSeries)
DataSeries[] axisAngleSeries
TrendGraphModel(int numGraph)
String getAttributePath()
static void printErr(String s)
void setWorldState(GrxWorldStateItem world)
void setXStep(double xStep)
static Activator getDefault()
DataModel[] dataModelArray_
void setRPYSeries(int i, DataSeries dataSeries)
def j(str, encoding="cp932")
String getTrendGraphName(int index)
DataSeries addDataItem(DataItem dataItem)
static final double LOG10
void _getData(long origin, int offset, int count)
final Double getDbl(String key, Double defaultVal)
get double value associated to key
void setRangeAndPos(double timeRange, double markerPos)
void setCurrentTime(long currentTime)
void setPanel(GraphPanel gPanel)
HashMap< String, AttitudeDataModel > attitudeDataModelMap_
static final double TIME_SCALE
void setStepTime(long stepTime)
static final double MAX_DIV
void removeDataItem(DataItem dataItem)
TrendGraph getTrendGraph(int index)