10 package com.generalrobotix.ui.item;
13 import java.lang.reflect.InvocationTargetException;
14 import java.util.Collection;
15 import java.util.List;
16 import java.util.Vector;
18 import org.eclipse.core.runtime.IProgressMonitor;
19 import org.eclipse.jface.dialogs.MessageDialog;
20 import org.eclipse.jface.dialogs.ProgressMonitorDialog;
21 import org.eclipse.jface.operation.IRunnableWithProgress;
22 import org.eclipse.swt.widgets.Display;
44 @SuppressWarnings(
"serial")
50 public static final String TITLE =
"PPAlgorithm";
51 public static final String FILE_EXTENSION =
"ppa";
54 private PathPlanner planner_ =
null;
56 private boolean connectChange_ =
false;
63 setProperty(
"rebuildRoadmap",
"true");
64 setProperty(
"carpetZ",
"0.01");
65 setProperty(
"tolerance",
"0.0");
69 Runnable
run =
new Runnable(){
72 notifyObservers(
"connected");
73 connectChange_ =
false;
75 Display display = Display.getCurrent();
76 if ( display!=
null && !display.isDisposed()){
77 display.timerExec(100,
this);
81 Display display = Display.getCurrent();
82 if ( display!=
null && !display.isDisposed()){
83 display.timerExec(100, run);
91 @SuppressWarnings(
"unchecked")
93 Collection<GrxPathPlanningAlgorithmItem> col=(Collection<GrxPathPlanningAlgorithmItem>) manager_.getItemMap(
GrxPathPlanningAlgorithmItem.class).values();
94 if(col.size()==1 && col.contains(
this))
101 if (super.propertyChanged(key, value)){
104 setProperty(key, value);
111 return _pathConsumer().getImpl();
115 if (ppcomp_ ==
null){
116 execPathPlannerConsumer();
125 String [] args = {
"-f", getConfigFilePath()};
126 if( args[1].isEmpty() ){
132 final Manager
manager = Manager.init(args);
137 manager.setModuleInitProc(ppcomp_);
140 manager.activateManager();
147 manager.runManager(
true);
149 ppcomp_.setConnectedCallback(
this);
159 if( defualtRtcFile.isFile() ){
160 confPath = defualtRtcFile.getPath();
164 String confPathFromProperty = System.getProperty(
"com.generalrobotix.grxui.rtcpath");
165 if( confPathFromProperty !=
null ) {
166 confPath = confPathFromProperty;
177 planner_ = _pathConsumer().getImpl();
178 if( planner_ ==
null ){
183 StringSequenceHolder propertyNames_ =
new StringSequenceHolder();
184 StringSequenceHolder propertyDefaults_ =
new StringSequenceHolder();
185 planner_.getProperties( getProperty(
"algorithm"), propertyNames_, propertyDefaults_ );
186 String[] props = propertyNames_.value;
187 String[] defaults = propertyDefaults_.value;
190 for(
int i=0;
i<props.length;
i++ )
191 setProperty( props[
i], defaults[i] );
200 planner_ = _pathConsumer().getImpl();
201 if( planner_ ==
null ){
207 planner_.initPlanner();
210 planner_.setAlgorithmName( getProperty(
"algorithm") );
214 List<GrxBaseItem> models = manager_.getSelectedItemList(
GrxModelItem.class );
220 planner_.registerCharacter( m.
getName(), binfo );
228 double t = getDbl(
"tolerance", 0.0);
232 planner_.registerIntersectionCheckPair(
233 item.
getStr(
"objectName1",
""), item.
getStr(
"jointName1",
""),
234 item.
getStr(
"objectName2",
""), item.
getStr(
"jointName2",
""),
239 String modelName = getProperty(
"model");
240 if( modelName ==
null || modelName.equals(
"") ){
244 String mobilityName = getProperty(
"mobility");
245 if( mobilityName ==
null || mobilityName.equals(
"") ){
249 planner_.setMobilityName(mobilityName);
251 planner_.setRobotName(modelName);
255 String[][]p = getAlgoProperty();
259 planner_.setProperties( p );
262 planner_.initSimulation();
270 planner_.setCharacterPosition(m.
getName(), v);
280 Vector<String[]> tmp =
new Vector<String[]>();
281 for( Object s : keySet() ){
282 if( ! getStr( s.toString() ).equals(
"") ){
283 String []tmp2 = { s.toString(), getStr( s.toString() ) };
287 String [][]
params =
new String[tmp.size()+1][2];
288 for(
int i=0;
i<tmp.size();
i++ )
289 params[
i] = tmp.get(
i);
292 Double z = getZPosition();
298 params[ params.length-1 ][0] =
"z-pos";
299 params[ params.length-1 ][1] = String.valueOf( getZPosition() );
308 Double getZPosition(){
309 String modelName = getProperty(
"model");
314 double [] tr = robot.
getDblAry(getRobotBaseLink(robot)+
".translation",
null);
334 double sx = 0,sy = 0,st = 0;
336 sx = getDbl(
"startX", 0.0);
337 sy = getDbl(
"startY", 0.0);
338 st = getDbl(
"startTheta", 0.0)/ 360
f * (2*Math.PI);
339 while (st < 0) st += 2*Math.PI;
340 while (st > 2*Math.PI) st -= 2*Math.PI;
346 planner_.setStartPosition( sx,sy,st );
357 double ex = 0,ey = 0,et = 0;
359 ex = getDbl(
"goalX", 0.0);
360 ey = getDbl(
"goalY", 0.0);
361 et = getDbl(
"goalTheta", 0.0) / 360
f * (2*Math.PI);
362 while (et < 0) et += 2*Math.PI;
363 while (et > 2*Math.PI) et -= 2*Math.PI;
369 planner_.setGoalPosition( ex,ey,et);
374 double sx = 0,sy = 0,st = 0;
377 sx = getDbl(
"startX", 0.0);
378 sy = getDbl(
"startY", 0.0);
379 st = getDbl(
"startTheta", 0.0)/ 360
f * (2*Math.PI);
384 String modelName = getProperty(
"model");
388 robot.
propertyChanged(getRobotBaseLink(robot)+
".translation",
""+sx+
" "+sy+
" "+getZPosition());
389 robot.
propertyChanged(getRobotBaseLink(robot)+
".rotation",
"0.0 0.0 1.0 "+st);
393 double ex = 0,ey = 0,et = 0;
396 ex = getDbl(
"goalX", 0.0);
397 ey = getDbl(
"goalY", 0.0);
398 et = getDbl(
"goalTheta", 0.0) / 360
f * (2*Math.PI);
403 String modelName = getProperty(
"model");
405 robot.
propertyChanged(getRobotBaseLink(robot)+
".translation",
""+ex+
" "+ey+
" "+getZPosition() );
406 robot.
propertyChanged(getRobotBaseLink(robot)+
".rotation",
"0.0 0.0 1.0 "+et);
410 planner_ = _pathConsumer().getImpl();
411 if( planner_ ==
null ){
416 if ( getProperty(
"rebuildRoadmap").equals(
"true")){
417 if (!initPathPlanner()){
429 private boolean calcSucceed=
false;
433 IRunnableWithProgress runnableProgress =
new IRunnableWithProgress() {
434 public void run(IProgressMonitor monitor)
throws InterruptedException {
435 Thread calcThread =
new Thread(
new Runnable(){
437 calcSucceed = planner_.calcPath();
442 monitor.beginTask(
"Planning a path. Please Wait.", IProgressMonitor.UNKNOWN );
443 while( calcThread.isAlive() ){
446 if( monitor.isCanceled() ){
448 planner_.stopPlanning();
457 progressMonitorDlg.run(
true,
true, runnableProgress);
458 }
catch (InvocationTargetException e) {
461 }
catch (InterruptedException e) {
466 if( calcSucceed ==
false ){
477 planner_ = _pathConsumer().getImpl();
478 if( planner_ ==
null ){
483 String optimizer = getProperty(
"optimizer");
484 if( optimizer ==
null || optimizer.equals(
"") ){
489 planner_.optimize(optimizer);
494 PointArrayHolder
path =
new PointArrayHolder();
495 planner_.getPath( path );
499 double dt = 10.0 / path.value.length, nowTime = 0;
501 if( currentWorld_ ==
null ) {
506 currentWorld_.
setDbl(
"logTimeStep", dt);
507 DynamicsSimulator dynSim = getDynamicsSimulator();
508 if( dynSim ==
null ){
514 String model = getProperty(
"model");
515 String base = getRobotBaseLink(model);
516 WorldStateHolder stateH_ =
new WorldStateHolder();
517 for(
double p[] : path.value ) {
519 double newPos[] =
new double[12];
520 newPos[0] = p[0]; newPos[1] = p[1]; newPos[2] = getZPosition();
521 newPos[0 + 3] = Math.cos( p[2] ); newPos[1 + 3] = -Math.sin( p[2] ); newPos[2 + 3] = 0.0;
522 newPos[3 + 3] = Math.sin( p[2] ); newPos[4 + 3] = Math.cos( p[2] ); newPos[5 + 3] = 0.0;
523 newPos[6 + 3] = 0.0; newPos[7 + 3] = 0.0; newPos[8 + 3] = 1.0;
525 dynSim.setCharacterLinkData( model, base, LinkDataType.ABS_TRANSFORM, newPos);
527 dynSim.calcWorldForwardKinematics();
530 dynSim.getWorldState(stateH_);
534 currentWorld_.
addValue(nowTime, wsx);
537 System.out.println(
"worldstate.getLogSize() = "+currentWorld_.
getLogSize());
542 DynamicsSimulator getDynamicsSimulator(){
547 manager_.setSelectedItem(simItem,
true);
558 return new String[0];
559 StringSequenceHolder names =
new StringSequenceHolder();
561 planner_.getAlgorithmNames( names );
567 return new String[0];
568 StringSequenceHolder names =
new StringSequenceHolder();
569 planner_.getMobilityNames( names );
575 return new String[0];
576 StringSequenceHolder names =
new StringSequenceHolder();
577 planner_.getOptimizerNames( names );
583 return new RoadmapNode[0];
584 RoadmapHolder h =
new RoadmapHolder();
585 planner_.getRoadmap(h);
586 return (RoadmapNode[])h.value;
591 return new double[0][0];
592 PointArrayHolder
path =
new PointArrayHolder();
593 planner_.getPath( path );
599 planner_ = _pathConsumer().getImpl();
602 connectChange_ =
true;
static final String get(String key)
boolean initPathPlanner()
void addValue(Double t, Object obj)
String [] getAlgorithms()
final double [] getDblAry(String key, double[] defaultVal)
get double array associated to key
#define null
our own NULL pointer
DynamicsSimulator getDynamicsSimulator(boolean update)
BodyInfo getBodyInfo()
get BodyInfo
png_infop png_charpp name
png_infop png_charp png_int_32 png_int_32 int int png_charp png_charpp * params
item corresponds to a robot model
static final int ADD_ITEM
final void setDbl(String key, double value)
associate double value to key
void setPosition(Integer pos)
static void printErr(String s)
GrxPathPlanningAlgorithmItem(String name, GrxPluginManager manager)
double [] getTransformArray(GrxLinkItem link)
get transform of link in array form
static Shell getCurrentShell()
static Activator getDefault()
boolean _setGoalPosition()
set goal position of planning to planner
GrxLinkItem rootLink()
get root link
boolean initDynamicsSimulator()
boolean propertyChanged(String key, String value)
String getRobotBaseLink(String name)
static void println(String s)
RoadmapNode [] getRoadmap()
String [] getMobilityNames()
final String getStr(String key)
get value associated to keyword
プラグイン管理クラス GrxUIの核になるクラス。プラグインのロード等の、初期化を実行する。 プラグインとそ...
void propertyUpdate()
移動動作設計コンポーネントから現在選択している経路計画アルゴリズムに対するプロパティを取得し、選択し...
String getRobotBaseLink(GrxModelItem model)
final String getName()
get name
String getConfigFilePath()
String [][] getAlgoProperty()
boolean propertyChanged(String property, String value)
check validity of new value of property and update if valid
static void print(String s)
void execPathPlannerConsumer()
経路計画コンポーネントのコンシューマを立ち上げ
PathConsumerComp _pathConsumer()
String [] getOptimizerNames()
boolean _setStartPosition()
set start position of planning to planner
void connectedCallback(boolean b)