-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcontrol2.cpp
executable file
·82 lines (73 loc) · 1.52 KB
/
control2.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#include "ros/ros.h"
#include "prius_msgs/Control.h"
#include <opencv2/core/core.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <iostream>
using namespace std;
int main(int argc, char **argv)
{
ros::init(argc, argv, "control2");
ros::NodeHandle n;
ros::Publisher instance = n.advertise<prius_msgs::Control>("/prius", 1000);
prius_msgs::Control msg;
msg.throttle = 0.0;
msg.brake = 0.0;
msg.steer = 0.0;
msg.shift_gears = 1;
cv::namedWindow("control");
char input = '0';
while (ros::ok() && input != 'q')
{
if (input == 'w')
{
msg.throttle = 3.5;
msg.brake = 0.0;
msg.steer = 0.0;
}
else if (input == 's')
{
msg.brake = 1.0;
msg.throttle = 0.0;
msg.steer = 0.0;
}
else if (input == 'a')
{
msg.throttle = 1.0;
msg.brake = 0.0;
msg.steer = 1.0;
}
else if (input == 'd')
{
msg.throttle = 1.0;
msg.brake = 0.0;
msg.steer = -1.0;
}
else if (input == 'i')
{
msg.throttle = 0.0;
msg.brake = 0.0;
msg.steer = 0.0;
msg.shift_gears = 2;
}
else if (input == 'o')
{
msg.throttle = 0.0;
msg.brake = 0.0;
msg.steer = 0.0;
msg.shift_gears = 1;
}
else if (input == 'p')
{
msg.throttle = 0.0;
msg.brake = 0.0;
msg.steer = 0.0;
msg.shift_gears = 3;
}
input = '0';
input = (char)cv::waitKey(1);
instance.publish(msg);
}
ros::spinOnce();
return 0;
}