diff --git a/Rapport fonctionnemet.odt b/Rapport fonctionnemet.odt new file mode 100644 index 0000000..fae66db Binary files /dev/null and b/Rapport fonctionnemet.odt differ diff --git a/supervizer/CMakeLists.txt b/supervizer/CMakeLists.txt new file mode 100644 index 0000000..ab81ce6 --- /dev/null +++ b/supervizer/CMakeLists.txt @@ -0,0 +1,216 @@ +cmake_minimum_required(VERSION 2.8.3) +project(supervizer) + +## Find catkin macros and libraries +## if COMPONENTS list like find_package(catkin REQUIRED COMPONENTS xyz) +## is used, also find other catkin packages +find_package(catkin REQUIRED COMPONENTS + roscpp + rospy + std_msgs + message_generation +) + +## System dependencies are found with CMake's conventions +# find_package(Boost REQUIRED COMPONENTS system) + + +## Uncomment this if the package has a setup.py. This macro ensures +## modules and global scripts declared therein get installed +## See http://ros.org/doc/api/catkin/html/user_guide/setup_dot_py.html +# catkin_python_setup() + +################################################ +## Declare ROS messages, services and actions ## +################################################ + +## To declare and build messages, services or actions from within this +## package, follow these steps: +## * Let MSG_DEP_SET be the set of packages whose message types you use in +## your messages/services/actions (e.g. std_msgs, actionlib_msgs, ...). +## * In the file package.xml: +## * add a build_depend tag for "message_generation" +## * add a build_depend and a run_depend tag for each package in MSG_DEP_SET +## * If MSG_DEP_SET isn't empty the following dependency has been pulled in +## but can be declared for certainty nonetheless: +## * add a run_depend tag for "message_runtime" +## * In this file (CMakeLists.txt): +## * add "message_generation" and every package in MSG_DEP_SET to +## find_package(catkin REQUIRED COMPONENTS ...) +## * add "message_runtime" and every package in MSG_DEP_SET to +## catkin_package(CATKIN_DEPENDS ...) +## * uncomment the add_*_files sections below as needed +## and list every .msg/.srv/.action file to be processed +## * uncomment the generate_messages entry below +## * add every package in MSG_DEP_SET to generate_messages(DEPENDENCIES ...) + +## Generate messages in the 'msg' folder + add_message_files( + FILES + beacon.msg + #Reste a mettre les messages propres à chaque fichier" + # + # + ) + +## Generate services in the 'srv' folder +# add_service_files( +# FILES +# Service1.srv +# Service2.srv +# ) + +## Generate actions in the 'action' folder +# add_action_files( +# FILES +# Action1.action +# Action2.action +# ) + +## Generate added messages and services with any dependencies listed here + generate_messages( + DEPENDENCIES + std_msgs + ) + +################################################ +## Declare ROS dynamic reconfigure parameters ## +################################################ + +## To declare and build dynamic reconfigure parameters within this +## package, follow these steps: +## * In the file package.xml: +## * add a build_depend and a run_depend tag for "dynamic_reconfigure" +## * In this file (CMakeLists.txt): +## * add "dynamic_reconfigure" to +## find_package(catkin REQUIRED COMPONENTS ...) +## * uncomment the "generate_dynamic_reconfigure_options" section below +## and list every .cfg file to be processed + +## Generate dynamic reconfigure parameters in the 'cfg' folder +# generate_dynamic_reconfigure_options( +# cfg/DynReconf1.cfg +# cfg/DynReconf2.cfg +# ) + +################################### +## catkin specific configuration ## +################################### +## The catkin_package macro generates cmake config files for your package +## Declare things to be passed to dependent projects +## INCLUDE_DIRS: uncomment this if you package contains header files +## LIBRARIES: libraries you create in this project that dependent projects also need +## CATKIN_DEPENDS: catkin_packages dependent projects also need +## DEPENDS: system dependencies of this project that dependent projects also need +catkin_package( + INCLUDE_DIRS include + LIBRARIES supervizer + CATKIN_DEPENDS roscpp rospy std_msgs message_runtime + DEPENDS system_lib +) + +########### +## Build ## +########### + +## Specify additional locations of header files +## Your package locations should be listed before other locations +# include_directories(include) +include_directories( + ${catkin_INCLUDE_DIRS} +) + +## Declare a C++ library +# add_library(supervizer +# src/${PROJECT_NAME}/supervizer.cpp +# ) + +## Add cmake target dependencies of the library +## as an example, code may need to be generated before libraries +## either from message generation or dynamic reconfigure +# add_dependencies(supervizer ${${PROJECT_NAME}_EXPORTED_TARGETS} ${catkin_EXPORTED_TARGETS}) + +## Declare a C++ executable +# add_executable(supervizer_node src/supervizer_node.cpp) + +## Add cmake target dependencies of the executable +## same as for the library above +# add_dependencies(supervizer_node ${${PROJECT_NAME}_EXPORTED_TARGETS} ${catkin_EXPORTED_TARGETS}) + +## Specify libraries to link a library or executable target against +# target_link_libraries(supervizer_node +# ${catkin_LIBRARIES} +# ) + +############# +## Install ## +############# + +# all install targets should use catkin DESTINATION variables +# See http://ros.org/doc/api/catkin/html/adv_user_guide/variables.html + +## Mark executable scripts (Python etc.) for installation +## in contrast to setup.py, you can choose the destination +# install(PROGRAMS +# scripts/my_python_script +# DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION} +# ) + +## Mark executables and/or libraries for installation +# install(TARGETS supervizer supervizer_node +# ARCHIVE DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION} +# LIBRARY DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION} +# RUNTIME DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION} +# ) + +## Mark cpp header files for installation +# install(DIRECTORY include/${PROJECT_NAME}/ +# DESTINATION ${CATKIN_PACKAGE_INCLUDE_DESTINATION} +# FILES_MATCHING PATTERN "*.h" +# PATTERN ".svn" EXCLUDE +# ) + +## Mark other files for installation (e.g. launch and bag files, etc.) +# install(FILES +# # myfile1 +# # myfile2 +# DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION} +# ) + +############# +## Testing ## +############# + +## Add gtest based cpp test target and link libraries +# catkin_add_gtest(${PROJECT_NAME}-test test/test_supervizer.cpp) +# if(TARGET ${PROJECT_NAME}-test) +# target_link_libraries(${PROJECT_NAME}-test ${PROJECT_NAME}) +# endif() + +## Add folders to be run by python nosetests +# catkin_add_nosetests(test) + +include_directories(include + + + ${catkin_INCLUDE_DIRS}) + +add_executable(supervizer + src/supervizer.cpp + src/CStockage.cpp + ) +target_link_libraries(supervizer ${catkin_LIBRARIES}) +add_dependencies(supervizer supervizer_generate_messages_cpp) + +add_executable(node_test + src/node_test.cpp + ) +target_link_libraries(node_test ${catkin_LIBRARIES}) +add_dependencies(node_test supervizer_generate_messages_cpp) + + +add_executable(deuxio + src/deuxio.cpp + ) +target_link_libraries(deuxio ${catkin_LIBRARIES}) +add_dependencies(deuxio supervizer_generate_messages_cpp) \ No newline at end of file diff --git a/supervizer/include/CStockage.h b/supervizer/include/CStockage.h new file mode 100644 index 0000000..c81d5dd --- /dev/null +++ b/supervizer/include/CStockage.h @@ -0,0 +1,51 @@ + +#ifndef CSTOCKAGE +#define CSTOCKAGE + + + +#include "ros/ros.h" +#include "supervizer/beacon.h" +#include "std_msgs/Time.h" +#include "std_msgs/Duration.h" +#include +#include +#include +#include +#include + +using std::string; +using namespace std; + +class CStockage{ + private: + string m_sName, m_sTopic_In, m_sTopic_Out; + bool m_bState; + ros::Time essai; + std_msgs::Time m_tTps_Reception; + std_msgs::Duration m_dDead_line; + ros::Publisher m_pubEch; + ros::Subscriber m_subEch; + ros::NodeHandle* m_nohNode; + + public: + CStockage(void); + CStockage(string, string, string, ros::Time , ros::Duration, ros::NodeHandle*); + ~CStockage(void); + void callback(const std_msgs::Time&); + void subscribe(void); + void transmission(void); + void repub(void); + + void setData(ros::Time temps){essai = temps;}; + void setTime(ros::Time temps){m_tTps_Reception.data = temps;}; + void setDuration(ros::Duration dur){m_dDead_line.data = dur;}; + void setState(bool etat){m_bState = etat;}; + + ros::Time getTime(void){return m_tTps_Reception.data;}; + ros::Duration getDuration(void){return m_dDead_line.data;}; + std::string getName(void){return m_sName;}; + +}; + +#endif \ No newline at end of file diff --git a/supervizer/msg/beacon.msg b/supervizer/msg/beacon.msg new file mode 100644 index 0000000..baf522b --- /dev/null +++ b/supervizer/msg/beacon.msg @@ -0,0 +1,6 @@ +string name +time r_time +int8 state +string In_topic +string Out_topic +duration dead_line diff --git a/supervizer/package.xml b/supervizer/package.xml new file mode 100644 index 0000000..92eecaf --- /dev/null +++ b/supervizer/package.xml @@ -0,0 +1,50 @@ + + + supervizer + 0.0.1 + The supervizer package + + + + + François Duport + + + + + + TODO + + + + + + + + + + + + + + + + + + catkin + roscpp + rospy + std_msgs + message_generation + roscpp + rospy + std_msgs + message_runtime + + + + + + + + diff --git a/supervizer/src/CStockage.cpp b/supervizer/src/CStockage.cpp new file mode 100644 index 0000000..77e1a8b --- /dev/null +++ b/supervizer/src/CStockage.cpp @@ -0,0 +1,74 @@ +#include "CStockage.h" + +CStockage::CStockage(void) + :m_sName("default"),m_sTopic_In("input"),m_sTopic_Out("output"),m_bState(false) +{ + m_tTps_Reception.data = ros::Time(0); + m_dDead_line.data= ros::Duration(60); +} + CStockage::CStockage(string sName, string sTopic_In, string sTopic_Out, + ros::Time temps = ros::Time::now(), ros::Duration dead_line = ros::Duration(60),ros::NodeHandle* pnh = NULL) + :m_sName(sName),m_sTopic_In(sTopic_In),m_sTopic_Out(sTopic_Out),m_bState(false),m_nohNode(pnh) +{ + essai = ros::Time(0); + m_tTps_Reception.data = temps; + m_dDead_line.data= dead_line; + this->subscribe(); + m_pubEch = m_nohNode->advertise(m_sTopic_Out, 1000); +} +CStockage::~CStockage(void) +{ +} + +void CStockage::callback(const std_msgs::Time &msg) +{ + //TODO Adapter aux echanges complets + // ROS_INFO_STREAM(endl<<"Reception : " << this->getName() << endl); + ros::Time tmp = msg.data; + + this->setData(tmp); + ROS_INFO_STREAM("Temps: "<< this->essai<<" Node :"<< this ->m_sName << " I/O : "<< m_sTopic_In << " "<< m_sTopic_Out); + +} +void CStockage::subscribe() +{ + m_subEch = m_nohNode->subscribe(m_sTopic_In, 10,&CStockage::callback,this); +} + +void CStockage::repub(void) +{ + //TODO Réecrire pour le message complet + ROS_INFO_STREAM("J'envoie de "<< this-> m_sName); + this->m_pubEch.publish(this->m_tTps_Reception); +} + +void CStockage::transmission(void) +{ + //TODO adapter au vrai message + + + ros::Rate loop_rate(1000); + + while (ros::ok()) + { + + std_msgs::Time msg; + + + msg.data = m_tTps_Reception.data + ros::Duration(1); + + ROS_INFO_STREAM("Time : " << msg.data); + + /** + * The publish() function is how you send messages. The parameter + * is the message object. The type of this object must agree with the type + * given as a template parameter to the advertise<>() call, as was done + * in the constructor above. + * + */ + this->m_pubEch.publish(msg); + //TODO looprate + ros::spinOnce(); + + } +} diff --git a/supervizer/src/deuxio.cpp b/supervizer/src/deuxio.cpp new file mode 100644 index 0000000..7e3bc3c --- /dev/null +++ b/supervizer/src/deuxio.cpp @@ -0,0 +1,88 @@ +#include "ros/ros.h" +#include "supervizer/beacon.h" +#include "std_msgs/Time.h" +#include "std_msgs/Duration.h" +#include + + +#include +using std::string; +using std::vector; +using namespace std; + +ros::Publisher beacon_pub ; +ros::Publisher stockage_pub ; +ros::Time tpsmemoire = ros::Time(0); +std::string g_sNomNode, g_sNomIn, g_sNomOut; +ros::NodeHandle* g_nhNode; +void transmission_stockage(void) +{ + + + std_msgs::Time msg; + msg.data = tpsmemoire; + stockage_pub.publish(msg); + ROS_INFO_STREAM("Send time : " <advertise("beacon", 1000); + stockage_pub = g_nhNode->advertise(g_sNomOut, 1000); + + ros::Subscriber sub = g_nhNode->subscribe(g_sNomIn, 10, chatterCallback); + + ros::Rate loop_rate(1); + + while (ros::ok()) + { + transmission_beacon(); + transmission_stockage(); + tpsmemoire = tpsmemoire +ros::Duration(100); + ros::spinOnce(); + loop_rate.sleep(); + } + + return 0; + } \ No newline at end of file diff --git a/supervizer/src/node_test.cpp b/supervizer/src/node_test.cpp new file mode 100644 index 0000000..c61ea18 --- /dev/null +++ b/supervizer/src/node_test.cpp @@ -0,0 +1,87 @@ +#include "ros/ros.h" +#include "supervizer/beacon.h" +#include "std_msgs/Time.h" +#include "std_msgs/Duration.h" +#include + + +#include +using std::string; +using std::vector; +using namespace std; + +ros::Publisher beacon_pub ; +ros::Publisher stockage_pub ; + +std::string g_sNomNode, g_sNomIn, g_sNomOut; +ros::NodeHandle* g_nhNode; +void transmission_stockage(void) +{ + + + std_msgs::Time msg; + msg.data = ros::Time::now(); + stockage_pub.publish(msg); + ROS_INFO_STREAM("Send time : " <advertise("beacon", 1000); + stockage_pub = g_nhNode->advertise(g_sNomOut, 1000); + + ros::Subscriber sub = g_nhNode->subscribe(g_sNomIn, 10, chatterCallback); + + ros::Rate loop_rate(1); + + while (ros::ok()) + { + transmission_beacon(); + transmission_stockage(); + ros::spinOnce(); + loop_rate.sleep(); + } + + return 0; + } \ No newline at end of file diff --git a/supervizer/src/supervizer.cpp b/supervizer/src/supervizer.cpp new file mode 100644 index 0000000..1f0a58c --- /dev/null +++ b/supervizer/src/supervizer.cpp @@ -0,0 +1,126 @@ +#include "ros/ros.h" +#include "supervizer/beacon.h" +#include "std_msgs/Time.h" +#include "std_msgs/Duration.h" +#include +#include "topic_tools/shape_shifter.h" +#include "topic_tools/parse.h" +#include "CStockage.h" + +#include "stdio.h" +#include +using std::string; +using std::vector; +using namespace topic_tools; +using namespace std; +std::vector g_tab_nodes; +ros::NodeHandle* g_node; + +/* +***** Le superviseur ne publie rien de lui meme ****** +void transmission(void) +{ + ros::Publisher chatter_pub = n.advertise("chatter", 1000); + + ros::Rate loop_rate(10); + + int count = 0; + while (ros::ok()) + { + + std_msgs::String msg; + + std::stringstream ss; + ss << "hello world " << count; + msg.data = ss.str(); + + ROS_INFO("%s", msg.data.c_str()); + + /** + * The publish() function is how you send messages. The parameter + * is the message object. The type of this object must agree with the type + * given as a template parameter to the advertise<>() call, as was done + * in the constructor above. + * + chatter_pub.publish(msg); + + ros::spinOnce(); +std_msgs::String + loop_rate.sleep(); + ++count; + } +} +*/ + void beaconCallback(const supervizer::beacon::ConstPtr& msg) +{ + ROS_INFO_STREAM("I heard: "<< msg->name.c_str() <<" " << msg->In_topic.c_str() << endl + << msg->Out_topic.c_str()<< " " << (msg->state?"Actif!":"Idle!")<< " "<r_time.toSec()<< " " << msg->dead_line.toSec()<getName() == msg->name.c_str()) + { + ROS_INFO("Modification"); + g_tab_nodes[i]->setTime(msg->r_time); + ROS_INFO_STREAM("Temps enregistré " << g_tab_nodes[i]->getTime()); + g_tab_nodes[i]->setDuration(msg->dead_line); + g_tab_nodes[i]->setState(msg->state); + + ROS_INFO_STREAM("Ici on gere" << g_tab_nodes[i]->getName()); + research = true; + } + else if(g_tab_nodes.size()!= 0 && igetName() != msg->name.c_str()) + { + ROS_INFO("Test ++"); + i++; + } + else if (g_tab_nodes.size() == 0 || i>=taille) + { + ROS_INFO("Ajout"); + CStockage* S2 = new CStockage(msg->name.c_str(),msg->Out_topic.c_str(), msg->In_topic.c_str(), + msg->r_time, msg->dead_line, g_node); + g_tab_nodes.push_back(S2); + research = true; + + } + else + { + ROS_INFO("Error IF beacon callBack out of range"); + } + } + + +} + +int main(int argc, char **argv) +{ + ros::init(argc, argv, "supervizer"); + + ros::NodeHandle n; + g_node = &n; + ros::Subscriber sub = g_node->subscribe("beacon", 10, beaconCallback); + + while(ros::ok()) + { + ros::Rate loop_rate(1); + if(g_tab_nodes.size() != 0) + { + int taille = g_tab_nodes.size(),i=0; + ROS_INFO("Taille vecteur : %d", taille); + { + g_tab_nodes[i]->repub(); + i++; + } + } + loop_rate.sleep(); + ros::spinOnce(); + } + while(g_tab_nodes.size()!=0) + { + delete(g_tab_nodes[g_tab_nodes.size()-1]); + g_tab_nodes.pop_back(); + + } + return 0; +}