Commit 6ec55188 authored by Mohamed Ahmed's avatar Mohamed Ahmed

Adding all pakcages ros-services based

parent 5fa21b48
......@@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 2.8.3)
project(timeClient)
## Compile as C++11, supported in ROS Kinetic and newer
# add_compile_options(-std=c++11)
add_compile_options(-std=c++11)
## Find catkin macros and libraries
## if COMPONENTS list like find_package(catkin REQUIRED COMPONENTS xyz)
......@@ -10,6 +10,7 @@ project(timeClient)
find_package(catkin REQUIRED COMPONENTS
roscpp
std_msgs
message_generation
)
## System dependencies are found with CMake's conventions
......@@ -46,18 +47,19 @@ find_package(catkin REQUIRED COMPONENTS
## * add every package in MSG_DEP_SET to generate_messages(DEPENDENCIES ...)
## Generate messages in the 'msg' folder
# add_message_files(
# FILES
add_message_files(
FILES
time.msg
# Message1.msg
# Message2.msg
# )
)
## Generate services in the 'srv' folder
# add_service_files(
# FILES
# Service1.srv
add_service_files(
FILES
time_srv.srv
# Service2.srv
# )
)
## Generate actions in the 'action' folder
# add_action_files(
......@@ -67,10 +69,10 @@ find_package(catkin REQUIRED COMPONENTS
# )
## Generate added messages and services with any dependencies listed here
# generate_messages(
# DEPENDENCIES
# std_msgs
# )
generate_messages(
DEPENDENCIES
std_msgs
)
################################################
## Declare ROS dynamic reconfigure parameters ##
......@@ -104,7 +106,7 @@ find_package(catkin REQUIRED COMPONENTS
catkin_package(
# INCLUDE_DIRS include
# LIBRARIES timeClient
# CATKIN_DEPENDS roscpp std_msgs
CATKIN_DEPENDS message_runtime
# DEPENDS system_lib
)
......
uint8 hours
uint8 minutes
uint8 seconds
\ No newline at end of file
......@@ -51,6 +51,8 @@
<buildtool_depend>catkin</buildtool_depend>
<build_depend>roscpp</build_depend>
<build_depend>std_msgs</build_depend>
<build_depend>message_generation</build_depend>
<exec_depend>message_runtime</exec_depend>
<build_export_depend>roscpp</build_export_depend>
<build_export_depend>std_msgs</build_export_depend>
<exec_depend>roscpp</exec_depend>
......
bool getTime
---
uint8 hours
uint8 minutes
uint8 seconds
\ No newline at end of file
......@@ -11,21 +11,27 @@
#include "ros/master.h"
#include "std_msgs/Int64.h"
#include "std_msgs/Bool.h"
//#include "timeClient/time.h"
#include "timeClient/time_srv.h"
namespace methods
{
class getTime
{
private:
// bool flag;
timeService::getTimeOutput returnValue;
ros::NodeHandle rosHandler;
ros::ServiceClient getTimeClient;
// ros::Publisher proxyTimePublisher;
// ros::Subscriber proxyTimeSubscriber;
// void proxyCallBack(const timeClient::time &msg);
public:
getTime();
bool flag;
timeService::getTimeOutput returnValue;
ros::NodeHandle rosHandler;
ros::Publisher proxyTimePublisher;
ros::Subscriber proxyTimeSubscriber;
void proxyCallBack(const std_msgs::Int64 &msg);
/**
* \brief Operation will call the method.
*
......
......@@ -2,30 +2,45 @@
using namespace methods;
getTime::getTime(): flag(false)
getTime::getTime()//: flag(false)
{
proxyTimePublisher = rosHandler.advertise<std_msgs::Bool>("/request",100);
proxyTimeSubscriber = rosHandler.subscribe("/timeTopic_",100,&getTime::proxyCallBack,this);
getTimeClient = rosHandler.serviceClient<timeClient::time_srv>("timeService");
// proxyTimePublisher = rosHandler.advertise<std_msgs::Bool>("/request",100);
// proxyTimeSubscriber = rosHandler.subscribe("/timeTopic_",100,&getTime::proxyCallBack,this);
}
ara::core::Future<timeService::getTimeOutput> getTime::operator()()
{
/*
std_msgs::Bool tMsg;
tMsg.data = true;
proxyTimePublisher.publish(tMsg);
while(flag == false)
{}
ara::core::Promise<timeService::getTimeOutput> promise;
promise.set_value(returnValue);
{
proxyTimePublisher.publish(tMsg);
}
*/
timeClient::time_srv srv;
srv.request.getTime = true;
if(getTimeClient.call(srv)){
ROS_INFO("\nHours: %i\nMinutes: %i\nSeconds: %i", srv.response.hours,srv.response.minutes,srv.response.seconds);
}
returnValue.hours = srv.response.hours;
returnValue.minutes = srv.response.minutes;
returnValue.seconds = srv.response.seconds;
ara::core::Promise<timeService::getTimeOutput> promise;
promise.set_value(returnValue);
return promise.get_future();
}
void getTime::proxyCallBack(const std_msgs::Int64 &msg)
/*
void getTime::proxyCallBack(const timeClient::time &msg)
{
ROS_INFO("%i",msg.data);
returnValue.seconds = msg.data;
ROS_INFO("\nHours: %i\nMinutes: %i\nSeconds: %i\n",msg.hours,msg.minutes,msg.seconds);
returnValue.hours = msg.hours;
returnValue.minutes = msg.minutes;
returnValue.seconds = msg.seconds;
flag = true;
}
*/
\ No newline at end of file
......@@ -25,12 +25,12 @@ void Timeactivity::run()
{
while(1)
{
ROS_INFO("############3\n###############3");
//ROS_INFO("############3\n###############3");
std::this_thread::sleep_for(std::chrono::milliseconds(DELAY));
if (nullptr != m_proxy)
{
ROS_INFO("############3\n**************83");
//ROS_INFO("############\n**************83");
std::chrono::time_point<std::chrono::system_clock> deadline
= std::chrono::system_clock::now() + std::chrono::milliseconds(DEADLINE);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment