1 ////////////////////////////////////////////////// 2 // 3 // ChModuleVehicle.i 4 // 5 // SWIG configuration file. 6 // This is processed by SWIG to create the C::E 7 // wrapper for Python. 8 // 9 /////////////////////////////////////////////////// 10 11 12 13 // Define the module to be used in Python when typing 14 // 'import pychrono.robot' 15 16 17 %module(directors="1") robot 18 19 20 // Turn on the documentation of members, for more intuitive IDE typing 21 22 %feature("autodoc", "1"); 23 %feature("flatnested", "1"); 24 25 // Turn on the exception handling to intercept C++ exceptions 26 %include "exception.i" 27 28 %exception { 29 try { 30 $action catch(const std::exception & e)31 } catch (const std::exception& e) { 32 SWIG_exception(SWIG_RuntimeError, e.what()); 33 } 34 } 35 36 37 // For optional downcasting of polimorphic objects: 38 %include "../chrono_downcast.i" 39 40 // For supporting shared pointers: 41 %include <std_shared_ptr.i> 42 43 44 45 // Include C++ headers this way... 46 47 %{ 48 #include <string> 49 #include <vector> 50 51 #include "chrono/core/ChQuaternion.h" 52 #include "chrono/core/ChVector.h" 53 #include "chrono/solver/ChSolver.h" 54 55 #include "chrono/physics/ChSystem.h" 56 #include "chrono/physics/ChBody.h" 57 #include "chrono/physics/ChBodyAuxRef.h" 58 #include "chrono/physics/ChMarker.h" 59 #include "chrono/physics/ChLink.h" 60 #include "chrono/physics/ChLinkTSDA.h" 61 #include "chrono/physics/ChLinkRotSpringCB.h" 62 #include "chrono/physics/ChPhysicsItem.h" 63 64 #include "Eigen/src/Core/util/Memory.h" 65 66 #include "chrono_models/ChApiModels.h" 67 #include "chrono_models/robot/robosimian/RoboSimian.h" 68 #include "chrono_models/robot/viper/Viper.h" 69 #include "chrono_models/robot/curiosity/Curiosity.h" 70 #include "chrono_models/robot/turtlebot/Turtlebot.h" 71 #include "chrono_models/robot/copters/Copter.h" 72 #include "chrono_models/robot/copters/Little_Hexy.h" 73 74 using namespace chrono; 75 using namespace chrono::robosimian; 76 using namespace chrono::viper; 77 using namespace chrono::curiosity; 78 using namespace chrono::turtlebot; 79 using namespace chrono::copter; 80 81 %} 82 83 84 // Undefine ChApiFea otherwise SWIG gives a syntax error 85 #define ChApi 86 #define EIGEN_MAKE_ALIGNED_OPERATOR_NEW 87 88 #define CH_MODELS_API 89 90 91 92 93 // Include other .i configuration files for SWIG. 94 // These are divided in many .i files, each per a 95 // different c++ class, when possible. 96 97 %include "std_string.i" 98 %include "std_vector.i" 99 %include "std_array.i" 100 %include "typemaps.i" 101 102 // This is to enable references to double,int,etc. types in function parameters 103 %pointer_class(int,int_ptr); 104 %pointer_class(double,double_ptr); 105 %pointer_class(float,float_ptr); 106 107 108 %template(vector_int) std::vector< int >; 109 %template(limb_data) std::array<double, 8>; 110 %template(Actuation) std::array<std::array<double, 8>, 4>; 111 112 // 113 // For each class, keep updated the A, B, C sections: 114 // 115 116 117 // 118 // A- ENABLE SHARED POINTERS 119 // 120 // Note that this must be done for almost all objects (not only those that are 121 // handled by shered pointers in C++, but all their chidren and parent classes. It 122 // is enough that a single class in an inheritance tree uses %shared_ptr, and all other in the 123 // tree must be promoted to %shared_ptr too). 124 125 //from core module: 126 %shared_ptr(chrono::ChFunction) 127 %shared_ptr(chrono::ChFrame<double>) 128 %shared_ptr(chrono::ChFrameMoving<double>) 129 %shared_ptr(chrono::ChPhysicsItem) 130 %shared_ptr(chrono::ChNodeBase) 131 %shared_ptr(chrono::ChNodeXYZ) 132 %shared_ptr(chrono::ChTriangleMeshShape) 133 %shared_ptr(chrono::geometry::ChTriangleMeshConnected) 134 %shared_ptr(chrono::ChLinkSpring) 135 %shared_ptr(chrono::ChFunction_Recorder) 136 %shared_ptr(chrono::ChBezierCurve) 137 %shared_ptr(chrono::ChLinkMarkers) 138 139 %shared_ptr(chrono::robosimian::RS_Part) 140 %shared_ptr(chrono::robosimian::RS_Chassis) 141 %shared_ptr(chrono::robosimian::RS_Sled) 142 %shared_ptr(chrono::robosimian::RS_WheelDD) 143 %shared_ptr(chrono::robosimian::RS_Driver) 144 145 %shared_ptr(chrono::viper::ViperPart) 146 %shared_ptr(chrono::viper::ViperChassis) 147 %shared_ptr(chrono::viper::ViperWheel) 148 %shared_ptr(chrono::viper::ViperUpperArm) 149 %shared_ptr(chrono::viper::ViperLowerArm) 150 %shared_ptr(chrono::viper::ViperUpright) 151 %shared_ptr(chrono::viper::ViperDriver) 152 %shared_ptr(chrono::viper::ViperDCMotorControl) 153 %shared_ptr(chrono::viper::ViperSpeedDriver) 154 155 %shared_ptr(chrono::curiosity::CuriosityPart) 156 %shared_ptr(chrono::curiosity::CuriosityChassis) 157 %shared_ptr(chrono::curiosity::CuriosityWheel) 158 %shared_ptr(chrono::curiosity::CuriosityRocker) 159 %shared_ptr(chrono::curiosity::CuriosityBogie) 160 %shared_ptr(chrono::curiosity::CuriosityUpright) 161 %shared_ptr(chrono::curiosity::CuriosityDifferentialBar) 162 %shared_ptr(chrono::curiosity::CuriosityDifferentialLink) 163 %shared_ptr(chrono::curiosity::CuriosityDriver) 164 %shared_ptr(chrono::curiosity::CuriosityDCMotorControl) 165 %shared_ptr(chrono::curiosity::CuriositySpeedDriver) 166 167 %shared_ptr(chrono::turtlebot::Turtlebot_Part) 168 %shared_ptr(chrono::turtlebot::Turtlebot_Chassis) 169 %shared_ptr(chrono::turtlebot::Turtlebot_ActiveWheel) 170 %shared_ptr(chrono::turtlebot::Turtlebot_PassiveWheel) 171 %shared_ptr(chrono::turtlebot::Turtlebot_Rod_Short) 172 %shared_ptr(chrono::turtlebot::Turtlebot_BottomPlate) 173 %shared_ptr(chrono::turtlebot::Turtlebot_MiddlePlate) 174 %shared_ptr(chrono::turtlebot::Turtlebot_TopPlate) 175 %shared_ptr(chrono::turtlebot::Turtlebot_Rod_Long) 176 177 // 178 // B- INCLUDE HEADERS 179 // 180 // 181 // 1) 182 // When including with %include all the .i files, make sure that 183 // the .i of a derived class is included AFTER the .i of 184 // a base class, otherwise SWIG is not able to build the type 185 // infos. 186 // 187 // 2) 188 // Then, this said, if one member function in Foo_B.i returns 189 // an object of Foo_A.i (or uses it as a parameter) and yet you must %include 190 // A before B, ex.because of rule 1), a 'forward reference' to A must be done in 191 // B by. Seems that it is enough to write 192 // mynamespace { class myclass; } 193 // in the .i file, before the %include of the .h, even if already forwarded in .h 194 195 %import(module = "pychrono.core") "chrono_python/core/ChClassFactory.i" 196 %import(module = "pychrono.core") "chrono_python/core/ChObject.i" 197 %import(module = "pychrono.core") "chrono_python/core/ChPhysicsItem.i" 198 %import(module = "pychrono.core") "chrono_python/core/ChVector.i" 199 %import(module = "pychrono.core") "chrono_python/core/ChQuaternion.i" 200 %import(module = "pychrono.core") "chrono_python/core/ChCoordsys.i" 201 %import(module = "pychrono.core") "chrono_python/core/ChFrame.i" 202 %import(module = "pychrono.core") "chrono_python/core/ChFrameMoving.i" 203 %import(module = "pychrono.core") "chrono_python/core/ChTimestepper.i" 204 %import(module = "pychrono.core") "chrono_python/core/ChSystem.i" 205 //%import(module = "pychrono.core") "chrono_python/core/ChSystemNSC.i" 206 //%import(module = "pychrono.core") "chrono_python/core/ChSystemSMC.i" 207 %import(module = "pychrono.core") "chrono_python/core/ChAssembly.i" 208 %import(module = "pychrono.core") "chrono_python/core/ChCoordsys.i" 209 %import(module = "pychrono.core") "chrono_python/core/ChMatrix.i" 210 %import(module = "pychrono.core") "chrono_python/core/ChBodyFrame.i" 211 %import(module = "pychrono.core") "chrono_python/core/ChBody.i" 212 %import(module = "pychrono.core") "chrono_python/core/ChBodyAuxRef.i" 213 %import(module = "pychrono.core") "chrono_python/core/ChLinkBase.i" 214 %import(module = "pychrono.core") "chrono_python/core/ChLinkLock.i" 215 %import(module = "pychrono.core") "chrono_python/core/ChLinkTSDA.i" 216 %import(module = "pychrono.core") "../chrono/motion_functions/ChFunction_Base.h" 217 %import(module = "pychrono.core") "chrono_python/core/ChMaterialSurface.i" 218 %import(module = "pychrono.core") "../chrono/fea/ChContinuumMaterial.h" 219 %import(module = "pychrono.core") "../chrono/physics/ChPhysicsItem.h" 220 221 %import(module = "pychrono.core") "../chrono/physics/ChBodyFrame.h" 222 %import(module = "pychrono.core") "../chrono/physics/ChLinkBase.h" 223 %import(module = "pychrono.core") "../chrono/assets/ChTriangleMeshShape.h" 224 225 %rename(CollisionFamily_CHASSIS) chrono::robosimian::CollisionFamily::CHASSIS; 226 %rename(CollisionFamily_SLED) chrono::robosimian::CollisionFamily::SLED; 227 %rename(VisualizationType_NONE) chrono::robosimian::VisualizationType::NONE; 228 %rename(VisualizationType_MESH) chrono::robosimian::VisualizationType::MESH; 229 %rename(VisualizationType_COLLISION) chrono::robosimian::VisualizationType::COLLISION; 230 %rename(CollisionFlags_COLLISION) chrono::robosimian::CollisionFlags::CHASSIS; 231 232 %ignore chrono::robosimian::RS_Driver::GetCurrentPhase; 233 %feature("director") chrono::robosimian::RS_Driver::PhaseChangeCallback; 234 235 %include "../../chrono_models/robot/robosimian/RoboSimian.h" 236 %include "../../chrono_models/robot/viper/Viper.h" 237 %include "../../chrono_models/robot/curiosity/Curiosity.h" 238 %include "../../chrono_models/robot/turtlebot/Turtlebot.h" 239 240 %include "../../chrono_models/robot/copters/Copter.h" 241 %template(ChCopter6) chrono::copter::Copter<6>; 242 %template(ChCopter4) chrono::copter::Copter<4>; 243 %include "../../chrono_models/robot/copters/Little_Hexy.h" 244 245 246 247 // 248 // C- DOWNCASTING OF SHARED POINTERS 249 // 250 // This is not automatic in Python + SWIG, except if one uses the 251 // %downcast_output_sharedptr(...) macro, as above, but this causes 252 // a lot of code bloat. 253 // Alternatively, in the following we create a set of Python-side 254 // functions to perform casting by hand, thank to the macro 255 // %DefSharedPtrDynamicDowncast(base,derived). 256 // Do not specify the "chrono::" namespace before base or derived! 257 // Later, in python, you can do the following: 258 // myvis = chrono.CastToChVisualizationShared(myasset) 259 // print ('Could be cast to visualization object?', !myvis.IsNull()) 260 261 //%DefSharedPtrDynamicDowncast2NS(chrono,chrono::fea,ChPhysicsItem,ChMesh) 262 263 264 // 265 // ADDITIONAL C++ FUNCTIONS / CLASSES THAT ARE USED ONLY FOR PYTHON WRAPPER 266 // 267 268 /* 269 %inline %{ 270 271 272 %} 273 */ 274 275 %extend chrono::viper::Viper{ 276 public: Viper(chrono::ChSystem * system)277 Viper(chrono::ChSystem* system){ 278 279 auto selfpoint = std::make_shared<chrono::viper::Viper>(system, ViperWheelType::RealWheel); 280 return selfpoint.get(); 281 } 282 }; 283 284 %extend chrono::curiosity::Curiosity{ 285 public: Curiosity(chrono::ChSystem * system)286 Curiosity(chrono::ChSystem* system){ 287 288 auto selfpoint = std::make_shared<chrono::curiosity::Curiosity>(system, CuriosityChassisType::FullRover, CuriosityWheelType::RealWheel); 289 return selfpoint.get(); 290 } 291 }; 292 293 %extend chrono::turtlebot::TurtleBot{ 294 public: TurtleBot(chrono::ChSystem * system,const chrono::ChVector<double> & robot_pos,const chrono::ChQuaternion<double> & robot_rot)295 TurtleBot(chrono::ChSystem* system, 296 const chrono::ChVector<double>& robot_pos, 297 const chrono::ChQuaternion<double>& robot_rot){ 298 299 auto selfpoint = std::make_shared<chrono::turtlebot::TurtleBot>(system, robot_pos, robot_rot, nullptr); 300 return selfpoint.get(); 301 } 302 }; 303 // 304 // ADD PYTHON CODE 305 // 306 307 /* 308 %pythoncode %{ 309 310 %} 311 */ 312 313 314