GrxRobotStatView.java
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2008, AIST, the University of Tokyo and General Robotix Inc.
3  * All rights reserved. This program is made available under the terms of the
4  * Eclipse Public License v1.0 which accompanies this distribution, and is
5  * available at http://www.eclipse.org/legal/epl-v10.html
6  * Contributors:
7  * General Robotix Inc.
8  * National Institute of Advanced Industrial Science and Technology (AIST)
9  */
10 /*
11  * GrxRobotStatView.java
12  *
13  * Copyright (C) 2007 GeneralRobotix, Inc.
14  * All Rights Reserved
15  *
16  * @author Yuichiro Kawasumi (General Robotix, Inc.)
17  */
18 
19 package com.generalrobotix.ui.view;
20 
21 import java.text.DecimalFormat;
22 import java.util.ArrayList;
23 import java.util.Iterator;
24 import java.util.List;
25 import java.util.Vector;
26 
27 import jp.go.aist.hrp.simulator.SensorState;
28 
29 import org.eclipse.jface.layout.AbstractColumnLayout;
30 import org.eclipse.jface.layout.TableColumnLayout;
31 import org.eclipse.jface.viewers.ArrayContentProvider;
32 import org.eclipse.jface.viewers.ColumnWeightData;
33 import org.eclipse.jface.viewers.ILabelProviderListener;
34 import org.eclipse.jface.viewers.ITableColorProvider;
35 import org.eclipse.jface.viewers.ITableFontProvider;
36 import org.eclipse.jface.viewers.ITableLabelProvider;
37 import org.eclipse.jface.viewers.TableViewer;
38 import org.eclipse.swt.SWT;
39 import org.eclipse.swt.events.ControlEvent;
40 import org.eclipse.swt.events.ControlListener;
41 import org.eclipse.swt.events.SelectionAdapter;
42 import org.eclipse.swt.events.SelectionEvent;
43 import org.eclipse.swt.graphics.Color;
44 import org.eclipse.swt.graphics.Font;
45 import org.eclipse.swt.graphics.Image;
46 import org.eclipse.swt.graphics.Point;
47 import org.eclipse.swt.layout.GridData;
48 import org.eclipse.swt.layout.GridLayout;
49 import org.eclipse.swt.widgets.Combo;
50 import org.eclipse.swt.widgets.Composite;
51 import org.eclipse.swt.widgets.Event;
52 import org.eclipse.swt.widgets.Listener;
53 import org.eclipse.swt.widgets.TableColumn;
54 
67 
68 @SuppressWarnings("serial")
69 public class GrxRobotStatView extends GrxBaseView {
70  public static final String TITLE = "Robot State";
71 
72  private static final DecimalFormat FORMAT1 = new DecimalFormat(" 0.0;-0.0");
73  private static final DecimalFormat FORMAT2 = new DecimalFormat(" 0.000;-0.000");
74 
75  private Font plainFont_;
76  private Font boldFont_;
77 
78  private GrxWorldStateItem currentWorld_ = null;
79  private GrxModelItem currentModel_ = null;
80  private SensorState currentSensor_;
81  private double[] currentRefAng_;
82  private int[] currentSvStat_;
83  private double[] currentPower_;
84  private WorldStateEx currentState_ = null;
85 
86  private List<GrxLinkItem> jointList_ = new ArrayList<GrxLinkItem>();
87  private String[] forceName_;
88  private String[] gyroName_;
89  private String[] accName_;
90 
91  private Combo comboModelName_;
92  private List<GrxModelItem> modelList_;
93 
94  private TableViewer[] viewers_;
95  private TableViewer jointTV_;
96  private TableViewer sensorTV_;
97 
98  //private Label lblInstruction1_;// = new Label("Select Model Item on ItemView");
99  //private Label lblInstruction2_;
100 
101  private Color white_;
102  private Color black_;
103  private Color red_;
104  private Color blue_;
105  private Color yellow_;
106 
107  private String osName_ = "Windows";
108 
109  private static final int COMBO_WIDTH = 100;
110  private int [][] columnWidth_ = new int[][]{
111  {5,16,11,11,11,7,7,7,7,9,9},
112  {22,13,13,13,13,13,13},
113  {30,90,60,60,60,40,40,40,40,50,50},
114  {110,75,75,75,75,75,75}
115  };
116  private Composite[] viewPanel_ = new Composite[2];
117  private Composite mainPanel_;
118 
119  public GrxRobotStatView(String name, GrxPluginManager manager, GrxBaseViewPart vp, Composite parent) {
120  super(name, manager,vp,parent);
121  osName_ = System.getProperty("os.name");
122 
123  white_ = Activator.getDefault().getColor("white");
124  black_ = Activator.getDefault().getColor("black");
125  red_ = Activator.getDefault().getColor("red");
126  blue_ = Activator.getDefault().getColor("blue");
127  yellow_ = Activator.getDefault().getColor("yellow");
128 
129  mainPanel_ = new Composite(composite_, SWT.NONE);
130  GridLayout gridLayout = new GridLayout(1,false);
131  gridLayout.marginHeight = 0;
132  gridLayout.verticalSpacing = 0;
133  mainPanel_.setLayout(gridLayout);
134  modelList_ = new ArrayList<GrxModelItem>();
135 
136  comboModelName_ = new Combo(mainPanel_,SWT.READ_ONLY);
137  GridData gridData = new GridData();
138  gridData.widthHint = COMBO_WIDTH;
139  comboModelName_.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
140 
141  comboModelName_.addSelectionListener(new SelectionAdapter(){
142  //選択が変更されたとき呼び出される
143  public void widgetSelected(SelectionEvent e) {
144  GrxModelItem item = modelList_.get(comboModelName_.getSelectionIndex());
145  if (item == null || item == currentModel_)
146  return;
147 
148  currentModel_ = item;
149  setJointList();
150  updateTableViewer();
151  }
152 
153  });
154 
155  String[][] header = new String[][] {
156  { "No", "Joint", "Angle", "Target", "Torque", "PWR", "SRV", "ARM", "T", "Pgain", "Dgain" },
157  { "1","2","3","4","5","6","7"},
158  };
159  boolean showheader[] = {true, false};
160  int[][] alignment = new int[][] {
161  { SWT.RIGHT, SWT.LEFT, SWT.RIGHT, SWT.RIGHT, SWT.RIGHT, SWT.CENTER, SWT.CENTER, SWT.RIGHT, SWT.RIGHT, SWT.RIGHT, SWT.RIGHT },
162  { SWT.LEFT, SWT.RIGHT, SWT.RIGHT, SWT.RIGHT, SWT.RIGHT, SWT.RIGHT, SWT.RIGHT, SWT.RIGHT },
163  };
164 
165  for(int i=0; i<2; i++){
166  viewPanel_[i] = new Composite(mainPanel_, SWT.NONE);
167  viewPanel_[i].setLayoutData(new GridData(GridData.FILL_BOTH));
168  GridLayout gridLayout1 = new GridLayout();
169  gridLayout1.marginHeight = 0;
170  gridLayout1.marginWidth = 0;
171  gridLayout1.horizontalSpacing = 0;
172  gridLayout1.verticalSpacing = 0;
173  viewPanel_[i].setLayout(gridLayout1);
174  }
175 
176  jointTV_ = new TableViewer(viewPanel_[0],SWT.BORDER|SWT.FULL_SELECTION|SWT.VIRTUAL);
177  sensorTV_ = new TableViewer(viewPanel_[1],SWT.BORDER|SWT.FULL_SELECTION|SWT.VIRTUAL);
178 
179  jointTV_.setContentProvider(new ArrayContentProvider());
180  sensorTV_.setContentProvider(new ArrayContentProvider());
181 
182  jointTV_.setLabelProvider(new JointTableLabelProvider());
183  sensorTV_.setLabelProvider(new SensorTableLabelProvider());
184 
185  viewers_ = new TableViewer[]{jointTV_,sensorTV_};
186  TableColumnLayout[] layout = new TableColumnLayout[2];
187  for(int i=0;i<viewers_.length;i++){
188  layout[i] = new TableColumnLayout();
189  for(int j=0;j<header[i].length;j++){
190  TableColumn column = new TableColumn(viewers_[i].getTable(),SWT.NULL);
191  column.setText(header[i][j]);
192  column.setAlignment(alignment[i][j]);
193  layout[i].setColumnData(column, new ColumnWeightData(columnWidth_[i][j],columnWidth_[i+2][j]));
194  if(i==0)
195  column.addControlListener(new ControlListener(){
196  public void controlMoved(ControlEvent e) {
197  }
198  public void controlResized(ControlEvent e) {
199  TableColumn column = (TableColumn)e.getSource();
200  int i = jointTV_.getTable().indexOf(column);
201  int width = column.getWidth();
202  setInt("jcolumnWidth"+i, width);
203  }
204  });
205  else if(i==1)
206  column.addControlListener(new ControlListener(){
207  public void controlMoved(ControlEvent e) {
208  }
209  public void controlResized(ControlEvent e) {
210  TableColumn column = (TableColumn)e.getSource();
211  int i = sensorTV_.getTable().indexOf(column);
212  int width = column.getWidth();
213  setInt("scolumnWidth"+i, width);
214  }
215  });
216  }
217  viewPanel_[i].setLayout(layout[i]);
218  viewers_[i].getTable().setHeaderVisible(showheader[i]);
219  viewers_[i].getTable().setLinesVisible(true);
220  viewers_[i].getTable().setLayoutData(new GridData(GridData.FILL_BOTH));
221  }
222  //setScrollMinSize(SWT.DEFAULT,SWT.DEFAULT);
223 
224  setUp();
225  manager_.registerItemChangeListener(this, GrxModelItem.class);
226  manager_.registerItemChangeListener(this, GrxWorldStateItem.class);
227 
228  }
229 
230  public void setUp(){
231  Iterator<GrxModelItem> it = modelList_.iterator();
232  while(it.hasNext()){
233  GrxModelItem modelItem = it.next();
234  modelItem.deleteObserver(this);
235  comboModelName_.remove(modelItem.getName());
236  }
237  modelList_ = manager_.<GrxModelItem>getSelectedItemList(GrxModelItem.class);
238  if(!modelList_.isEmpty()){
239  it = modelList_.iterator();
240  while(it.hasNext()){
241  GrxModelItem model = it.next();
242  comboModelName_.add(model.getName());
243  model.addObserver(this);
244  }
245  comboModelName_.select(0);
246  currentModel_ = modelList_.get(0);
247  setJointList();
248  }else
249  currentModel_ = null;
250  if(currentWorld_ != null ){
251  currentWorld_.deleteObserver(this);
252  currentWorld_.deletePosObserver(this);
253  }
254  currentWorld_ = manager_.<GrxWorldStateItem>getSelectedItem(GrxWorldStateItem.class, null);
255  if(currentWorld_!=null){
256  currentState_ = currentWorld_.getValue();
257  currentWorld_.addObserver(this);
258  currentWorld_.addPosObserver(this);
259  updatePosition(currentWorld_, currentWorld_.getPosition());
260  }
261  updateTableFont();
262  updateTableViewer();
263  }
264 
265 
266  //TableViewer#setInputには
267  //これらの_create○○TVInput()の戻り値を与えている。
268  //具体的には表示したい行数分の長さを持ったInteger型配列
269  //行番号を値としてもつ
270  //LabelProviderはgetColumnText()内でこのInputを行番号として扱いカラムのテキストを設定する
271  //(Swingからの移植を容易にするための処置)
272  private Integer[] _createJointTVInput(){
273  Integer[] input = new Integer[jointList_.size()];
274  for(int i=0;i<input.length;i++){
275  input[i] = i;
276  }
277  return input;
278  }
279 
280  private Integer[] _createSensorTVInput(){
281  int length = 0;
282  if(forceName_ != null){
283  length += forceName_.length;
284  if (forceName_.length >= 2 && forceName_[0].equals("rfsensor") && forceName_[1].equals("lfsensor")){
285  length += 1; // ZMP
286  }
287  }
288  if(gyroName_ != null)
289  length += gyroName_.length;
290  if(accName_ != null)
291  length += accName_.length;
292  length += 1; // power
293  Integer[] input = new Integer[length];
294  for(int i=0;i<input.length;i++){
295  input[i] = i;
296  }
297  return input;
298  }
299 
300  public boolean propertyChanged(String key, String value){
301  if (super.propertyChanged(key, value)){
302  return true;
303  }else {
304  if (key.startsWith("jcolumnWidth")){
305  int i = Integer.parseInt(key.replace("jcolumnWidth", ""));
306  int width = Integer.parseInt(value.trim());
307  int w = jointTV_.getTable().getSize().x;
308  int width0 = width*100/w;
309  int width1;
310  if(width < columnWidth_[2][i])
311  width1 = width;
312  else
313  width1 = columnWidth_[2][i];
314  ((AbstractColumnLayout) viewPanel_[0].getLayout()).setColumnData(jointTV_.getTable().getColumn(i), new ColumnWeightData(width0,width1));
315  viewPanel_[0].layout(true);
316  final String key_ = key;
317  final String value_ = value;
318  syncExec(new Runnable(){
319  public void run(){
320  setProperty(key_, value_);
321  }
322  });
323  return true;
324  }else if (key.startsWith("scolumnWidth")){
325  int i = Integer.parseInt(key.replace("scolumnWidth", ""));
326  int width = Integer.parseInt(value.trim());
327  int w = sensorTV_.getTable().getSize().x;
328  int width0 = width*100/w;
329  int width1;
330  if(width < columnWidth_[3][i])
331  width1 = width;
332  else
333  width1 = columnWidth_[3][i];
334  ((AbstractColumnLayout) viewPanel_[1].getLayout()).setColumnData(sensorTV_.getTable().getColumn(i), new ColumnWeightData(width0,width1));
335  viewPanel_[1].layout(true);
336  final String key_ = key;
337  final String value_ = value;
338  syncExec(new Runnable(){
339  public void run(){
340  setProperty(key_, value_);
341  }
342  });
343  return true;
344  }
345  }
346  return false;
347  }
348 
349 
350  private void setJointList(){
351  jointList_.clear();
352  Vector<GrxLinkItem> lInfo = currentModel_.links_;
353  for (int i = 0; i < lInfo.size(); i++) {
354  for (int j = 0; j < lInfo.size(); j++) {
355  if (i == lInfo.get(j).jointId_) {
356  jointList_.add(lInfo.get(j));
357  break;
358  }
359  }
360  }
361  forceName_ = currentModel_.getSensorNames("Force");
362  gyroName_ = currentModel_.getSensorNames("RateGyro");
363  accName_ = currentModel_.getSensorNames("Acceleration");
364  }
365 
366  public void registerItemChange(GrxBaseItem item, int event){
367  if(item instanceof GrxModelItem){
368  GrxModelItem modelItem = (GrxModelItem) item;
369  switch(event){
371  if(!modelList_.contains(modelItem)){
372  modelList_.add(modelItem);
373  comboModelName_.add(modelItem.getName());
374  modelItem.addObserver(this);
375  if(currentModel_ == null){
376  currentModel_ = modelItem;
377  comboModelName_.select(comboModelName_.indexOf(modelItem.getName()));
378  setJointList();
379  updateTableViewer();
380  }
381  }
382  break;
385  if(modelList_.contains(modelItem)){
386  int index = modelList_.indexOf(modelItem);
387  modelList_.remove(modelItem);
388  modelItem.deleteObserver(this);
389  comboModelName_.remove(modelItem.getName());
390  if(currentModel_ == modelItem){
391  if(index < modelList_.size()){
392  currentModel_ = modelList_.get(index);
393  comboModelName_.select(comboModelName_.indexOf(currentModel_.getName()));
394  setJointList();
395  updateTableViewer();
396  }else{
397  index--;
398  if(index >= 0 ){
399  currentModel_ = modelList_.get(index);
400  comboModelName_.select(comboModelName_.indexOf(currentModel_.getName()));
401  setJointList();
402  updateTableViewer();
403  }else{
404  currentModel_ = null;
405  jointList_.clear();
406  updateTableViewer();
407  }
408  }
409 
410  }
411  }
412  break;
413  default:
414  break;
415  }
416  }else if(item instanceof GrxWorldStateItem){
417  GrxWorldStateItem worldStateItem = (GrxWorldStateItem) item;
418  switch(event){
420  if(currentWorld_ != worldStateItem){
421  currentWorld_ = worldStateItem;
422  currentState_ = currentWorld_.getValue();
423  updatePosition(currentWorld_, currentWorld_.getPosition());
424  currentWorld_.addObserver(this);
425  currentWorld_.addPosObserver(this);
426  }
427  break;
430  if(currentWorld_ == worldStateItem){
431  currentWorld_.deleteObserver(this);
432  currentWorld_.deletePosObserver(this);
433  currentWorld_ = null;
434  currentState_ = null;
435  updateTableViewer();
436  }
437  break;
438  default:
439  break;
440  }
441  }
442  }
443 
444  public void update(GrxBasePlugin plugin, Object... arg){
445  if(currentWorld_ == plugin ){
446  if((String)arg[0]=="ClearLog"){
447  currentState_ = null;
448  }
449  }else if(modelList_.contains(plugin)){
450  if( (String)arg[0] == "PropertyChange" ){
451  if( (String)arg[1] == "name" ){
452  int index = comboModelName_.indexOf(plugin.getOldName());
453  comboModelName_.setItem(index, (String)arg[2]);
454  }
455  }
456  }
457  }
458 
459  public void updatePosition(GrxBasePlugin plugin, Integer arg_pos){
460  if(currentWorld_ != plugin)
461  return;
462 
463  int pos = arg_pos.intValue();
464  currentState_ = currentWorld_.getValue(pos);
465  _refresh();
466  }
467 
468  private void updateTableViewer(){
469  if (currentModel_ == null ){
470  jointTV_.setInput(new Integer[0]);
471  sensorTV_.setInput(new Integer[0]);
472  return;
473  }
474  currentSensor_ = null;
475  currentRefAng_ = null;
476  currentSvStat_ = null;
477  currentPower_ = null;
478  if (currentState_ != null) {
479  CharacterStateEx charStat = currentState_.get(currentModel_.getName());
480  if (charStat != null) {
481  currentSensor_ = charStat.sensorState;
482  currentRefAng_ = charStat.targetState;
483  currentSvStat_ = charStat.servoState;
484  currentPower_ = charStat.powerState;
485  }
486  }
487  jointTV_.setInput(_createJointTVInput());
488  sensorTV_.setInput(_createSensorTVInput());
489  viewPanel_[0].layout();
490  viewPanel_[1].layout();
491 
492  Point point = jointTV_.getTable().computeSize(SWT.DEFAULT, SWT.DEFAULT);
493  jointTV_.getTable().setSize(point);
494  Point point1 = sensorTV_.getTable().computeSize(SWT.DEFAULT, SWT.DEFAULT);
495  sensorTV_.getTable().setSize(point1);
496  setScrollMinSize(0, point.y+point1.y);
497  mainPanel_.layout(true);
498  }
499 
500  private void _refresh(){
501  if (currentModel_ == null ) return;
502  currentSensor_ = null;
503  currentRefAng_ = null;
504  currentSvStat_ = null;
505  currentPower_ = null;
506  if (currentState_ != null) {
507  CharacterStateEx charStat = currentState_.get(currentModel_.getName());
508  if (charStat != null) {
509  currentSensor_ = charStat.sensorState;
510  currentRefAng_ = charStat.targetState;
511  currentSvStat_ = charStat.servoState;
512  currentPower_ = charStat.powerState;
513  }
514  }
515  jointTV_.refresh();
516  sensorTV_.refresh();
517  }
518 
519  class JointTableLabelProvider implements ITableLabelProvider,ITableColorProvider,ITableFontProvider {
520  final int CALIB_STATE_MASK = 0x00000001;
521  final int SERVO_STATE_MASK = 0x00000002;
522  final int POWER_STATE_MASK = 0x00000004;
523  final int SERVO_ALARM_MASK = 0x0007fff8;
524  final int SERVO_ALARM_SHIFT = 3;
525  final int DRIVER_TEMP_MASK = 0xff000000;
526  final int DRIVER_TEMP_SHIFT = 24;
527 
528  public Image getColumnImage(Object element, int columnIndex) {
529  return null;
530  }
531 
532  public String getColumnText(Object element, int columnIndex) {
533  int rowIndex = ((Integer)element).intValue();
534 
535  /*
536  if (currentModel_ != null) {
537  if (jointList_.get(rowIndex) == currentModel_.activeLinkInfo_) {
538  return "---";
539  }
540  }
541  */
542  switch (columnIndex) {
543  case 0: // id
544  return Integer.toString(rowIndex);
545  case 1: // name
546  if (jointList_.size() <= 0)
547  break;
548  return jointList_.get(rowIndex).getName();
549  case 2: // angle
550  if (currentSensor_ == null)
551  break;
552  return FORMAT2.format(Math.toDegrees(currentSensor_.q[rowIndex]));
553  case 3: // command
554  if (currentRefAng_ == null)
555  break;
556  return FORMAT2.format(Math.toDegrees(currentRefAng_[rowIndex]));
557  case 4: // torque
558  if (currentSensor_ == null || currentSensor_.u == null)
559  break;
560  return FORMAT2.format(currentSensor_.u[rowIndex]);
561 
562  case 5: // power
563  if (currentSvStat_ == null)
564  break;
565  if (_isPowerOn(currentSvStat_[rowIndex])){
566  return "ON";
567  }else{
568  return "OFF";
569  }
570  case 6: // servo
571  if (currentSvStat_ == null)
572  break;
573  if (_isServoOn(currentSvStat_[rowIndex])) {
574  return "ON";
575  } else return "OFF";
576  case 7: // alarm
577  if (currentSvStat_ == null) break;
578  int alarm = _getAlarm(currentSvStat_[rowIndex]);
579  return String.format("%03x", alarm);
580  case 8: // driver temperature
581  if (currentSvStat_ == null) break;
582  int temp = _getDriverTemperature(currentSvStat_[rowIndex]);
583  if (temp == 0){
584  return "---";
585  }else{
586  return String.format("%3d", temp);
587  }
588  case 9: // P gain
589  break;
590  case 10: // D gain
591  break;
592  default:
593  break;
594  }
595  return "---";
596  }
597 
598  public void addListener(ILabelProviderListener listener) {
599  }
600 
601  public void dispose() {
602  }
603 
604  public boolean isLabelProperty(Object element, String property) {
605  return false;
606  }
607 
608  public void removeListener(ILabelProviderListener listener) {
609  }
610 
611  public Color getBackground(Object element, int columnIndex) {
612  int rowIndex = ((Integer)element).intValue();;
613  GrxBaseItem bitem = manager_.focusedItem();
614  if (currentModel_ != null && bitem instanceof GrxLinkItem) {
615  if (jointList_.get(rowIndex) == (GrxLinkItem)bitem) {
616  return yellow_;
617  }
618  }
619  return white_;
620  }
621 
622  public Color getForeground(Object element, int columnIndex) {
623  int rowIndex = ((Integer)element).intValue();
624  if (currentSvStat_ == null) return black_;
625  switch (columnIndex) {
626  case 0:
627  if (!_isCalibrated(currentSvStat_[rowIndex])) {
628  return red_;
629  }
630  break;
631  case 1:
632  case 2:
633  if (jointList_.size() <= 0)
634  break;
635  GrxLinkItem info = jointList_.get(rowIndex);
636  if (info.llimit_ != null && info.ulimit_ != null && info.llimit_[0] < info.ulimit_[0]
637  && (currentSensor_.q[rowIndex] <= info.llimit_[0] || info.ulimit_[0] <= currentSensor_.q[rowIndex])) {
638  return red_;
639  }
640  break;
641  case 5:
642  if (_isPowerOn(currentSvStat_[rowIndex]))
643  return blue_;
644  break;
645  case 6:
646  if (_isServoOn(currentSvStat_[rowIndex]))
647  return red_;
648  break;
649  case 7: // alarm
650  if (_getAlarm(currentSvStat_[rowIndex]) != 0)
651  return red_;
652  break;
653  case 8: // driver temperature
654  if (_getDriverTemperature(currentSvStat_[rowIndex]) > 60){
655  return red_;
656  }
657  break;
658  default:
659  break;
660  }
661 
662  return black_;
663  }
664 
665  public Font getFont(Object element, int columnIndex) {
666  int rowIndex = ((Integer)element).intValue();
667 
668  switch (columnIndex) {
669  case 0:
670  if (currentSvStat_ != null
671  && !_isCalibrated(currentSvStat_[rowIndex])) {
672  return boldFont_;
673  }
674  break;
675  case 2:
676  if(jointList_.isEmpty())
677  break;
678  GrxLinkItem info = jointList_.get(rowIndex);
679  if (info != null && info.llimit_ != null && info.ulimit_ != null && info.llimit_[0] < info.ulimit_[0]
680  && (info.jointValue_ <= info.llimit_[0] || info.ulimit_[0] <= info.jointValue_)) {
681  return boldFont_;
682  }
683  break;
684  case 3:
685  case 4:
686  break;
687  case 5:
688  if (currentSvStat_ == null)
689  break;
690  if (_isPowerOn(currentSvStat_[rowIndex])) {
691  return boldFont_;
692  }
693  break;
694  case 6:
695  if (currentSvStat_ == null)
696  break;
697  if (_isServoOn(currentSvStat_[rowIndex])) {
698  return boldFont_;
699  }
700  break;
701  case 7: // alarm
702  if (currentSvStat_ == null)
703  break;
704  if (_getAlarm(currentSvStat_[rowIndex]) != 0){
705  return boldFont_;
706  }
707  break;
708  case 8:
709  if (currentSvStat_ == null)
710  break;
711  if (_getDriverTemperature(currentSvStat_[rowIndex]) > 60){
712  return boldFont_;
713  }
714  break;
715  default:
716  break;
717  }
718  return plainFont_;
719  }
720 
721  private boolean _isServoOn(int state) {
722  if ((state & SERVO_STATE_MASK) != 0){
723  return true;
724  }else{
725  return false;
726  }
727  }
728  private boolean _isPowerOn(int state) {
729  if ((state & POWER_STATE_MASK) != 0){
730  return true;
731  }else{
732  return false;
733  }
734  }
735  private boolean _isCalibrated(int state) {
736  if ((state & CALIB_STATE_MASK) != 0){
737  return true;
738  }else{
739  return false;
740  }
741  }
742  private int _getAlarm(int state){
743  return (state&SERVO_ALARM_MASK)>>SERVO_ALARM_SHIFT;
744  }
745  private int _getDriverTemperature(int state){
746  return (state&DRIVER_TEMP_MASK)>>DRIVER_TEMP_SHIFT;
747  }
748 
749 
750  }
751 
752  class SensorTableLabelProvider implements ITableLabelProvider,ITableColorProvider,ITableFontProvider{
753 
754  public Image getColumnImage(Object element, int columnIndex) {
755  return null;
756  }
757 
758  public String getColumnText(Object element, int columnIndex) {
759  int rowIndex = ((Integer)element).intValue();
760  int numForce = 0;
761  if(forceName_!=null)
762  numForce = forceName_.length;
763  int numAccel = 0;
764  if(accName_!=null)
765  numAccel = accName_.length;
766  int numGyro = 0;
767  if(gyroName_!=null)
768  numGyro = gyroName_.length;
769  boolean showzmp = numForce >= 2 && forceName_[0].equals("rfsensor") && forceName_[1].equals("lfsensor");
770  if (columnIndex == 0) {
771  if (rowIndex < numForce)
772  return forceName_[rowIndex] + " [N],[Nm]";
773  if (rowIndex < numForce+numAccel)
774  return accName_[rowIndex-numForce] + " [m/s^2]";
775  if (rowIndex < numForce+numAccel+numGyro)
776  return gyroName_[rowIndex-numForce-numAccel] + " [rad/s]";
777  if (rowIndex == numForce+numAccel+numGyro && showzmp)
778  return "ZMP(right)[m]";
779  return "Voltage [V]";
780  }
781 
782  if (currentSensor_ == null) return "---";
783  if (rowIndex < numForce){
784  if (currentSensor_.force == null || columnIndex >= 7){
785  return "---";
786  }else{
787  return FORMAT2.format(currentSensor_.force[rowIndex][columnIndex - 1]);
788  }
789  }else if (rowIndex < numForce+numAccel){
790  if (currentSensor_.accel == null || columnIndex >= 4){
791  return "---";
792  }else{
793  return FORMAT2.format(currentSensor_.accel[rowIndex - numForce][columnIndex - 1]);
794  }
795  }else if (rowIndex < numForce+numAccel+numGyro){
796  if (currentSensor_.rateGyro == null || columnIndex >= 4){
797  return "---";
798  }else{
799  return FORMAT2.format(currentSensor_.rateGyro[rowIndex - numForce - numAccel][columnIndex - 1]);
800  }
801  }else if (rowIndex == numForce+numAccel+numGyro && showzmp){
802  if (columnIndex == 1){
803  if (currentSensor_.force[0][2]>25){
804  return FORMAT2.format(-currentSensor_.force[0][4]/currentSensor_.force[0][2]);
805  }else{
806  return FORMAT2.format(0);
807  }
808  }else if (columnIndex == 2){
809  if (currentSensor_.force[0][2]>25){
810  return FORMAT2.format(currentSensor_.force[0][3]/currentSensor_.force[0][2]);
811  }else{
812  return FORMAT2.format(0);
813  }
814  }else if(columnIndex == 3){
815  return "ZMP(left)[m]";
816  }else if (columnIndex == 4){
817  if (currentSensor_.force[1][2]>25){
818  return FORMAT2.format(-currentSensor_.force[1][4]/currentSensor_.force[1][2]);
819  }else{
820  return FORMAT2.format(0);
821  }
822  }else if (columnIndex == 5){
823  if (currentSensor_.force[1][2]>25){
824  return FORMAT2.format(currentSensor_.force[1][3]/currentSensor_.force[1][2]);
825  }else{
826  return FORMAT2.format(0);
827  }
828  }else{
829  return "---";
830  }
831  }else{
832  if(currentPower_ == null || columnIndex >= 4)
833  return "---";
834  if(columnIndex == 2){
835  return "Current[A]";
836  }else{
837  return FORMAT1.format(currentPower_[columnIndex/2]);
838  }
839  }
840  }
841 
842  public void addListener(ILabelProviderListener listener) {
843  }
844 
845  public void dispose() {
846  }
847 
848  public boolean isLabelProperty(Object element, String property) {
849  return false;
850  }
851 
852  public void removeListener(ILabelProviderListener listener) {
853  }
854 
855  public Color getBackground(Object element, int columnIndex) {
856  int rowIndex = ((Integer)element).intValue();;
857  GrxBaseItem bitem = manager_.focusedItem();
858  int numForce = 0;
859  if(forceName_!=null)
860  numForce = forceName_.length;
861  int numAccel = 0;
862  if(accName_!=null)
863  numAccel = accName_.length;
864  int numGyro = 0;
865  if(gyroName_!=null)
866  numGyro = gyroName_.length;
867  if (rowIndex < numForce){
868  if (bitem instanceof GrxSensorItem) {
869  if (forceName_[rowIndex].equals(((GrxSensorItem)bitem).getName())) {
870  return yellow_;
871  }
872  }
873  }else if (rowIndex < numForce + numAccel){
874  if (bitem instanceof GrxSensorItem) {
875  if (accName_[rowIndex-numForce].equals(((GrxSensorItem)bitem).getName())) {
876  return yellow_;
877  }
878  }
879  }else if (rowIndex < numForce + numAccel + numGyro){
880  if (bitem instanceof GrxSensorItem) {
881  if (gyroName_[rowIndex-numForce-numAccel].equals(((GrxSensorItem)bitem).getName())) {
882  return yellow_;
883  }
884  }
885  }
886  return white_;
887  }
888 
889  public Color getForeground(Object element, int columnIndex) {
890  return black_;
891  }
892 
893  public Font getFont(Object element, int columnIndex) {
894  return plainFont_;
895  }
896 
897  }
898 
899  public void shutdown() {
900  manager_.removeItemChangeListener(this, GrxModelItem.class);
901  manager_.removeItemChangeListener(this, GrxWorldStateItem.class);
902  if(currentWorld_ != null){
903  currentWorld_.deleteObserver(this);
904  currentWorld_.deletePosObserver(this);
905  }
906  modelList_ = manager_.<GrxModelItem>getSelectedItemList(GrxModelItem.class);
907  if(!modelList_.isEmpty()){
908  Iterator<GrxModelItem> it = modelList_.iterator();
909  while(it.hasNext())
910  it.next().deleteObserver(this);
911 
912  }
913  }
914 
915  public void updateTableFont(){
916  plainFont_ = Activator.getDefault().getFont("robot_state_plain");
917  boldFont_ = Activator.getDefault().getFont("robot_state_bold");
918 
919  for(int i=0;i<viewers_.length;i++){
920  viewers_[i].getTable().setFont(Activator.getDefault().getFont("preference_table"));
921  viewers_[i].refresh();
922  }
923 
924  }
925 }
state
#define null
our own NULL pointer
Definition: IceTypes.h:57
png_infop png_charpp name
Definition: png.h:2382
png_voidp int value
Definition: png.h:2113
void update(GrxBasePlugin plugin, Object...arg)
item corresponds to a robot model
w
png_bytep png_bytep png_size_t length
Definition: png.h:1541
png_uint_32 i
Definition: png.h:2735
void updatePosition(GrxBasePlugin plugin, Integer arg_pos)
png_infop png_uint_32 * width
Definition: png.h:2309
void registerItemChange(GrxBaseItem item, int event)
boolean propertyChanged(String key, String value)
def j(str, encoding="cp932")
list index
def run(tree, args)
GrxRobotStatView(String name, GrxPluginManager manager, GrxBaseViewPart vp, Composite parent)
backing_store_ptr info
Definition: jmemsys.h:181
プラグイン管理クラス GrxUIの核になるクラス。プラグインのロード等の、初期化を実行する。 プラグインとそ...
org
char * arg
Definition: cdjpeg.h:136


openhrp3
Author(s): AIST, General Robotix Inc., Nakamura Lab of Dept. of Mechano Informatics at University of Tokyo
autogenerated on Sat May 8 2021 02:42:38