10 #ifndef _GAZEBO_WORLD_SERVER_HH_
11 #define _GAZEBO_WORLD_SERVER_HH_
12 #ifndef _GAZEBO_CUTOMIZED_WORLD_PLUGIN
13 #define _GAZEBO_CUTOMIZED_WORLD_PLUGIN WorldServer
24 #include <boost/bind.hpp>
29 #include "gazebo/gazebo.hh"
30 #include "gazebo/common/common.hh"
31 #include "gazebo/transport/transport.hh"
32 #include "gazebo/physics/physics.hh"
33 #include "gazebo/msgs/msgs.hh"
35 #include "collision_message.pb.h"
36 #include "command_message.pb.h"
37 #include "world_status_message.pb.h"
42 #include "SmoresModule.hh"
44 #include "CollisionInformation.hh"
45 #include "Condition.hh"
47 #include "ColorLog.hh"
49 #include "LibraryTemplate.hh"
51 #define PI 3.141593 // 3.1411593
52 #define VALIDCONNECTIONDISUPPER 0.110
53 #define VALIDCONNECTIONDISLOWER 0.098
55 #define MODULEPATH "SMORE.sdf"
61 typedef const boost::shared_ptr
62 <
const collision_message::msgs::CollisionMessage> CollisionMessagePtr;
63 typedef const boost::shared_ptr
64 <
const command_message::msgs::CommandMessage> CommandMessagePtr;
65 typedef boost::shared_ptr<gazebo::Condition> ConditionPtr;
66 typedef const boost::shared_ptr
67 <
const command_message::msgs::WorldStatusMessage> WorldStatusMessagePtr;
87 sdf::ElementPtr _sdf);
93 virtual void OnSystemRunningExtra(
const common::UpdateInfo & _info);
98 virtual void InsertModel(
string name, math::Pose position,
string joint_angles);
103 virtual void InsertModel(
string name, math::Pose position,
string joint_angles,
146 int node1_ID,
int node2_ID,
double node_angle,
double node_distance);
149 int node1_ID,
int node2_ID);
152 int node1_ID,
int node2_ID,
double node_angle,
double node_distance);
155 int node1_ID,
int node2_ID);
162 void Disconnect(
string moduleName,
int node_ID);
164 void Disconnect(
string moduleName1,
string moduleName2);
181 const double *gait_value,
int msg_type,
unsigned int time_stamp,
182 string condition_str,
string dependency_str);
194 const double *gait_value,
int msg_type,
unsigned int time_stamp);
207 const double *gait_value,
int msg_type,
208 string condition_str,
string dependency_str);
219 const double *gait_value,
int msg_type);
232 double gait_value,
int msg_type,
unsigned int time_stamp,
233 string condition_str,
string dependency_str);
244 double gait_value,
int msg_type,
unsigned int time_stamp);
256 double gait_value,
int msg_type,
257 string condition_str,
string dependency_str);
267 double gait_value,
int msg_type);
282 int node1,
int node2,
int commandtype,
unsigned int time_stamp,
283 string condition_str,
string dependency_str);
296 int node1,
int node2,
int commandtype,
unsigned int time_stamp);
310 int node1,
int node2,
int commandtype,
311 string condition_str,
string dependency_str);
323 int node1,
int node2,
int commandtype);
334 const double *gait_value,
int msg_type);
344 const double *gait_value);
353 double orientation_angle);
366 int GetNodeIDByName(
string node_name);
380 int GetModuleIndexByName(
string module_name);
383 int node1_ID,
int node2_ID);
396 void FigureInterpret(
const vector<string> *joints_spec,
int *type_flags,
397 double *joint_values);
421 void Load(physics::WorldPtr _parent, sdf::ElementPtr _sdf);
423 void AddEntityToWorld(std::string & _info);
425 void OnSystemRunning(
const common::UpdateInfo & );
427 void FeedBackMessageDecoding(CommandMessagePtr &msg);
429 void WorldStatusMessageDecoding(WorldStatusMessagePtr &msg);
433 void AutomaticMagneticConnectionManagement(CollisionMessagePtr &msg);
438 SmoresEdgePtr an_edge);
441 void RotationQuaternionCalculation(math::Vector3 normal_axis,
442 math::Vector3 z_axis_of_link1, math::Vector3 z_axis_of_link2,
443 math::Vector3 first_rotation, math::Vector3 second_rotation,
444 math::Quaternion *first_rotation_of_link2,
445 math::Quaternion *second_rotation_of_link2);
447 void NewPositionCalculation(SmoresEdgePtr an_edge,
448 math::Pose old_pose_of_module1, math::Pose old_pose_of_module2,
449 int node1_ID,
int node2_ID,
450 math::Pose *new_pose_of_module1, math::Pose *new_pose_of_module2);
452 void CommandManager(
void);
455 void AddCondition(
string conditionid);
456 void FinishOneConditionCommand(
string conditionid);
457 bool CheckCondition(
string conditionid);
459 int StripOffTimerInCommandString(
string &command_string);
461 string StripOffCondition(
string &command_string);
463 string StripOffDependency(
string &command_string);
466 physics::WorldPtr currentWorld;
468 event::ConnectionPtr addEntityConnection;
469 transport::PublisherPtr welcomePub;
471 transport::PublisherPtr smoreWorldPub;
472 transport::SubscriberPtr smoreWorldSub;
474 vector<SmoresModulePtr> moduleList;
476 vector<CollisionInformation> pendingRequest;
478 vector<physics::JointPtr> dynamicConnections;
480 event::ConnectionPtr updateConnection;
482 vector<SmoresEdgePtr> connectionEdges;
484 vector<string> waitingNameList;
486 vector<string> initalJointValue;
488 vector<math::Pose> initialPosition;
490 vector<ConditionPtr> commandConditions;
491 vector<ModuleCommandsPtr> moduleCommandContainer;
494 vector<transport::SubscriberPtr> WorldColSubscriber;
496 bool autoMagneticConnectionFlag;
498 string configurationFile;
LibraryTemplate * DynamicallyLoadedLibrary(const char *library_path, void *lib_handle)
Load a shared library in linux.
Definition: WorldServer.cc:67
boost::shared_ptr< ModuleCommands > ModuleCommandsPtr
Smart pointer to the ModuleCommands object.
Definition: SmoresModule.hh:23
This file contains rapidxml parser and DOM implementation.
Definition: LibraryTemplate.hh:13
void DeleteModule(string module_name)
Delete a model that already in the world.
Definition: WorldServer.cc:643
gazebo name space
Definition: system_gui.cc:41
void DeleteSmoresmodulePtr(string module_name)
Delete the smoresmodule object in the world.
Definition: WorldServer.cc:600
void SendPositionInstance(SmoresModulePtr module, double x, double y, double orientation_angle)
Used in direct control, dirve a module to a specific position.
Definition: WorldServer.cc:1075
void InterpretSpecialString(string a_command_str)
Interpret special command.
Definition: WorldServer.cc:1294
virtual void InsertModel(string name, math::Pose position, string joint_angles)
Insert a model to the current world.
Definition: WorldServer.cc:542
void BuildConnectionFromXML(string file_name)
This function is used to build connection using a XML file.
Definition: WorldServer.cc:201
unsigned int GetModuleListSize(void)
Get the count of the modules that are in the list.
Definition: WorldServer.cc:1145
Definition: WorldServer.hh:80
void EnableAutoMagneticConnection(void)
Definition: WorldServer.cc:88
void SendGaitTable(SmoresModulePtr module, const int *flag, const double *gait_value, int msg_type, unsigned int time_stamp, string condition_str, string dependency_str)
Send time based common gait with condition and dependency.
Definition: WorldServer.cc:880
bool AlreadyConnected(SmoresModulePtr module_1, SmoresModulePtr module_2, int node1_ID, int node2_ID)
Check whether two nodes are connected together.
Definition: WorldServer.cc:1169
SmoresModulePtr GetModulePtrByName(string module_name)
Get SmoresModule object by specifying the name.
Definition: WorldServer.cc:1126
void ReBuildDynamicJoint(SmoresEdgePtr a_edge)
Rebuild the dynamic joint using the information in the edge object.
Definition: WorldServer.cc:1464
void DeleteAllModules(void)
Delete all models that already in the world.
Definition: WorldServer.cc:657
virtual void ExtraInitializationInLoad(physics::WorldPtr _parent, sdf::ElementPtr _sdf)
This function will be called in Load() to perform extra initialization.
Definition: WorldServer.cc:64
void Disconnect(SmoresEdgePtr aEdge)
Definition: WorldServer.cc:748
SmoresEdgePtr GetEdgePtrByIDX(unsigned int idx)
Get SmoresEdge object by specifying the index in the vector connectionEdges.
Definition: WorldServer.cc:1456
void PassiveConnect(SmoresModulePtr module_1, SmoresModulePtr module_2, int node1_ID, int node2_ID, double node_angle, double node_distance)
Connect two modules by pointers and node_ID.
Definition: WorldServer.cc:705
unsigned int CountModules(SmoresModulePtr module)
Count how many modules are there in a cluster with the current module.
Definition: WorldServer.cc:1207
string Int2String(int number)
Converts int to string.
Definition: util.hh:25
bool CheckModuleExistByName(string module_name)
Get return true if the smores module with given name exist in the world.
Definition: WorldServer.cc:1117
boost::shared_ptr< SmoresModule > SmoresModulePtr
Smart pointer of the SmoresModule object.
Definition: CommandManagement.hh:19
void SendGaitTableInstance(SmoresModulePtr module, const int *flag, const double *gait_value, int msg_type)
Used in the direct driving situation, ignore execution order.
Definition: WorldServer.cc:1059
void CloseLoadedLibrary(void **lib_handle)
Close the loaded libraries.
Definition: WorldServer.cc:84
void AddInitialPosition(math::Pose position)
Add a new position to set at the end of 'intialPosition' vector.
Definition: WorldServer.cc:592
virtual void ExtraWorkWhenModelInserted(CommandMessagePtr &msg)
This function will be called after set the model initial position.
Definition: WorldServer.cc:313
unsigned int GetEdgeCounts(void)
Get the total counts of the edges that stored in the program.
Definition: WorldServer.cc:1460
double ConversionForAngleOverPi(double angle)
Convert angles so that their absolutely value always smaller than Pi.
Definition: WorldServer.cc:522
SmoresModulePtr GetModulePtrByIDX(unsigned int idx)
Get SmoresModule object by specifying the index in the vector moduleList.
Definition: WorldServer.cc:1137
void EraseComaands(SmoresModulePtr module)
Definition: WorldServer.cc:1091
void FigureInterpret(const vector< string > *joints_spec, int *type_flags, double *joint_values)
Used to interpret the number in gait table.
Definition: WorldServer.cc:1355
void AddInitialJoints(string joint_angles)
Add new initial joint values to set at the end of 'initalJointValue' vector.
Definition: WorldServer.cc:596
math::Vector3 GetCurrentConfigurationPose(void)
Get the current position in world of the inserted configuration.
Definition: WorldServer.cc:682
void BuildConfigurationFromXML(string file_name)
Build a configuration at origin using a XML file.
Definition: WorldServer.cc:145
void ActiveConnect(SmoresModulePtr module_1, SmoresModulePtr module_2, int node1_ID, int node2_ID, double node_angle, double node_distance)
TODO: Need add 'active' feature to this function.
Definition: WorldServer.cc:726
void DynamicJointDestroy(SmoresEdgePtr aEdge)
Definition: WorldServer.cc:529
void InterpretCommonGaitString(string a_command_str)
Interpret normal command string.
Definition: WorldServer.cc:1263
void ReadFileAndGenerateCommands(const char *fileName)
Read a 'gait table' stored in a text file.
Definition: WorldServer.cc:1232
unsigned int GetInitialJointSequenceSize(void)
Get the length of the initial joint value setting sequence.
Definition: WorldServer.cc:1228