sensor_module_tutorial.cpp
Go to the documentation of this file.
1 /*******************************************************************************
2 * Copyright 2018 ROBOTIS CO., LTD.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *******************************************************************************/
16 
17 #include <stdio.h>
19 
20 using namespace ROBOTIS;
21 
23  : control_cycle_msec_(8)
24 {
25  module_name_ = "test_sensor_module"; // set unique module name
26 
27  result_["test_sensor"] = 0.0;
28 }
29 
31 {
32  queue_thread_.join();
33 }
34 
35 void SensorModuleTutorial::initialize(const int control_cycle_msec, robotis_framework::Robot *robot)
36 {
37  control_cycle_msec_ = control_cycle_msec;
38  queue_thread_ = boost::thread(boost::bind(&SensorModuleTutorial::queueThread, this));
39 }
40 
42 {
43  ros::NodeHandle ros_node;
44  ros::CallbackQueue callback_queue;
45 
46  ros_node.setCallbackQueue(&callback_queue);
47 
48  /* subscriber */
49  sub1_ = ros_node.subscribe("/tutorial_topic", 10, &SensorModuleTutorial::topicCallback, this);
50 
51  /* publisher */
52  pub1_ = ros_node.advertise<std_msgs::Int16>("/tutorial_publish", 1, true);
53 
54  ros::WallDuration duration(control_cycle_msec_ / 1000.0);
55  while(ros_node.ok())
56  callback_queue.callAvailable(duration);
57 }
58 
59 void SensorModuleTutorial::topicCallback(const std_msgs::Int16::ConstPtr &msg)
60 {
61  std_msgs::Int16 msg_int16;
62  msg_int16.data = msg->data;
63  pub1_.publish(msg_int16);
64 }
65 
66 void SensorModuleTutorial::process(std::map<std::string, robotis_framework::Dynamixel *> dxls,
67  std::map<std::string, robotis_framework::Sensor *> sensors)
68 {
69  uint16_t ext_port_data_1 = dxls["r_leg_an_p"]->dxl_state_->bulk_read_table_["external_port_data_1"];
70  uint16_t ext_port_data_2 = dxls["r_leg_an_p"]->dxl_state_->bulk_read_table_["external_port_data_2"];
71 
72  // ...
73 
74  result_["test_sensor"] = 0.0;
75 }
76 
void publish(const boost::shared_ptr< M > &message) const
Subscriber subscribe(const std::string &topic, uint32_t queue_size, void(T::*fp)(M), T *obj, const TransportHints &transport_hints=TransportHints())
void process(std::map< std::string, robotis_framework::Dynamixel * > dxls, std::map< std::string, robotis_framework::Sensor * > sensors)
void initialize(const int control_cycle_msec, robotis_framework::Robot *robot)
std::map< std::string, double > result_
void setCallbackQueue(CallbackQueueInterface *queue)
void topicCallback(const std_msgs::Int16::ConstPtr &msg)
Publisher advertise(const std::string &topic, uint32_t queue_size, bool latch=false)
bool ok() const


sensor_module_tutorial
Author(s): Zerom , SCH , Kayman
autogenerated on Mon Jun 10 2019 15:37:42