diff --git a/trick_sims/ROS/SIM_ros_publisher/RUN_test/input.py b/trick_sims/ROS/SIM_ros_publisher/RUN_test/input.py new file mode 100644 index 00000000..44032d30 --- /dev/null +++ b/trick_sims/ROS/SIM_ros_publisher/RUN_test/input.py @@ -0,0 +1,9 @@ + +def main(): + trick.real_time_enable() + trick.exec_set_software_frame(0.5) + +if __name__ == "__main__": + main() + + diff --git a/trick_sims/ROS/SIM_ros_publisher/S_define b/trick_sims/ROS/SIM_ros_publisher/S_define new file mode 100644 index 00000000..83c572b6 --- /dev/null +++ b/trick_sims/ROS/SIM_ros_publisher/S_define @@ -0,0 +1,20 @@ + +#include "sim_objects/default_trick_sys.sm" + +##include "ros_comm/ros_framework.hh" +##include "ros_comm/ros_publish.hh" + +class RosPublishSimObject : public Trick::SimObject { + + public: + RosFramework rf ; + RosPublish rp ; + + RosPublishSimObject() : rf("talker") , rp() { + ("initialization") rp.init() ; + (0.5, "scheduled") rp.publish() ; + ("shutdown") rf.shutdown() ; + } +} ; + +RosPublishSimObject rp_so ; diff --git a/trick_sims/ROS/SIM_ros_publisher/S_overrides.mk b/trick_sims/ROS/SIM_ros_publisher/S_overrides.mk new file mode 100644 index 00000000..99c91712 --- /dev/null +++ b/trick_sims/ROS/SIM_ros_publisher/S_overrides.mk @@ -0,0 +1,20 @@ + +ROS_HOME = /opt/ros/jade +TRICK_ICG_EXCLUDE += :${ROS_HOME} + +TRICK_CFLAGS += -I../models -I${ROS_HOME}/include +TRICK_CXXFLAGS += -I../models -I${ROS_HOME}/include -Wno-shadow -Wno-unused-parameter + +TRICK_EXEC_LINK_LIBS += -L${ROS_HOME}/lib -lroscpp -lrosconsole -lroscpp_serialization + +$(MODEL_cpp_OBJ) : | ../models/ros_comm/Num.h + +MESSAGE_FILES = ../models/ros_comm/Num.h + +${MESSAGE_FILES} : %.h : %.msg + cd ${ +#include +#include + +#include +#include +#include +#include + + +namespace trick_msgs +{ +template +struct Num_ +{ + typedef Num_ Type; + + Num_() + : first_name() + , last_name() + , date() + , points(0) + , rebounds(0) + , blocks(0) + , assists(0) { + } + Num_(const ContainerAllocator& _alloc) + : first_name(_alloc) + , last_name(_alloc) + , date(_alloc) + , points(0) + , rebounds(0) + , blocks(0) + , assists(0) { + } + + + + typedef std::basic_string, typename ContainerAllocator::template rebind::other > _first_name_type; + _first_name_type first_name; + + typedef std::basic_string, typename ContainerAllocator::template rebind::other > _last_name_type; + _last_name_type last_name; + + typedef std::basic_string, typename ContainerAllocator::template rebind::other > _date_type; + _date_type date; + + typedef uint8_t _points_type; + _points_type points; + + typedef uint32_t _rebounds_type; + _rebounds_type rebounds; + + typedef uint32_t _blocks_type; + _blocks_type blocks; + + typedef uint32_t _assists_type; + _assists_type assists; + + + + + typedef boost::shared_ptr< ::trick_msgs::Num_ > Ptr; + typedef boost::shared_ptr< ::trick_msgs::Num_ const> ConstPtr; + +}; // struct Num_ + +typedef ::trick_msgs::Num_ > Num; + +typedef boost::shared_ptr< ::trick_msgs::Num > NumPtr; +typedef boost::shared_ptr< ::trick_msgs::Num const> NumConstPtr; + +// constants requiring out of line definition + + + +template +std::ostream& operator<<(std::ostream& s, const ::trick_msgs::Num_ & v) +{ +ros::message_operations::Printer< ::trick_msgs::Num_ >::stream(s, "", v); +return s; +} + +} // namespace trick_msgs + +namespace ros +{ +namespace message_traits +{ + + + +// BOOLTRAITS {'IsFixedSize': False, 'IsMessage': True, 'HasHeader': False} +// {'trick_msgs': ['.'], 'std_msgs': ['/opt/ros/jade/share/std_msgs/cmake/../msg']} + +// !!!!!!!!!!! ['__class__', '__delattr__', '__dict__', '__doc__', '__eq__', '__format__', '__getattribute__', '__hash__', '__init__', '__module__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', '_parsed_fields', 'constants', 'fields', 'full_name', 'has_header', 'header_present', 'names', 'package', 'parsed_fields', 'short_name', 'text', 'types'] + + + + +template +struct IsFixedSize< ::trick_msgs::Num_ > + : FalseType + { }; + +template +struct IsFixedSize< ::trick_msgs::Num_ const> + : FalseType + { }; + +template +struct IsMessage< ::trick_msgs::Num_ > + : TrueType + { }; + +template +struct IsMessage< ::trick_msgs::Num_ const> + : TrueType + { }; + +template +struct HasHeader< ::trick_msgs::Num_ > + : FalseType + { }; + +template +struct HasHeader< ::trick_msgs::Num_ const> + : FalseType + { }; + + +template +struct MD5Sum< ::trick_msgs::Num_ > +{ + static const char* value() + { + return "345b622c1a8704503c97d4d3be56b05d"; + } + + static const char* value(const ::trick_msgs::Num_&) { return value(); } + static const uint64_t static_value1 = 0x345b622c1a870450ULL; + static const uint64_t static_value2 = 0x3c97d4d3be56b05dULL; +}; + +template +struct DataType< ::trick_msgs::Num_ > +{ + static const char* value() + { + return "trick_msgs/Num"; + } + + static const char* value(const ::trick_msgs::Num_&) { return value(); } +}; + +template +struct Definition< ::trick_msgs::Num_ > +{ + static const char* value() + { + return "string first_name\n\ +string last_name\n\ +string date\n\ +uint8 points\n\ +uint32 rebounds\n\ +uint32 blocks\n\ +uint32 assists\n\ +"; + } + + static const char* value(const ::trick_msgs::Num_&) { return value(); } +}; + +} // namespace message_traits +} // namespace ros + +namespace ros +{ +namespace serialization +{ + + template struct Serializer< ::trick_msgs::Num_ > + { + template inline static void allInOne(Stream& stream, T m) + { + stream.next(m.first_name); + stream.next(m.last_name); + stream.next(m.date); + stream.next(m.points); + stream.next(m.rebounds); + stream.next(m.blocks); + stream.next(m.assists); + } + + ROS_DECLARE_ALLINONE_SERIALIZER; + }; // struct Num_ + +} // namespace serialization +} // namespace ros + +namespace ros +{ +namespace message_operations +{ + +template +struct Printer< ::trick_msgs::Num_ > +{ + template static void stream(Stream& s, const std::string& indent, const ::trick_msgs::Num_& v) + { + s << indent << "first_name: "; + Printer, typename ContainerAllocator::template rebind::other > >::stream(s, indent + " ", v.first_name); + s << indent << "last_name: "; + Printer, typename ContainerAllocator::template rebind::other > >::stream(s, indent + " ", v.last_name); + s << indent << "date: "; + Printer, typename ContainerAllocator::template rebind::other > >::stream(s, indent + " ", v.date); + s << indent << "points: "; + Printer::stream(s, indent + " ", v.points); + s << indent << "rebounds: "; + Printer::stream(s, indent + " ", v.rebounds); + s << indent << "blocks: "; + Printer::stream(s, indent + " ", v.blocks); + s << indent << "assists: "; + Printer::stream(s, indent + " ", v.assists); + } +}; + +} // namespace message_operations +} // namespace ros + +#endif // TRICK_MSGS_MESSAGE_NUM_H diff --git a/trick_sims/ROS/models/ros_comm/Num.msg b/trick_sims/ROS/models/ros_comm/Num.msg new file mode 100644 index 00000000..a6375ddf --- /dev/null +++ b/trick_sims/ROS/models/ros_comm/Num.msg @@ -0,0 +1,7 @@ +string first_name +string last_name +string date +uint8 points +uint32 rebounds +uint32 blocks +uint32 assists diff --git a/trick_sims/ROS/models/ros_comm/ros_framework.cpp b/trick_sims/ROS/models/ros_comm/ros_framework.cpp new file mode 100644 index 00000000..b125dff7 --- /dev/null +++ b/trick_sims/ROS/models/ros_comm/ros_framework.cpp @@ -0,0 +1,18 @@ + +#include "ros/ros.h" +#include "trick/command_line_protos.h" +#include "ros_framework.hh" + +RosFramework::RosFramework(std::string app_name) { + int argc = command_line_args_get_argc() ; + char **argv = command_line_args_get_argv() ; + ros::init(argc, argv, app_name.c_str(), ros::init_options::NoSigintHandler) ; +} + +RosFramework::~RosFramework() {} + +int RosFramework::shutdown() { + ros::shutdown() ; + return 0 ; +} + diff --git a/trick_sims/ROS/models/ros_comm/ros_framework.hh b/trick_sims/ROS/models/ros_comm/ros_framework.hh new file mode 100644 index 00000000..3c8fd026 --- /dev/null +++ b/trick_sims/ROS/models/ros_comm/ros_framework.hh @@ -0,0 +1,19 @@ + +/* +PURPOSE: (To be) +LIBRARY_DEPENDENCIES: (ros_framework.cpp) +*/ + +#ifndef ROS_FRAMEWORK_HH +#define ROS_FRAMEWORK_HH + +#include + +class RosFramework { + public: + RosFramework(std::string app_name) ; + virtual ~RosFramework() ; + virtual int shutdown() ; +} ; + +#endif diff --git a/trick_sims/ROS/models/ros_comm/ros_publish.cpp b/trick_sims/ROS/models/ros_comm/ros_publish.cpp new file mode 100644 index 00000000..01e3be6c --- /dev/null +++ b/trick_sims/ROS/models/ros_comm/ros_publish.cpp @@ -0,0 +1,34 @@ + +#include "std_msgs/String.h" +#include "trick/exec_proto.h" +#include "ros_publish.hh" + +#include "Num.h" + +RosPublish::RosPublish() : count(0) {} + +int RosPublish::init() { + msg_pub = n.advertise("num_chatter", 1000) ; + return 0 ; +} + +int RosPublish::publish() { + if ( ros::ok() ) { + trick_msgs::Num tn ; + tn.first_name = "Hakeem" ; + tn.last_name = "Olajuwon" ; + tn.date = "March 29, 1990" ; + tn.points = 18 ; + tn.rebounds = 16 ; + tn.blocks = 11 ; + tn.assists = 10 ; + std::cout << tn << std::endl ; + msg_pub.publish(tn) ; + + ros::spinOnce() ; + } else { + exec_terminate(__FILE__, "ros not ok") ; + } + return 0 ; +} + diff --git a/trick_sims/ROS/models/ros_comm/ros_publish.hh b/trick_sims/ROS/models/ros_comm/ros_publish.hh new file mode 100644 index 00000000..b0e69769 --- /dev/null +++ b/trick_sims/ROS/models/ros_comm/ros_publish.hh @@ -0,0 +1,24 @@ + +/* +PURPOSE: (To be) +LIBRARY_DEPENDENCIES: (ros_publish.cpp) +*/ + +#ifndef ROS_PUBLISH_HH +#define ROS_PUBLISH_HH + +#include "ros/ros.h" + +class RosPublish { + public: + ros::NodeHandle n ; // ** ros nodehandle + ros::Publisher msg_pub ; // ** ros publisher + + int count ; + + RosPublish() ; + int init() ; + int publish() ; +} ; + +#endif diff --git a/trick_sims/ROS/models/ros_comm/ros_subscribe.cpp b/trick_sims/ROS/models/ros_comm/ros_subscribe.cpp new file mode 100644 index 00000000..b896fab8 --- /dev/null +++ b/trick_sims/ROS/models/ros_comm/ros_subscribe.cpp @@ -0,0 +1,21 @@ + +#include "std_msgs/String.h" +#include "ros_subscribe.hh" +#include "Num.h" + +void numchatterCallback(const trick_msgs::Num::ConstPtr& msg) { + std::cout << *msg << std::endl ; +} + +RosSubscribe::RosSubscribe() {} + +int RosSubscribe::init() { + sub = n.subscribe("num_chatter", 1000, numchatterCallback) ; + return 0 ; +} + +int RosSubscribe::process() { + ros::spin() ; + return 0 ; +} + diff --git a/trick_sims/ROS/models/ros_comm/ros_subscribe.hh b/trick_sims/ROS/models/ros_comm/ros_subscribe.hh new file mode 100644 index 00000000..b48e7e55 --- /dev/null +++ b/trick_sims/ROS/models/ros_comm/ros_subscribe.hh @@ -0,0 +1,22 @@ + +/* +PURPOSE: (To be) +LIBRARY_DEPENDENCIES: (ros_subscribe.cpp) +*/ + +#ifndef ROS_SUBSCRIBE_HH +#define ROS_SUBSCRIBE_HH + +#include "ros/ros.h" + +class RosSubscribe { + public: + ros::NodeHandle n ; // ** ros nodehandle + ros::Subscriber sub ; // ** ros subscriber + + RosSubscribe() ; + int init() ; + int process() ; +} ; + +#endif