質問編集履歴
9
意図的な質問タイトルの抹消
title
CHANGED
@@ -1,1 +1,1 @@
|
|
1
|
-
|
1
|
+
ノード内のシュミレータロボに座標[5,5]の地点まで動くようにしたい
|
body
CHANGED
File without changes
|
8
初心者マークの追加
title
CHANGED
@@ -1,1 +1,1 @@
|
|
1
|
-
|
1
|
+
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
body
CHANGED
File without changes
|
7
文法の修正
title
CHANGED
File without changes
|
body
CHANGED
@@ -22,6 +22,10 @@
|
|
22
22
|
ros::Subscriber pose_sub;
|
23
23
|
ros::Timer timer;
|
24
24
|
ros::NodeHandle nh;
|
25
|
+
ros::Publisher pose_x;
|
26
|
+
ros::Publisher pose_y;
|
27
|
+
ros::Publisher pose_theta;
|
28
|
+
|
25
29
|
};
|
26
30
|
|
27
31
|
turtleSim::turtleSim(){
|
6
誤字の修正
title
CHANGED
File without changes
|
body
CHANGED
@@ -48,8 +48,8 @@
|
|
48
48
|
}
|
49
49
|
|
50
50
|
void turtleSim::timerCallback(const ros::TimerEvent&){
|
51
|
-
setMoveVector(10);
|
51
|
+
setMoveVector(0.2,20,10);
|
52
|
-
setMoveVector(10);
|
52
|
+
setMoveVector(-0.2,20,10);
|
53
53
|
}
|
54
54
|
|
55
55
|
vvoid turtleSim::setMoveVector(float liner_x,int theta, int cnt){
|
5
書式の改善
title
CHANGED
File without changes
|
body
CHANGED
@@ -14,7 +14,7 @@
|
|
14
14
|
turtleSim();
|
15
15
|
~turtleSim();
|
16
16
|
void poseCallback(const turtlesim::PoseConstPtr& pose);
|
17
|
-
void setMoveVector(int
|
17
|
+
void setMoveVector(float liner_x,int theta, int cnt);
|
18
18
|
void timerCallback(const ros::TimerEvent&);
|
19
19
|
|
20
20
|
private:
|
@@ -52,39 +52,25 @@
|
|
52
52
|
setMoveVector(10);
|
53
53
|
}
|
54
54
|
|
55
|
-
|
55
|
+
vvoid turtleSim::setMoveVector(float liner_x,int theta, int cnt){
|
56
56
|
int i ;
|
57
|
-
float x, y,
|
57
|
+
float x, y,angular,pose_x,pose_y ;
|
58
58
|
geometry_msgs::Twist twist;
|
59
59
|
ros::Rate loop_rate(10);
|
60
60
|
|
61
61
|
x = 5.000000 - pose_x ;
|
62
62
|
y = 5.000000 - pose_y ;
|
63
63
|
theta = atan(y/x) ;
|
64
|
-
angular = 6.283185 - pose_theta ;
|
65
64
|
|
66
|
-
ROS_INFO("pose_x:%f",pose_x) ;
|
67
|
-
ROS_INFO("pose_y:%f",pose_y) ;
|
68
|
-
ROS_INFO("theta:%f",theta) ;
|
69
|
-
ROS_INFO("angular:%f",angular) ;
|
70
|
-
for(i=0;i
|
65
|
+
for(i=0;i<cnt;i++){
|
71
|
-
if(x==0.000000) {
|
72
|
-
ROS_INFO("x:%f",x) ;
|
73
|
-
twist.angular.z = 1.570796 ;
|
74
|
-
twist.
|
66
|
+
twist.liner.x=liner_x;
|
67
|
+
twist.angular.x=theta;
|
75
|
-
twist_pub.publish(twist)
|
68
|
+
twist_pub.publish(twist);
|
76
|
-
loop_rate.sleep()
|
69
|
+
loop_rate.sleep();
|
77
|
-
|
70
|
+
}
|
78
|
-
else {
|
79
|
-
twist.angular.z = angular ;
|
80
|
-
twist.linear.x = x ;
|
81
|
-
twist.linear.y = y ;
|
82
|
-
twist_pub.publish(twist) ;
|
83
|
-
loop_rate.sleep() ;
|
84
|
-
}
|
85
|
-
}
|
86
71
|
}
|
87
72
|
|
73
|
+
|
88
74
|
int main(int argc, char **argv){
|
89
75
|
ros::init(argc, argv, "move_turtlesim");
|
90
76
|
|
4
誤字
title
CHANGED
@@ -1,1 +1,1 @@
|
|
1
|
-
ノード内のシュミレータロボ
|
1
|
+
ノード内のシュミレータロボに座標[5,5]の地点まで動くようにしたい
|
body
CHANGED
File without changes
|
3
文の追加
title
CHANGED
@@ -1,1 +1,1 @@
|
|
1
|
-
ノード内のシュミレータロボである亀に座標[5,5]の地点まで動
|
1
|
+
ノード内のシュミレータロボである亀に座標[5,5]の地点まで動くようにしたい
|
body
CHANGED
File without changes
|
2
大幅な内容の変更
title
CHANGED
@@ -1,1 +1,1 @@
|
|
1
|
-
座標[5,5]の地点まで動いてほしい
|
1
|
+
ノード内のシュミレータロボである亀に座標[5,5]の地点まで動いてほしい
|
body
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
### 前提・実現したいこと
|
2
|
-
今私はROSを使用してturtlesimノードの亀が
|
2
|
+
今私はROSを使用してturtlesimノードの亀が今いる座標軸や回転角を購読してそこから回転、移動して座標[5.5]地点まで動くプログラミングを作りたいと思っており、プログラミングを組み立ててみたのですが、ビルドはできたのですが,亀は超高速で円を描くだけでした。以下にプログラミングを載せますので改善点を教えてもらえないでしょうか。恐らくsetMoveVector関数の中の書き方が違うのかなと思われます。
|
3
3
|
|
4
|
-
|
5
4
|
### 該当のソースコード
|
6
5
|
|
7
6
|
```C++
|
@@ -9,27 +8,27 @@
|
|
9
8
|
#include "ros/ros.h"
|
10
9
|
#include <geometry_msgs/Twist.h>
|
11
10
|
#include <turtlesim/Pose.h>
|
12
|
-
|
11
|
+
|
13
12
|
class turtleSim{
|
14
13
|
public:
|
15
14
|
turtleSim();
|
16
15
|
~turtleSim();
|
17
16
|
void poseCallback(const turtlesim::PoseConstPtr& pose);
|
18
|
-
void setMoveVector(
|
17
|
+
void setMoveVector(int count);
|
19
18
|
void timerCallback(const ros::TimerEvent&);
|
20
|
-
|
19
|
+
|
21
20
|
private:
|
22
21
|
ros::Publisher twist_pub;
|
23
22
|
ros::Subscriber pose_sub;
|
24
23
|
ros::Timer timer;
|
25
24
|
ros::NodeHandle nh;
|
26
25
|
};
|
27
|
-
|
26
|
+
|
28
27
|
turtleSim::turtleSim(){
|
29
28
|
twist_pub = nh.advertise<geometry_msgs::Twist>("turtle1/cmd_vel", 1000);
|
30
29
|
pose_sub = nh.subscribe<turtlesim::Pose>("turtle1/pose", 1, &turtleSim::poseCallback, this);
|
31
30
|
timer = nh.createTimer(ros::Duration(0.1), &turtleSim::timerCallback, this);
|
32
|
-
|
31
|
+
|
33
32
|
geometry_msgs::Twist twist;
|
34
33
|
twist.linear.x = 0.0;
|
35
34
|
twist.linear.y = 0.0;
|
@@ -39,45 +38,66 @@
|
|
39
38
|
twist.angular.z = 0.0;
|
40
39
|
twist_pub.publish(twist);
|
41
40
|
}
|
42
|
-
|
41
|
+
|
43
42
|
turtleSim::~turtleSim(){
|
44
|
-
|
43
|
+
|
45
44
|
}
|
46
|
-
|
45
|
+
|
47
46
|
void turtleSim::poseCallback(const turtlesim::PoseConstPtr& pose){
|
48
47
|
ROS_INFO("x:%f",pose->x);
|
49
48
|
}
|
50
|
-
|
49
|
+
|
51
50
|
void turtleSim::timerCallback(const ros::TimerEvent&){
|
52
|
-
setMoveVector(
|
51
|
+
setMoveVector(10);
|
53
|
-
setMoveVector(
|
52
|
+
setMoveVector(10);
|
54
53
|
}
|
55
|
-
|
54
|
+
|
56
|
-
void turtleSim::setMoveVector(
|
55
|
+
void turtleSim::setMoveVector(int count){
|
57
|
-
int i;
|
56
|
+
int i ;
|
57
|
+
float x, y, theta, angular,pose_x,pose_y,pose_theta ;
|
58
58
|
geometry_msgs::Twist twist;
|
59
59
|
ros::Rate loop_rate(10);
|
60
|
+
|
60
|
-
|
61
|
+
x = 5.000000 - pose_x ;
|
62
|
+
y = 5.000000 - pose_y ;
|
63
|
+
theta = atan(y/x) ;
|
64
|
+
angular = 6.283185 - pose_theta ;
|
65
|
+
|
66
|
+
ROS_INFO("pose_x:%f",pose_x) ;
|
67
|
+
ROS_INFO("pose_y:%f",pose_y) ;
|
68
|
+
ROS_INFO("theta:%f",theta) ;
|
69
|
+
ROS_INFO("angular:%f",angular) ;
|
61
|
-
for(i
|
70
|
+
for(i=0;i < count; i++) {
|
71
|
+
if(x==0.000000) {
|
72
|
+
ROS_INFO("x:%f",x) ;
|
73
|
+
twist.angular.z = 1.570796 ;
|
62
|
-
|
74
|
+
twist.linear.x = y ;
|
63
|
-
|
75
|
+
twist_pub.publish(twist) ;
|
64
|
-
|
76
|
+
loop_rate.sleep() ;
|
65
77
|
}
|
78
|
+
else {
|
79
|
+
twist.angular.z = angular ;
|
80
|
+
twist.linear.x = x ;
|
81
|
+
twist.linear.y = y ;
|
82
|
+
twist_pub.publish(twist) ;
|
83
|
+
loop_rate.sleep() ;
|
84
|
+
}
|
85
|
+
}
|
66
86
|
}
|
67
|
-
|
87
|
+
|
68
88
|
int main(int argc, char **argv){
|
69
89
|
ros::init(argc, argv, "move_turtlesim");
|
70
|
-
|
90
|
+
|
71
91
|
turtleSim turtlesim;
|
72
|
-
|
92
|
+
|
73
93
|
ros::spin();
|
74
94
|
return 0;
|
75
95
|
}
|
96
|
+
|
76
97
|
```
|
77
98
|
|
78
99
|
|
79
100
|
### 試したこと
|
80
|
-
|
101
|
+
とりあえず自分の座標[x,y]と回転角θを購読しそこから目的の座標[5,5]と自分の座標の差を求めそこからatanθを算出そこから亀がどれくらい回転すれば良いのか算出したつもりでした(まぁ、実際のところはできていませんが...)
|
81
|
-
|
82
102
|
### 補足情報(FW/ツールのバージョンなど)
|
83
|
-
今の環境とし
|
103
|
+
今の環境としは、ubuntsu16.4でC++ベースです。
|
1
タイトルの変更
title
CHANGED
@@ -1,1 +1,1 @@
|
|
1
|
-
|
1
|
+
座標[5,5]の地点まで動いてほしい
|
body
CHANGED
File without changes
|