AnimatLab  2
Test
RbClassFactory.cpp
1 // RbClassFactory.cpp: implementation of the RbClassFactory class.
2 //
4 
5 #include "StdAfx.h"
6 #include "RbClassFactory.h"
7 
8 #include "RbConstraintRelaxation.h"
9 #include "RbConstraintFriction.h"
10 #include "RbMovableItem.h"
11 #include "RbBody.h"
12 #include "RbJoint.h"
13 #include "RbMotorizedJoint.h"
14 #include "RbRigidBody.h"
15 #include "RbBox.h"
16 #include "RbCylinder.h"
17 #include "RbCone.h"
18 #include "RbSphere.h"
19 #include "RbTorus.h"
20 #include "RbEllipsoid.h"
21 #include "RbMesh.h"
22 
23 #include "RbHinge.h"
24 #include "RbPrismatic.h"
25 #include "RbBallSocket.h"
26 #include "RbRPRO.h"
27 #include "RbUniversal.h"
28 #include "RbFreeJoint.h"
29 
30 #include "RbAttachment.h"
31 #include "RbMouth.h"
32 #include "RbOdorSensor.h"
33 
34 #include "RbLine.h"
35 #include "RbLinearHillMuscle.h"
36 #include "RbLinearHillStretchReceptor.h"
37 #include "RbSpring.h"
38 
39 #include "RbOrganism.h"
40 #include "RbStructure.h"
41 
42 #include "RbSimulator.h"
43 #include "RbMaterialType.h"
44 
45 #include "RbLANWirelessInterface.h"
46 #include "RbDynamixelUSB.h"
47 #include "RbDynamixelUSBServo.h"
48 
49 #include "RbFirmataController.h"
50 #include "RbFirmataPart.h"
51 #include "RbFirmataAnalogInput.h"
52 #include "RbFirmataAnalogOutput.h"
53 #include "RbFirmataDigitalInput.h"
54 #include "RbFirmataDigitalOutput.h"
55 #include "RbFirmataHingeServo.h"
56 #include "RbFirmataPrismaticServo.h"
57 #include "RbFirmataPWMOutput.h"
58 
59 #include "RbFirmataDynamixelServo.h"
60 #include "RbXBeeCommander.h"
61 #include "RbAnimatSerial.h"
62 
63 #ifdef _WINDOWS
64  extern "C" __declspec(dllexport) IStdClassFactory* __cdecl GetStdClassFactory()
65 #else
66  extern "C" IStdClassFactory* GetStdClassFactory()
67 #endif
68 {
69  IStdClassFactory *lpFactory = new RbClassFactory;
70  return lpFactory;
71 }
72 
73 #ifdef _WINDOWS
74  extern "C" __declspec(dllexport) int __cdecl BootstrapRunLibrary(int argc, const char **argv)
75 #else
76  extern "C" int BootstrapRunLibrary(int argc, const char **argv)
77 #endif
78 {
79  Simulator *lpSim = NULL;
80 
81 try
82 {
83  Simulator *lpSim = Simulator::CreateSimulator(argc, argv);
84 
85  lpSim->Load();
86  lpSim->Initialize(argc, argv);
87  lpSim->VisualSelectionMode(SIMULATION_SELECTION_MODE);
88 
89  lpSim->StartSimulation();
90  lpSim->Simulate();
91 
92  if(lpSim) delete lpSim;
93 
94  return 0;
95 }
96 catch(CStdErrorInfo oError)
97 {
98  if(lpSim) delete lpSim;
99  printf("Error occurred: %s\n", oError.m_strError.c_str()) ;
100  return (int) oError.m_lError;
101 }
102 catch(...)
103 {
104  if(lpSim) delete lpSim;
105  printf("An Unknown Error occurred.\n") ;
106  return -1;
107 }
108 }
109 
110 
111 
112 namespace RoboticsAnimatSim
113 {
114 
116 // Construction/Destruction
118 
119 RbClassFactory::RbClassFactory()
120 {
121 
122 }
123 
124 RbClassFactory::~RbClassFactory()
125 {
126 
127 }
128 
129 // ************* Body Type Conversion functions ******************************
130 
131 RigidBody *RbClassFactory::CreateRigidBody(std::string strType, bool bThrowError)
132 {
133  RigidBody *lpPart=NULL;
134 
135 try
136 {
137  strType = Std_ToUpper(Std_Trim(strType));
138 
139  if(strType == "BOX")
140  lpPart = new RbBox;
141  else if(strType == "BOXCONTACTSENSOR")
142  {
143  lpPart = new RbBox;
144  lpPart->IsContactSensor(true);
145  }
146  else if(strType == "CYLINDER")
147  lpPart = new RbCylinder;
148  else if(strType == "CYLINDERCONTACTSENSOR")
149  {
150  lpPart = new RbCylinder;
151  lpPart->IsContactSensor(true);
152  }
153  else if(strType == "CONE")
154  lpPart = new RbCone;
155  else if(strType == "SPHERE")
156  lpPart = new RbSphere;
157  else if(strType == "ATTACHMENT")
158  lpPart = new RbAttachment;
159  else if(strType == "LINEARHILLMUSCLE")
160  lpPart = new RbLinearHillMuscle;
161  else if(strType == "LINEARHILLSTRETCHRECEPTOR")
162  lpPart = new RbLinearHillStretchReceptor;
163  else if(strType == "SPRING")
164  lpPart = new RbSpring;
165  else if(strType == "TORUS")
166  lpPart = new RbTorus;
167  else if(strType == "ELLIPSOID")
168  lpPart = new RbEllipsoid;
169  else if(strType == "MOUTH")
170  lpPart = new RbMouth;
171  else if(strType == "ODORSENSOR")
172  lpPart = new RbOdorSensor;
173  else if(strType == "MESH")
174  lpPart = new RbMesh;
175  else if(strType == "STOMACH")
176  lpPart = new Stomach;
177  else
178  {
179  lpPart = NULL;
180  if(bThrowError)
181  THROW_PARAM_ERROR(Al_Err_lInvalidPartType, Al_Err_strInvalidPartType, "PartType", strType);
182  }
183 
184  return lpPart;
185 }
186 catch(CStdErrorInfo oError)
187 {
188  if(lpPart) delete lpPart;
189  RELAY_ERROR(oError);
190  return NULL;
191 }
192 catch(...)
193 {
194  if(lpPart) delete lpPart;
195  THROW_ERROR(Std_Err_lUnspecifiedError, Std_Err_strUnspecifiedError);
196  return NULL;
197 }
198 }
199 
200 // ************* Body Type Conversion functions ******************************
201 
202 
203 // ************* Body Joint Conversion functions ******************************
204 
205 Joint *RbClassFactory::CreateJoint(std::string strType, bool bThrowError)
206 {
207  Joint *lpJoint=NULL;
208 
209 try
210 {
211  strType = Std_ToUpper(Std_Trim(strType));
212 
213  if(strType == "HINGE")
214  lpJoint = new RbHinge;
215  else if(strType == "PRISMATIC")
216  lpJoint = new RbPrismatic;
217  else if(strType == "BALLSOCKET")
218  lpJoint = new RbBallSocket;
219  else if(strType == "RPRO")
220  lpJoint = new RbRPRO;
221  else if(strType == "STATIC")
222  lpJoint = NULL;
223  else if(strType == "UNIVERSAL")
224  lpJoint = new RbUniversal;
225  else if(strType == "FREEJOINT")
226  lpJoint = new RbFreeJoint;
227  else
228  {
229  lpJoint = NULL;
230  if(bThrowError)
231  THROW_PARAM_ERROR(Al_Err_lInvalidJointType, Al_Err_strInvalidJointType, "JointType", strType);
232  }
233 
234  return lpJoint;
235 }
236 catch(CStdErrorInfo oError)
237 {
238  if(lpJoint) delete lpJoint;
239  RELAY_ERROR(oError);
240  return NULL;
241 }
242 catch(...)
243 {
244  if(lpJoint) delete lpJoint;
245  THROW_ERROR(Std_Err_lUnspecifiedError, Std_Err_strUnspecifiedError);
246  return NULL;
247 }
248 }
249 
250 // ************* Body Joint Conversion functions ******************************
251 
252 // ************* Organism Type Conversion functions ******************************
253 
254 Structure *RbClassFactory::CreateStructure(std::string strType, bool bThrowError)
255 {
256  Structure *lpStructure=NULL;
257 
258 try
259 {
260  strType = Std_ToUpper(Std_Trim(strType));
261 
262  if(strType == "BASIC")
263  lpStructure = new RbOrganism;
264  else if(strType == "ORGANISM")
265  lpStructure = new RbOrganism;
266  else if(strType == "STRUCTURE")
267  lpStructure = new RbStructure;
268  else
269  {
270  lpStructure = NULL;
271  if(bThrowError)
272  THROW_PARAM_ERROR(Al_Err_lInvalidOrganismType, Al_Err_strInvalidOrganismType, "OrganismType", strType);
273  }
274 
275  return lpStructure;
276 }
277 catch(CStdErrorInfo oError)
278 {
279  if(lpStructure) delete lpStructure;
280  RELAY_ERROR(oError);
281  return NULL;
282 }
283 catch(...)
284 {
285  if(lpStructure) delete lpStructure;
286  THROW_ERROR(Std_Err_lUnspecifiedError, Std_Err_strUnspecifiedError);
287  return NULL;
288 }
289 }
290 
291 // ************* Organism Type Conversion functions ******************************
292 
293 
294 // ************* Simulator Type Conversion functions ******************************
295 
296 Simulator *RbClassFactory::CreateSimulator(std::string strType, bool bThrowError)
297 {
298  Simulator *lpSimulator=NULL;
299 
300 try
301 {
302  strType = Std_ToUpper(Std_Trim(strType));
303 
304  if(strType == "ROBOTICSSIMULATOR")
305  lpSimulator = new RbSimulator;
306  else if(strType == "")
307  lpSimulator = new RbSimulator;
308  else
309  {
310  lpSimulator = NULL;
311  if(bThrowError)
312  THROW_PARAM_ERROR(Al_Err_lInvalidSimulatorType, Al_Err_strInvalidSimulatorType, "SimulatorType", strType);
313  }
314 
315  return lpSimulator;
316 }
317 catch(CStdErrorInfo oError)
318 {
319  if(lpSimulator) delete lpSimulator;
320  RELAY_ERROR(oError);
321  return NULL;
322 }
323 catch(...)
324 {
325  if(lpSimulator) delete lpSimulator;
326  THROW_ERROR(Std_Err_lUnspecifiedError, Std_Err_strUnspecifiedError);
327  return NULL;
328 }
329 }
330 
331 // ************* Organism Type Conversion functions ******************************
332 
333 
334 
335 // ************* KeyFrame Type Conversion functions ******************************
336 KeyFrame *RbClassFactory::CreateKeyFrame(std::string strType, bool bThrowError)
337 {
338  KeyFrame *lpFrame=NULL;
339 
340 try
341 {
342 // strType = Std_ToUpper(Std_Trim(strType));
343 //
344 // if(strType == "VIDEO")
345 // lpFrame = new VsVideoKeyFrame;
346 // else if(strType == "SNAPSHOT")
347 // lpFrame = new VsSnapshotKeyFrame;
348 // else
349 // {
350 // lpFrame = NULL;
351 // if(bThrowError)
352 // THROW_PARAM_ERROR(Al_Err_lInvalidKeyFrameType, Al_Err_strInvalidKeyFrameType, "KeyFrameType", strType);
353 // }
354 
355  return lpFrame;
356 }
357 catch(CStdErrorInfo oError)
358 {
359  if(lpFrame) delete lpFrame;
360  RELAY_ERROR(oError);
361  return NULL;
362 }
363 catch(...)
364 {
365  if(lpFrame) delete lpFrame;
366  THROW_ERROR(Std_Err_lUnspecifiedError, Std_Err_strUnspecifiedError);
367  return NULL;
368 }
369 }
370 
371 // ************* KeyFrame Type Conversion functions ******************************
372 
373 
374 // ************* DataChart Type Conversion functions ******************************
375 
376 DataChart *RbClassFactory::CreateDataChart(std::string strType, bool bThrowError)
377 {
378  DataChart *lpChart=NULL;
379 
380 try
381 {
382  strType = Std_ToUpper(Std_Trim(strType));
383 
384  if(strType == "TABFILE")
385  lpChart = new FileChart;
386  else if(strType == "FILECHART")
387  lpChart = new FileChart;
388  else if(strType == "MEMORYCHART")
389  lpChart = new MemoryChart;
390  else if(strType == "ARRAYCHART")
391  lpChart = new ArrayChart;
392  else
393  {
394  lpChart = NULL;
395  if(bThrowError)
396  THROW_PARAM_ERROR(Al_Err_lInvalidDataChartType, Al_Err_strInvalidDataChartType, "DataChartType", strType);
397  }
398 
399  return lpChart;
400 }
401 catch(CStdErrorInfo oError)
402 {
403  if(lpChart) delete lpChart;
404  RELAY_ERROR(oError);
405  return NULL;
406 }
407 catch(...)
408 {
409  if(lpChart) delete lpChart;
410  THROW_ERROR(Std_Err_lUnspecifiedError, Std_Err_strUnspecifiedError);
411  return NULL;
412 }
413 }
414 // ************* DataChart Type Conversion functions ******************************
415 
416 
417 // ************* DataColumn Type Conversion functions ******************************
418 
419 DataColumn *RbClassFactory::CreateDataColumn(std::string strType, bool bThrowError)
420 {
421  DataColumn *lpColumn=NULL;
422 
423 try
424 {
425  strType = Std_ToUpper(Std_Trim(strType));
426 
427  if(strType == "DATACOLUMN")
428  lpColumn = new DataColumn;
429  else
430  {
431  lpColumn = NULL;
432  if(bThrowError)
433  THROW_PARAM_ERROR(Al_Err_lInvalidDataColumnType, Al_Err_strInvalidDataColumnType, "DataColumnType", strType);
434  }
435 
436  return lpColumn;
437 }
438 catch(CStdErrorInfo oError)
439 {
440  if(lpColumn) delete lpColumn;
441  RELAY_ERROR(oError);
442  return NULL;
443 }
444 catch(...)
445 {
446  if(lpColumn) delete lpColumn;
447  THROW_ERROR(Std_Err_lUnspecifiedError, Std_Err_strUnspecifiedError);
448  return NULL;
449 }
450 }
451 
452 // ************* DataColumn Type Conversion functions ******************************
453 
454 
455 // ************* Adapter Type Conversion functions ******************************
456 
457 Adapter *RbClassFactory::CreateAdapter(std::string strType, bool bThrowError)
458 {
459  Adapter *lpAdapter=NULL;
460 
461 try
462 {
463  strType = Std_ToUpper(Std_Trim(strType));
464 
465  if(strType == "NODETONODE")
466  lpAdapter = new Adapter;
467  else if(strType == "NODETOPHYSICAL")
468  lpAdapter = new Adapter;
469  else if(strType == "PHYSICALTONODE")
470  lpAdapter = new Adapter;
471  else if(strType == "CONTACT")
472  lpAdapter = new ContactAdapter;
473  else if(strType == "PROPERTYCONTROLADAPTER")
474  lpAdapter = new PropertyControlAdapter;
475  else
476  {
477  lpAdapter = NULL;
478  if(bThrowError)
479  THROW_PARAM_ERROR(Al_Err_lInvalidAdapterType, Al_Err_strInvalidAdapterType, "AdapterType", strType);
480  }
481 
482  return lpAdapter;
483 }
484 catch(CStdErrorInfo oError)
485 {
486  if(lpAdapter) delete lpAdapter;
487  RELAY_ERROR(oError);
488  return NULL;
489 }
490 catch(...)
491 {
492  if(lpAdapter) delete lpAdapter;
493  THROW_ERROR(Std_Err_lUnspecifiedError, Std_Err_strUnspecifiedError);
494  return NULL;
495 }
496 }
497 
498 // ************* Adpater Type Conversion functions ******************************
499 
500 
501 // ************* Gain Type Conversion functions ******************************
502 
503 Gain *RbClassFactory::CreateGain(std::string strType, bool bThrowError)
504 {
505  Gain *lpGain=NULL;
506 
507 try
508 {
509  strType = Std_ToUpper(Std_Trim(strType));
510 
511  if(strType == "BELL")
512  lpGain = new BellGain;
513  else if(strType == "EQUATION")
514  lpGain = new EquationGain;
515  else if(strType == "POLYNOMIAL")
516  lpGain = new PolynomialGain;
517  else if(strType == "SIGMOID")
518  lpGain = new SigmoidGain;
519  else
520  {
521  lpGain = NULL;
522  if(bThrowError)
523  THROW_PARAM_ERROR(Al_Err_lInvalidGainType, Al_Err_strInvalidGainType, "GainType", strType);
524  }
525 
526  return lpGain;
527 }
528 catch(CStdErrorInfo oError)
529 {
530  if(lpGain) delete lpGain;
531  RELAY_ERROR(oError);
532  return NULL;
533 }
534 catch(...)
535 {
536  if(lpGain) delete lpGain;
537  THROW_ERROR(Std_Err_lUnspecifiedError, Std_Err_strUnspecifiedError);
538  return NULL;
539 }
540 }
541 
542 // ************* Adpater Type Conversion functions ******************************
543 
544 
545 // ************* External Stimulus Type Conversion functions ******************************
546 
547 ExternalStimulus *RbClassFactory::CreateExternalStimulus(std::string strType, bool bThrowError)
548 {
549  ExternalStimulus *lpStimulus=NULL;
550 
551 try
552 {
553  strType = Std_ToUpper(Std_Trim(strType));
554 
555  if(strType == "MOTORVELOCITY" || strType == "MOTORPOSITION")
557  else if(strType == "FORCEINPUT")
559  else if(strType == "NODEINPUT")
560  lpStimulus = new ExternalInputStimulus;
561  else if(strType == "RIGIDBODYINPUT")
562  lpStimulus = new ExternalInputStimulus;
563  else if(strType == "JOINTINPUT")
564  lpStimulus = new ExternalInputStimulus;
565  else if(strType == "ENABLERINPUT")
566  lpStimulus = new EnablerStimulus;
567  else if(strType == "INVERSEMUSCLECURRENT")
568  lpStimulus = new InverseMuscleCurrent;
569  else if(strType == "CURRENT")
571  else if(strType == "VOLTAGECLAMP")
573  else if(strType == "PROPERTYCONTROLSTIMULUS")
575  else
576  {
577  lpStimulus = NULL;
578  if(bThrowError)
579  THROW_PARAM_ERROR(Al_Err_lInvalidExternalStimulusType, Al_Err_strInvalidExternalStimulusType, "ExternalStimulusType", strType);
580  }
581 
582  return lpStimulus;
583 }
584 catch(CStdErrorInfo oError)
585 {
586  if(lpStimulus) delete lpStimulus;
587  RELAY_ERROR(oError);
588  return NULL;
589 }
590 catch(...)
591 {
592  if(lpStimulus) delete lpStimulus;
593  THROW_ERROR(Std_Err_lUnspecifiedError, Std_Err_strUnspecifiedError);
594  return NULL;
595 }
596 }
597 
598 // ************* External Stimulus Type Conversion functions ******************************
599 
600 
601 // ************* Hud Item Type Conversion functions ******************************
602 
603 HudItem *RbClassFactory::CreateHudItem(std::string strType, bool bThrowError)
604 {
605  HudItem *lpItem=NULL;
606 
607 try
608 {
609  strType = Std_ToUpper(Std_Trim(strType));
610 
611  lpItem = NULL;
612  if(bThrowError)
613  THROW_PARAM_ERROR(Rb_Err_lInvalidHudItemType, Rb_Err_strInvalidHudItemType, "HudItem", strType);
614 
615  return lpItem;
616 }
617 catch(CStdErrorInfo oError)
618 {
619  if(lpItem) delete lpItem;
620  RELAY_ERROR(oError);
621  return NULL;
622 }
623 catch(...)
624 {
625  if(lpItem) delete lpItem;
626  THROW_ERROR(Std_Err_lUnspecifiedError, Std_Err_strUnspecifiedError);
627  return NULL;
628 }
629 }
630 
631 // ************* Hud Item Type Conversion functions ******************************
632 
633 // ************* Hud Type Conversion functions ******************************
634 
635 Hud *RbClassFactory::CreateHud(std::string strType, bool bThrowError)
636 {
637  Hud *lpHud=NULL;
638 
639 try
640 {
641  strType = Std_ToUpper(Std_Trim(strType));
642 
643  lpHud = NULL;
644  if(bThrowError)
645  THROW_PARAM_ERROR(Rb_Err_lInvalidHudItemType, Rb_Err_strInvalidHudItemType, "Hud", strType);
646 
647  return lpHud;
648 }
649 catch(CStdErrorInfo oError)
650 {
651  if(lpHud) delete lpHud;
652  RELAY_ERROR(oError);
653  return NULL;
654 }
655 catch(...)
656 {
657  if(lpHud) delete lpHud;
658  THROW_ERROR(Std_Err_lUnspecifiedError, Std_Err_strUnspecifiedError);
659  return NULL;
660 }
661 }
662 
663 // ************* Hud Item Type Conversion functions ******************************
664 //
665 // ************* Material Type Conversion functions ******************************
666 
667 MaterialType *RbClassFactory::CreateMaterialItem(std::string strType, bool bThrowError)
668 {
669  MaterialType *lpItem=NULL;
670 
671 try
672 {
673  strType = Std_ToUpper(Std_Trim(strType));
674 
675  if(strType == "BASIC" || strType == "DEFAULT" || strType == "BULLET")
676  lpItem = new RbMaterialType;
677  else
678  {
679  lpItem = NULL;
680  if(bThrowError)
681  THROW_PARAM_ERROR(Rb_Err_lInvalidMaterialItemType, Rb_Err_strInvalidMaterialItemType, "Material Pair", strType);
682  }
683 
684  return lpItem;
685 }
686 catch(CStdErrorInfo oError)
687 {
688  if(lpItem) delete lpItem;
689  RELAY_ERROR(oError);
690  return NULL;
691 }
692 catch(...)
693 {
694  if(lpItem) delete lpItem;
695  THROW_ERROR(Std_Err_lUnspecifiedError, Std_Err_strUnspecifiedError);
696  return NULL;
697 }
698 }
699 
700 // ************* Material Type Conversion functions ******************************
701 
702 // ************* Material Type Conversion functions ******************************
703 
704 SimulationWindow *RbClassFactory::CreateWindowItem(std::string strType, bool bThrowError)
705 {
706  SimulationWindow *lpItem=NULL;
707 
708 try
709 {
710  strType = Std_ToUpper(Std_Trim(strType));
711 
712  lpItem = NULL;
713  if(bThrowError)
714  THROW_PARAM_ERROR(Rb_Err_lInvalidSimWindowType, Rb_Err_strInvalidSimWindowType, "Simulation Window", strType);
715 
716  return lpItem;
717 }
718 catch(CStdErrorInfo oError)
719 {
720  if(lpItem) delete lpItem;
721  RELAY_ERROR(oError);
722  return NULL;
723 }
724 catch(...)
725 {
726  if(lpItem) delete lpItem;
727  THROW_ERROR(Std_Err_lUnspecifiedError, Std_Err_strUnspecifiedError);
728  return NULL;
729 }
730 }
731 
732 // ************* Material Type Conversion functions ******************************
733 
734 // ************* Light Conversion functions ******************************
735 
736 Light *RbClassFactory::CreateLight(std::string strType, bool bThrowError)
737 {
738  Light *lpItem=NULL;
739 
740 try
741 {
742  strType = Std_ToUpper(Std_Trim(strType));
743 
744  lpItem = NULL;
745  if(bThrowError)
746  THROW_PARAM_ERROR(Rb_Err_lInvalidLightType, Rb_Err_strInvalidLightType, "Light Type", strType);
747 
748  return lpItem;
749 }
750 catch(CStdErrorInfo oError)
751 {
752  if(lpItem) delete lpItem;
753  RELAY_ERROR(oError);
754  return NULL;
755 }
756 catch(...)
757 {
758  if(lpItem) delete lpItem;
759  THROW_ERROR(Std_Err_lUnspecifiedError, Std_Err_strUnspecifiedError);
760  return NULL;
761 }
762 }
763 
764 // ************* Light Conversion functions ******************************
765 
766 // ************* External Neural Module Conversion functions ******************************
767 
768 NeuralModule *RbClassFactory::CreateNeuralModule(std::string strType, bool bThrowError)
769 {
770  NeuralModule *lpModule=NULL;
771 
772 try
773 {
774  strType = Std_ToUpper(Std_Trim(strType));
775 
776  if(strType == "PHYSICSNEURALMODULE")
777  {
779  lpModule->ClassFactory(new RbClassFactory());
780  }
781  else
782  {
783  lpModule = NULL;
784  if(bThrowError)
785  THROW_PARAM_ERROR(Al_Err_lInvalidNeuralModuleType, Al_Err_strInvalidNeuralModuleType, "NeuralModule", strType);
786  }
787 
788  return lpModule;
789 }
790 catch(CStdErrorInfo oError)
791 {
792  if(lpModule) delete lpModule;
793  RELAY_ERROR(oError);
794  return NULL;
795 }
796 catch(...)
797 {
798  if(lpModule) delete lpModule;
799  THROW_ERROR(Std_Err_lUnspecifiedError, Std_Err_strUnspecifiedError);
800  return NULL;
801 }
802 }
803 
804 
805 // ************* Neural Module Type Conversion functions ******************************
806 
807 // ************* Constraint Relaxation Conversion functions ******************************
808 
809 ConstraintRelaxation *RbClassFactory::CreateConstraintRelaxation(std::string strType, bool bThrowError)
810 {
811  ConstraintRelaxation *lpRelax=NULL;
812 
813 try
814 {
815  strType = Std_ToUpper(Std_Trim(strType));
816 
817  if(strType == "CONSTRAINTRELAXATION" || strType == "DEFAULT")
818  {
819  lpRelax = new RbConstraintRelaxation;
820  }
821  else
822  {
823  lpRelax = NULL;
824  if(bThrowError)
825  THROW_PARAM_ERROR(Al_Err_lInvalidRelaxationType, Al_Err_strInvalidRelaxationType, "Relaxation", strType);
826  }
827 
828  return lpRelax;
829 }
830 catch(CStdErrorInfo oError)
831 {
832  if(lpRelax) delete lpRelax;
833  RELAY_ERROR(oError);
834  return NULL;
835 }
836 catch(...)
837 {
838  if(lpRelax) delete lpRelax;
839  THROW_ERROR(Std_Err_lUnspecifiedError, Std_Err_strUnspecifiedError);
840  return NULL;
841 }
842 }
843 
844 
845 // ************* Constraint Relaxation Type Conversion functions ******************************
846 
847 // ************* Constraint Friction Conversion functions ******************************
848 
849 ConstraintFriction *RbClassFactory::CreateConstraintFriction(std::string strType, bool bThrowError)
850 {
851  ConstraintFriction *lpFriction=NULL;
852 
853 try
854 {
855  strType = Std_ToUpper(Std_Trim(strType));
856 
857  if(strType == "CONSTRAINTRELAXATION" || strType == "DEFAULT")
858  {
859  lpFriction = new RbConstraintFriction;
860  }
861  else
862  {
863  lpFriction = NULL;
864  if(bThrowError)
865  THROW_PARAM_ERROR(Al_Err_lInvalidFrictionType, Al_Err_strInvalidFrictionType, "Friction", strType);
866  }
867 
868  return lpFriction;
869 }
870 catch(CStdErrorInfo oError)
871 {
872  if(lpFriction) delete lpFriction;
873  RELAY_ERROR(oError);
874  return NULL;
875 }
876 catch(...)
877 {
878  if(lpFriction) delete lpFriction;
879  THROW_ERROR(Std_Err_lUnspecifiedError, Std_Err_strUnspecifiedError);
880  return NULL;
881 }
882 }
883 
884 
885 // ************* Constraint Friction Type Conversion functions ******************************
886 
887 
888 // ************* Robot Interface Conversion functions ******************************
889 
890 RobotInterface *RbClassFactory::CreateRobotInterface(std::string strType, bool bThrowError)
891 {
892  RobotInterface *lpInterface=NULL;
893 
894 try
895 {
896  strType = Std_ToUpper(Std_Trim(strType));
897 
898  if(strType == "STANDARDINTERFACE" || strType == "DEFAULT")
899  {
900  lpInterface = new AnimatSim::Robotics::RobotInterface;
901  }
902  else if(strType == "LANWIRELESSINTERFACE")
903  {
904  lpInterface = new RbLANWirelessInterface;
905  }
906  else
907  {
908  lpInterface = NULL;
909  if(bThrowError)
910  THROW_PARAM_ERROR(Al_Err_lInvalidRobotInterfaceType, Al_Err_strInvalidRobotInterfaceType, "RobotInterface", strType);
911  }
912 
913  return lpInterface;
914 }
915 catch(CStdErrorInfo oError)
916 {
917  if(lpInterface) delete lpInterface;
918  RELAY_ERROR(oError);
919  return NULL;
920 }
921 catch(...)
922 {
923  if(lpInterface) delete lpInterface;
924  THROW_ERROR(Std_Err_lUnspecifiedError, Std_Err_strUnspecifiedError);
925  return NULL;
926 }
927 }
928 
929 // ************* Robot Interface Type Conversion functions ******************************
930 
931 
932 
933 // ************* Robot IO Control Conversion functions ******************************
934 
935 RobotIOControl *RbClassFactory::CreateRobotIOControl(std::string strType, bool bThrowError)
936 {
937  RobotIOControl *lpControl=NULL;
938 
939 try
940 {
941  strType = Std_ToUpper(Std_Trim(strType));
942 
943  if(strType == "DYNAMIXELUSB")
944  {
945  lpControl = new RbDynamixelUSB;
946  }
947  else if(strType == "FIRMATACONTROLLER")
948  {
949  lpControl = new RbFirmataController;
950  }
951  else if(strType == "XBEECOMMANDER")
952  {
953  lpControl = new RbXBeeCommander;
954  }
955  else if(strType == "ANIMATSERIAL")
956  {
957  lpControl = new RbAnimatSerial;
958  }
959  else
960  {
961  lpControl = NULL;
962  if(bThrowError)
963  THROW_PARAM_ERROR(Al_Err_lInvalidRobotIOControlType, Al_Err_strInvalidRobotIOControlType, "RobotartIOControl", strType);
964  }
965 
966  return lpControl;
967 }
968 catch(CStdErrorInfo oError)
969 {
970  if(lpControl) delete lpControl;
971  RELAY_ERROR(oError);
972  return NULL;
973 }
974 catch(...)
975 {
976  if(lpControl) delete lpControl;
977  THROW_ERROR(Std_Err_lUnspecifiedError, Std_Err_strUnspecifiedError);
978  return NULL;
979 }
980 }
981 
982 
983 // ************* Robot IO Control Conversion functions ******************************
984 
985 
986 // ************* Robot Part Interface Conversion functions ******************************
987 
988 RobotPartInterface *RbClassFactory::CreateRobotPartInterface(std::string strType, bool bThrowError)
989 {
990  RobotPartInterface *lpInterface=NULL;
991 
992 try
993 {
994  strType = Std_ToUpper(Std_Trim(strType));
995 
996  if(strType == "DYNAMIXELUSBHINGE")
997  {
998  lpInterface = new RbDynamixelUSBServo;
999  }
1000  else if(strType == "DYNAMIXELUSBPRISMATIC")
1001  {
1002  lpInterface = new RbDynamixelUSBServo;
1003  }
1004  else if(strType == "FIRMATAANALOGINPUT")
1005  {
1006  lpInterface = new RbFirmataAnalogInput;
1007  }
1008  else if(strType == "FIRMATAANALOGOUTPUT")
1009  {
1010  lpInterface = new RbFirmataAnalogInput;
1011  }
1012  else if(strType == "FIRMATADIGITALINPUT")
1013  {
1014  lpInterface = new RbFirmataDigitalInput;
1015  }
1016  else if(strType == "FIRMATADIGITALOUTPUT")
1017  {
1018  lpInterface = new RbFirmataDigitalOutput;
1019  }
1020  else if(strType == "FIRMATAHINGESERVO")
1021  {
1022  lpInterface = new RbFirmataHingeServo;
1023  }
1024  else if(strType == "FIRMATAPRISMATICSERVO")
1025  {
1026  lpInterface = new RbFirmataPrismaticServo;
1027  }
1028  else if(strType == "FIRMATAPWMOUTPUT")
1029  {
1030  lpInterface = new RbFirmataPWMOutput;
1031  }
1032  else if(strType == "FIRMATADYNAMIXELHINGESERVO")
1033  {
1034  lpInterface = new RbFirmataDynamixelServo;
1035  }
1036  else if(strType == "FIRMATADYNAMIXELPRISMATICSERVO")
1037  {
1038  lpInterface = new RbFirmataDynamixelServo;
1039  }
1040  else
1041  {
1042  lpInterface = NULL;
1043  if(bThrowError)
1044  THROW_PARAM_ERROR(Al_Err_lInvalidRobotPartInterfaceType, Al_Err_strInvalidRobotPartInterfaceType, "RobotartInterface", strType);
1045  }
1046 
1047  return lpInterface;
1048 }
1049 catch(CStdErrorInfo oError)
1050 {
1051  if(lpInterface) delete lpInterface;
1052  RELAY_ERROR(oError);
1053  return NULL;
1054 }
1055 catch(...)
1056 {
1057  if(lpInterface) delete lpInterface;
1058  THROW_ERROR(Std_Err_lUnspecifiedError, Std_Err_strUnspecifiedError);
1059  return NULL;
1060 }
1061 }
1062 
1063 
1064 // ************* Robot Part Interface Type Conversion functions ******************************
1065 
1066 // ************* RemoteControlLinkage Conversion functions ******************************
1067 
1068 RemoteControlLinkage *RbClassFactory::CreateRemoteControlLinkage(std::string strType, bool bThrowError)
1069 {
1070  RemoteControlLinkage *lpLink=NULL;
1071 
1072 try
1073 {
1074  strType = Std_ToUpper(Std_Trim(strType));
1075 
1076  if(strType == "PASSTHROUGHLINKAGE")
1077  {
1078  lpLink = new PassThroughLinkage;
1079  }
1080  else if(strType == "PULSEDLINKAGE")
1081  {
1082  lpLink = new PulsedLinkage;
1083  }
1084  else
1085  {
1086  lpLink = NULL;
1087  if(bThrowError)
1088  THROW_PARAM_ERROR(Al_Err_lInvalidFrictionType, Al_Err_strInvalidFrictionType, "Friction", strType);
1089  }
1090 
1091  return lpLink;
1092 }
1093 catch(CStdErrorInfo oError)
1094 {
1095  if(lpLink) delete lpLink;
1096  RELAY_ERROR(oError);
1097  return NULL;
1098 }
1099 catch(...)
1100 {
1101  if(lpLink) delete lpLink;
1102  THROW_ERROR(Std_Err_lUnspecifiedError, Std_Err_strUnspecifiedError);
1103  return NULL;
1104 }
1105 }
1106 
1107 
1108 // ************* RemoteControlLinkage Type Conversion functions ******************************
1109 
1110 
1111 
1112 
1113 // ************* IStdClassFactory functions ******************************
1114 
1115 CStdSerialize *RbClassFactory::CreateObject(std::string strClassType, std::string strObjectType, bool bThrowError)
1116 {
1117  CStdSerialize *lpObject=NULL;
1118 
1119  strClassType = Std_ToUpper(Std_Trim(strClassType));
1120 
1121  if(strClassType == "RIGIDBODY")
1122  lpObject = CreateRigidBody(strObjectType, bThrowError);
1123  else if(strClassType == "JOINT")
1124  lpObject = CreateJoint(strObjectType, bThrowError);
1125  else if(strClassType == "ORGANISM")
1126  lpObject = CreateStructure(strObjectType, bThrowError);
1127  else if(strClassType == "STRUCTURE")
1128  lpObject = CreateStructure(strObjectType, bThrowError);
1129  else if(strClassType == "SIMULATOR")
1130  lpObject = CreateSimulator(strObjectType, bThrowError);
1131  else if(strClassType == "KEYFRAME")
1132  lpObject = CreateKeyFrame(strObjectType, bThrowError);
1133  else if(strClassType == "DATACHART")
1134  lpObject = CreateDataChart(strObjectType, bThrowError);
1135  else if(strClassType == "DATACOLUMN")
1136  lpObject = CreateDataColumn(strObjectType, bThrowError);
1137  else if(strClassType == "EXTERNALSTIMULUS")
1138  lpObject = CreateExternalStimulus(strObjectType, bThrowError);
1139  else if(strClassType == "ADAPTER")
1140  lpObject = CreateAdapter(strObjectType, bThrowError);
1141  else if(strClassType == "GAIN")
1142  lpObject = CreateGain(strObjectType, bThrowError);
1143  else if(strClassType == "HUDITEM")
1144  lpObject = CreateHudItem(strObjectType, bThrowError);
1145  else if(strClassType == "HUD")
1146  lpObject = CreateHud(strObjectType, bThrowError);
1147  else if(strClassType == "MATERIAL")
1148  lpObject = CreateMaterialItem(strObjectType, bThrowError);
1149  else if(strClassType == "SIMULATIONWINDOW")
1150  lpObject = CreateWindowItem(strObjectType, bThrowError);
1151  else if(strClassType == "LIGHT")
1152  lpObject = CreateLight(strObjectType, bThrowError);
1153  else if(strClassType == "NEURALMODULE")
1154  lpObject = CreateNeuralModule(strObjectType, bThrowError);
1155  else if(strClassType == "CONSTRAINTRELAXATION")
1156  lpObject = CreateConstraintRelaxation(strObjectType, bThrowError);
1157  else if(strClassType == "CONSTRAINTFRICTION")
1158  lpObject = CreateConstraintFriction(strObjectType, bThrowError);
1159  else if(strClassType == "ROBOTINTERFACE")
1160  lpObject = CreateRobotInterface(strObjectType, bThrowError);
1161  else if(strClassType == "ROBOTIOCONTROL")
1162  lpObject = CreateRobotIOControl(strObjectType, bThrowError);
1163  else if(strClassType == "ROBOTPARTINTERFACE")
1164  lpObject = CreateRobotPartInterface(strObjectType, bThrowError);
1165  else if(strClassType == "REMOTECONTROLLINKAGE")
1166  lpObject = CreateRemoteControlLinkage(strObjectType, bThrowError);
1167  else
1168  {
1169  lpObject = NULL;
1170  if(bThrowError)
1171  THROW_PARAM_ERROR(Std_Err_lInvalidClassType, Std_Err_strInvalidClassType, "ClassType", strClassType);
1172  }
1173 
1174  return lpObject;
1175 }
1176 // ************* IStdClassFactory functions ******************************
1177 
1178 
1179 void ROBOTICS_PORT RunBootstrap(int argc, const char **argv)
1180 {
1181  BootstrapRunLibrary(argc, argv);
1182 }
1183 
1184 
1185 } //RoboticsAnimatSim
Declares the vs universal class.
virtual IStdClassFactory * ClassFactory()
Gets the class factory.
Declares the vortex Torus class.
Declares the vortex ellipsoid class.
Vortex ball-and-socket joint class.
Definition: RbBallSocket.h:29
Vortex physical structure implementation.
Definition: RbStructure.h:25
Vortex Organism implementation.
Definition: RbOrganism.h:20
Vortex relative position, relative orientation joint class.
Definition: RbRPRO.h:23
Declares the vortex relative position, relative orientation class.
Declares the vortex mouth class.
std::string Std_Trim(std::string strVal)
Trims a string.
Declares the vortex structure class.
Declares the vortex hinge class.
Declares the vortex ball socket class.
Declares the vs prismatic class.
Declares the vortex odor sensor class.
Current stimulus for neural items.
This stimulus enables or disables a joint or body part for a specified period of time.
virtual bool IsContactSensor()
Query if this object is contact sensor.
Definition: RigidBody.cpp:448
Declares the vs universal class.
Classes for implementing the cm-labs vortex physics engine for AnimatLab.
std::string Std_ToUpper(std::string strVal)
Converts a string to upper case.
Declares the vortex organism class.
The Robotics interface configures a simulation to run on a microcontroller board. ...