Project

General

Profile

Revision 5d4b79f4

ID5d4b79f462bfc53ae26a5f28c77c229ee75a06e5

Added by Thomas Mullins over 12 years ago

Added joystick_control node, with a skeleton of a JoystickControl class,
modeled after the keyboard_control node. Eventually it will take
messages from joy_node and call velocity_control in MikrokopterControl.
At the moment, it compiles but does nothing.

View differences:

mikrokopter/CMakeLists.txt
28 28
rosbuild_add_executable(externctrl_client src/externctrl_client.cpp)
29 29
rosbuild_add_executable(keyboard_control src/keyboard_control.cpp src/nav_lib.cpp)
30 30
target_link_libraries(keyboard_control ncurses)
31
rosbuild_add_executable(joystick_control src/joystick_control.cpp src/nav_lib.cpp)
mikrokopter/manifest.xml
9 9
  <review status="unreviewed" notes=""/>
10 10
  <url>https://aeroscoutsim.frc.cs.cmu.edu/redmine/projects/riverine/wiki/Mikrokopter</url>
11 11
  <depend package="std_msgs" />
12
  <depend package="sensor_msgs" />
12 13
  <depend package="roscpp" />
13 14
  <rosdep name="libserial" />
14 15

  
mikrokopter/src/joystick_control.cpp
1
/**
2
 * @brief A node responsible for reading joystick messages from ros
3
 *        joystick_drivers to control the MikroKopter
4
 *
5
 * @author CMU Quadrotor Project
6
 */
7

  
8
#include <ros/ros.h>
9
#include <sensor_msgs/Joy.h>
10
#include <stdio.h>
11

  
12
#include "nav_lib.h"
13

  
14
class JoystickControl
15
{
16
    public:
17
        JoystickControl();
18
        void joyLoop();
19
        void joyCallback(const sensor_msgs::Joy::ConstPtr& joy);
20

  
21
    private:
22
        MikrokopterControl control;
23
        ros::Publisher pub;
24
        ros::NodeHandle n;
25
        ros::Subscriber sub;
26
};
27

  
28
JoystickControl::JoystickControl()
29
{
30
  pub = n.advertise<mikrokopter::Control>("/mikrokopter/req_set_control", 100); 
31
  sub = n.subscribe<sensor_msgs::Joy>("joy", 100,
32
      &JoystickControl::joyCallback, this);
33
}
34

  
35
void JoystickControl::joyLoop()
36
{
37
    ros::Rate loop_rate(25);
38
    while(ros::ok())
39
    {
40
        ros::spinOnce(); // if joyCallback is called, it will be in here
41
        control.publish_on(pub);
42
        loop_rate.sleep();
43
    }
44
    return;
45
}
46

  
47
void JoystickControl::joyCallback(const sensor_msgs::Joy::ConstPtr& joy)
48
{
49
  // TODO call control.velocity_control(...) based on Joy message
50
}
51

  
52
int main(int argc, char** argv)
53
{
54
    ros::init(argc, argv, "joystick_control");
55
    JoystickControl joy_control;
56

  
57
    // This commands loops infinitely
58
    joy_control.joyLoop();
59

  
60
    return 0;
61
}

Also available in: Unified diff