Project

General

Profile

Statistics
| Branch: | Revision:

root / scout / scoutsim / src / scout_teleop_userinput.cpp @ 86222358

History | View | Annotate | Download (1.47 KB)

1
#include "scout_teleop_userinput.h"
2

    
3
TeleopInput::TeleopInput(std::string scoutname)
4
{
5
    input_pub = node.advertise<scoutsim::teleop_input>(scoutname+"/teleop_input", QUEUE_SIZE);
6
    kfd = 0;
7

    
8
    // get the console in raw mode
9
    tcgetattr(kfd, &cooked);
10
    memcpy(&raw, &cooked, sizeof(struct termios));
11
    raw.c_lflag &=~ (ICANON | ECHO);
12
    // Setting a new line, then end of file                         
13
    raw.c_cc[VEOL] = 1;
14
    raw.c_cc[VEOF] = 2;
15
    tcsetattr(kfd, TCSANOW, &raw);
16

    
17
    //TeleopInput::keyLoop();
18
    return;
19
}
20

    
21
TeleopInput::~TeleopInput()
22
{
23
    // reset console mode to no longer be raw
24
    tcsetattr(kfd, TCSANOW, &cooked);
25
    return;
26
}
27

    
28
void TeleopInput::keyLoop()
29
{
30
    ROS_INFO("press keys to start moving!");
31
    char pressed_key;
32

    
33
    while (ros::ok())
34
    {
35
        // get the next event from the keyboard  
36
        if(read(kfd, &pressed_key, 1) < 0)
37
        {
38
          perror("read():");
39
          exit(-1);
40
        }
41

    
42
        // note: printing this normally slows things the hell down
43
        ROS_DEBUG("pressed key 0x%02X at time: %f\n", pressed_key, ros::Time::now().toSec());
44

    
45
        scoutsim::teleop_input msg;
46
        msg.last_key = pressed_key;
47
        msg.header.stamp = ros::Time::now();
48
        input_pub.publish(msg);    
49
        
50
        ros::spinOnce();
51
    }
52
    return;
53
}
54

    
55
int main(int argc, char** argv)
56
{
57
    ros::init(argc, argv, "scout_teleop_userinput");
58
    TeleopInput teleop_input = TeleopInput("scout1");
59
    teleop_input.keyLoop();
60

    
61
    return(0);
62
}
63