rh_p12_rn_manager.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 /* Author: Zerom */
18 
19 #include "std_msgs/String.h"
21 
22 /* Sensor Module Header */
23 
24 /* Motion Module Header */
26 
27 using namespace robotis_framework;
28 using namespace dynamixel;
29 using namespace rh_p12_rn;
30 
31 const int BAUD_RATE = 2000000;
32 const double PROTOCOL_VERSION = 2.0;
33 const int DXL_BROADCAST_ID = 254;
34 const int DEFAULT_DXL_ID = 1;
35 const std::string SUB_CONTROLLER_DEVICE = "/dev/ttyUSB0";
36 
37 bool g_is_simulation = false;
39 std::string g_offset_file;
40 std::string g_robot_file;
41 std::string g_init_file;
42 std::string g_device_name;
43 
44 int main(int argc, char **argv)
45 {
46  ros::init(argc, argv, "rh_p12_rn_manager");
47  ros::NodeHandle nh;
48 
49  ROS_INFO("manager->init");
51 
52  /* Load ROS Parameter */
53 
54  nh.param<std::string>("offset_file_path", g_offset_file, "");
55  nh.param<std::string>("robot_file_path", g_robot_file, "");
56  nh.param<std::string>("init_file_path", g_init_file, "");
57  nh.param<std::string>("device_name", g_device_name, SUB_CONTROLLER_DEVICE);
58  nh.param<int>("baud_rate", g_baudrate, BAUD_RATE);
59 
60  nh.param<bool>("gazebo", controller->gazebo_mode_, false);
61  g_is_simulation = controller->gazebo_mode_;
62 
63  /* gazebo simulation */
64  if (g_is_simulation == true)
65  {
66  ROS_WARN("SET TO GAZEBO MODE!");
67  std::string robot_name;
68  nh.param<std::string>("gazebo_robot_name", robot_name, "");
69  if (robot_name != "")
70  controller->gazebo_robot_name_ = robot_name;
71  }
72 
73  if (g_robot_file == "")
74  {
75  ROS_ERROR("NO robot file path in the ROS parameters.");
76  return -1;
77  }
78 
79  // initialize robot
80  if (controller->initialize(g_robot_file, g_init_file) == false)
81  {
82  ROS_ERROR("ROBOTIS Controller Initialize Fail!");
83  return -1;
84  }
85 
86  // load offset
87  if (g_offset_file != "")
88  controller->loadOffset(g_offset_file);
89 
90  usleep(300 * 1000);
91 
92  /* Add Sensor Module */
93 
94  /* Add Motion Module */
95  controller->addMotionModule((MotionModule*) BaseModule::getInstance());
96 
97  // start timer
98  controller->startTimer();
99 
100  controller->setCtrlModule("rh_p12_rn_base_module");
101 
102  while (ros::ok())
103  {
104  usleep(8 * 1000);
105 
106  ros::spin();
107  }
108 
109  return 0;
110 }
std::string g_offset_file
const int DEFAULT_DXL_ID
bool g_is_simulation
int g_baudrate
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
const int BAUD_RATE
int main(int argc, char **argv)
std::string g_robot_file
void addMotionModule(MotionModule *module)
#define ROS_WARN(...)
const std::string SUB_CONTROLLER_DEVICE
std::string g_init_file
bool initialize(const std::string robot_file_path, const std::string init_file_path)
#define ROS_INFO(...)
bool param(const std::string &param_name, T &param_val, const T &default_val) const
void loadOffset(const std::string path)
ROSCPP_DECL bool ok()
ROSCPP_DECL void spin()
const double PROTOCOL_VERSION
#define ROS_ERROR(...)
const int DXL_BROADCAST_ID
std::string g_device_name
void setCtrlModule(std::string module_name)


rh_p12_rn_manager
Author(s): Zerom
autogenerated on Mon Jun 10 2019 14:42:14