single_robot_mobile_circle.cpp
Go to the documentation of this file.
1 /*
2  * [c++ example] single robot on mobile
3  * Author: Kab Kyoum Kim (kabkyoum.kim@doosan.com)
4  *
5  * Copyright (c) 2019 Doosan Robotics
6  * Use of this source code is governed by the BSD, see LICENSE
7 */
8 
9 #include <ros/ros.h>
10 #include <geometry_msgs/Twist.h>
11 #include <stdlib.h>
12 #include <signal.h>
13 
14 #include "dsr_util.h"
15 #include "dsr_robot.h"
16 
17 using namespace std;
18 using namespace DSR_Robot;
19 
20 //----- set tartget robot----------------------------------------------------
21 string ROBOT_ID = "dsr01";
22 string ROBOT_MODEL = "m1013";
23 void SET_ROBOT(string id, string model) {ROBOT_ID = id; ROBOT_MODEL= model;}
24 //---------------------------------------------------------------------------
25 
27 
28 static void thread_mobile()
29 {
30  ros::NodeHandlePtr node = boost::make_shared<ros::NodeHandle>();
31  ros::Publisher pubMobile = node->advertise<geometry_msgs::Twist>("/"+ROBOT_ID+"/twist_marker_server/cmd_vel", 1000);
32 
33  srand(time(0));
34  geometry_msgs::Twist msg;
35  float x_odom = 0;
36  float z_angular = 0;
37  msg.linear.x = 10;
38 
39  int time_cnt = 0;
40  while(ros::ok())
41  {
42  msg.linear.x = x_odom;
43  msg.angular.z = z_angular;
44  pubMobile.publish(msg);
45  x_odom = x_odom + 0.1;
46  if(time_cnt > 1)
47  {
48  z_angular = z_angular + 0.005;
49  }
50  //ROS_INFO("thread_mobile running...");
51  time_sleep(0.1);
52  time_cnt++;
53  }
54 
55 }
56 
57 void SigHandler(int sig)
58 {
59  // Do some custom action.
60  // For example, publish a stop message to some other nodes.
61 
62  // All the default sigint handler does is call shutdown()
63  ROS_INFO("shutdown time! sig=%d",sig);
64  ROS_INFO("shutdown time! sig=%d",sig);
65  ROS_INFO("shutdown time! sig=%d",sig);
66  //ros::ServiceClient srvMoveStop = nh.serviceClient<dsr_msgs::MoveStop>("/dsr01m1013/motion/move_stop");
67 
68  ros::NodeHandlePtr node = boost::make_shared<ros::NodeHandle>();
69  ros::Publisher pubRobotStop = node->advertise<dsr_msgs::RobotStop>("/"+ROBOT_ID +ROBOT_MODEL+"/stop",100);
70 
71  dsr_msgs::RobotStop msg;
72 
73  msg.stop_mode = STOP_TYPE_QUICK;
74  pubRobotStop.publish(msg);
75 
76  ros::shutdown();
77 }
78 
79 int main(int argc, char** argv)
80 {
81  //----- set target robot ---------------
82  const string my_robot_id = "dsr01";
83  const string my_robot_model = "m1013";
84  SET_ROBOT(my_robot_id, my_robot_model);
85 
86  //----- init ROS ----------------------
87  ros::init(argc, argv, "single_robot_mobile_circle_cpp", ros::init_options::NoSigintHandler);
88  ros::NodeHandle nh("~");
89  // Override the default ros sigint handler.
90  // This must be set after the first NodeHandle is created.
91  signal(SIGINT, SigHandler);
92  ros::Publisher pubRobotStop = nh.advertise<dsr_msgs::RobotStop>("/"+ROBOT_ID +ROBOT_MODEL+"/stop",10);
94  ros::Publisher pubMobile = nh.advertise<geometry_msgs::Twist>("/"+ROBOT_ID+"/twist_marker_server/cmd_vel", 1000);
95 
96  //----- create DsrRobot ---------------
97  CDsrRobot robot(nh, my_robot_id, my_robot_model);
98 
99  // run subscriber thread (for monitoring)
100  boost::thread thread_sub(thread_mobile);
101 
102 
103  float p1[6]={0.0,}; //joint
104  float p2[6]={0.0, 0.0, 90.0, 0.0, 90.0, 0.0}; //joint
105 
106  float x1[6]={400, 500, 800.0, 0.0, 180.0, 0.0}; //task
107  float x2[6]={400, 500, 500.0, 0.0, 180.0, 0.0}; //task
108  float velx[2]={50, 50}; // 태스크 속도를 50(mm/sec), 50(deg/sec)로 설정
109  float accx[2]={100, 100}; // 태스크 가속도를 100(mm/sec2), 100(deg/sec2)로 설정
110 
111 
112  float veljx[6] = {50, 50, 50, 50, 50, 50};
113  float accjx[6] = {100, 100, 100, 100, 100, 100};
114  float fCirclePos[2][6] = {{559,434.5,651.5,0,180,0}, {559,434.5,251.5,0,180,0}};
115 
116  float amp[6] = {10,0,0,0,30,0};
117  float periodic[6] = {1,0,1.5,0,0,0};
118 
119  float fSJPos[3][6] = {{10, -10, 20, -30, 10, 20}, {25, 0, 10, -50, 20, 40}, {50, 50, 50, 50, 50, 50}};
120  float fSXPos[3][6] = {{600, 600, 600, 0, 175, 0},{600, 750, 600, 0, 175, 0},{150, 600, 450, 0, 175, 0}};
121 
122  float bx1[2][6] = {{370, 670, 650, 0, 180, 0}, {370, 670, 650, 0, 180, 0}};
123  float bx2[2][6] = {{370, 670, 400, 0, 180, 0},{370, 545, 400, 0, 180, 0}};
124  float bx3[2][6] = {{370, 595, 400, 0, 180, 0}, {370, 595, 400, 0, 180, 0}};
125 
126  MOVE_POSB posb[3];// = {bx1, 0, 40}, {bx2, 1, 40}, {bx3, 1, 40};
127  for(int i=0; i<2; i++){
128  for(int j=0; j<6; j++){
129  posb[0]._fTargetPos[i][j] = bx1[i][j];
130  }
131  }
132  for(int i=0; i<2; i++){
133  for(int j=0; j<6; j++){
134  posb[1]._fTargetPos[i][j] = bx2[i][j];
135  }
136  }
137  for(int i=0; i<2; i++){
138  for(int j=0; j<6; j++){
139  posb[2]._fTargetPos[i][j] = bx3[i][j];
140  }
141  }
142  posb[0]._iBlendType = 0;
143  posb[1]._iBlendType = 1;
144  posb[2]._iBlendType = 0;
145  posb[0]._fBlendRad = 20;
146  posb[1]._fBlendRad = 20;
147  posb[2]._fBlendRad = 20;
148 
149  while(ros::ok())
150  {
151  robot.movej(p1, 30, 30);
152  robot.movej(p2, 30, 30);
153  robot.movel(x1, velx, accx);
154  robot.movel(x2, velx, accx);
155 
156  robot.movec(fCirclePos, velx, accx);
157  robot.move_periodic(amp, periodic, 0.5, 3, 0);
158  robot.move_spiral(9.5, 20.0, 50.0, velx, accx, 20.0, TASK_AXIS_Z);
159  robot.movesj(fSJPos,3, 30, 100);
160  robot.movesx(fSXPos, 3, velx, accx);
161 
162  robot.moveb(posb, 3, velx, accx);
163 
164  }
165 
166  ROS_INFO("single_robot_mobile_circle_cpp finished !!!!!!!!!!!!!!!!!!!!!");
167  ROS_INFO("single_robot_mobile_circle_cpp finished !!!!!!!!!!!!!!!!!!!!!");
168  ROS_INFO("single_robot_mobile_circle_cpp finished !!!!!!!!!!!!!!!!!!!!!");
169 
171  thread_sub.join();
172 
173  ROS_INFO("single_robot_mobile_cpp finished !!!!!!!!!!!!!!!!!!!!!");
174  return 0;
175 }
float amp[6]
float velx[2]
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
float accx[2]
#define ROS_INFO(...)
ROSCPP_DECL bool ok()
Publisher advertise(const std::string &topic, uint32_t queue_size, bool latch=false)
string ROBOT_MODEL
ROSCPP_DECL void shutdown()
int main(int argc, char **argv)
void SET_ROBOT(string id, string model)
static void thread_mobile()
void SigHandler(int sig)


cpp
Author(s): Kab Kyoum Kim , Jin Hyuk Gong , Jeongwoo Lee
autogenerated on Sat May 18 2019 02:32:53