Project

General

Profile

Revision d1cc615c

IDd1cc615c522c68ed0eef8c9d42f9e2b38f833714

Added by Leon almost 8 years ago

actually removing what I removed

View differences:

scout/buttons/msg/button_event.msg
1 1
Header header
2
int8 button1_pressed
3
int8 button2_pressed
2
bool button1_pressed
3
bool button2_pressed
scout/buttons/srv/query_buttons.srv
1 1
int8 units
2 2
---
3
int8 button1_pressed
4
int8 button2_pressed
3
bool button1_pressed
4
bool button2_pressed
scout/buttons/srv/query_motors.srv
1
int8 units
2
---
3
int8 fl_speed
4
int8 fr_speed
5
int8 bl_speed
6
int8 br_speed
scout/libscout/src/ButtonControl.cpp
48 48
    button_event_sub = node.subscribe("button_event", QUEUE_SIZE, event_button);
49 49
}
50 50

  
51
/*!
51
/*!*
52 52
 * @brief Respond to button events
53 53
 * Sends out button events if buttons are pressed. 
54 54
 * Processes message and updates private variables
scout/libscout/src/libbuttons.cpp
1
/**
2
 * Copyright (c) 2011 Colony Project
3
 * 
4
 * Permission is hereby granted, free of charge, to any person
5
 * obtaining a copy of this software and associated documentation
6
 * files (the "Software"), to deal in the Software without
7
 * restriction, including without limitation the rights to use,
8
 * copy, modify, merge, publish, distribute, sublicense, and/or sell
9
 * copies of the Software, and to permit persons to whom the
10
 * Software is furnished to do so, subject to the following
11
 * conditions:
12
 * 
13
 * The above copyright notice and this permission notice shall be
14
 * included in all copies or substantial portions of the Software.
15
 * 
16
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
18
 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
20
 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
21
 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23
 * OTHER DEALINGS IN THE SOFTWARE.
24
 **/
25

  
26

  
27
/**
28
 * @file libbuttons.cpp
29
 * @brief Contains buttons declarations and functions
30
 * 
31
 * Contains functions and definitions for the use of
32
 * buttons
33
 *
34
 * @author Colony Project, CMU Robotics Club
35
 **/
36

  
37
/* Author: Priyanka Deo
38
*/
39

  
40
#include "libbuttons.h"
41

  
42

  
43
/* ROS node created in libscout.cpp */
44
extern ros::NodeHandle node;
45

  
46
/** ROS publisher and client declaration */
47
ros::Publisher button_event_publisher;
48
ros::ServiceClient query_buttons_client;
49

  
50
/*!
51
 * \brief Initialize the buttons module of libscout.
52
 *
53
 * Initialize the libscout node as a publisher of button_event and a client of
54
 * query_buttons.
55
 */
56
void libbuttons_init()
57
{
58
  button_event_publisher = node.advertise<buttons::button_event>("libbuttons", 10);
59
  query_buttons_client = node.serviceClient<buttons::query_buttons>("libbuttons");
60
}
61

  
62
/*!
63
 * \brief Respond to button events
64
 * Sends out button events if buttons are pressed. Tells which buttons
65
 * have been pressed.
66
 * \param which_button - Which button is pressed
67
 * \param which A bitmask of which motors should be set
68
 * \return Function status
69
 */
70
int event_button(int which_button)
71
{
72
  if(!ros::ok())
73
  {
74
    return LIB_ERROR;
75
  }
76

  
77
  /* Create message */
78
  buttons::button_event msg;
79
  switch(which_button)
80
  {
81
    case BUTTON1:
82
      msg.button1_pressed = BUTTON_PRESSED;
83
      break;
84
    case BUTTON2:
85
      msg.button2_pressed = BUTTON_PRESSED;
86
      break;
87
    default:
88
      ROS_ERROR("Button %d does not exist\n", which_button);
89
      return LIB_ERROR;
90
  }
91

  
92
  /* Publishes message to button_event topic */
93
  button_event_publisher.publish(msg);
94
  ros::spinOnce();
95

  
96
  return LIB_OK;
97
}
98

  
99
/*!
100
 * \brief Query the current status of the buttons
101
 *
102
 * Sends a request to the query_buttons service which will reply with the
103
 *  current status of the buttons
104
 *
105
 * \param which_button - Which button we are querying
106
 * \return status of the button queried, or LIB_ERROR on error
107
 */
108

  
109
int buttons_query(int which_button)
110
{
111
  buttons::query_buttons srv;
112
  if(query_buttons_client.call(srv))
113
  {
114
    switch(which_button)
115
    {
116
      case BUTTON1:
117
        return srv.response.button1_pressed;
118
      case BUTTON2:
119
        return srv.response.button2_pressed;
120
      default:
121
        ROS_ERROR("Button %d does not exist", which_button);
122
        return LIB_ERROR;
123
    }
124
  }
125
  else
126
  {
127
    ROS_ERROR("Failed to call service query_buttons");
128
    return LIB_ERROR;
129
  }
130
  
131
  /* Code never reaches here */
132
  return 0;
133
}
scout/libscout/src/libbuttons.h
1
/**
2
 * Copyright (c) 2011 Colony Project
3
 * 
4
 * Permission is hereby granted, free of charge, to any person
5
 * obtaining a copy of this software and associated documentation
6
 * files (the "Software"), to deal in the Software without
7
 * restriction, including without limitation the rights to use,
8
 * copy, modify, merge, publish, distribute, sublicense, and/or sell
9
 * copies of the Software, and to permit persons to whom the
10
 * Software is furnished to do so, subject to the following
11
 * conditions:
12
 * 
13
 * The above copyright notice and this permission notice shall be
14
 * included in all copies or substantial portions of the Software.
15
 * 
16
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
18
 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
20
 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
21
 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23
 * OTHER DEALINGS IN THE SOFTWARE.
24
 **/
25

  
26

  
27
/**
28
 * @file libbuttons.h
29
 * @brief Contains buttons declarations and functions
30
 * 
31
 * Contains functions and definitions for the use of
32
 * buttons
33
 *
34
 * @author Colony Project, CMU Robotics Club
35
 **/
36

  
37
/* Author: Priyanka Deo
38
*/
39

  
40
#include "ros/ros.h"
41
#include "constants.h"
42
#include "buttons/query_buttons.h"
43
#include "buttons/button_event.h"
44

  
45
#ifndef _LIBBUTTONS_H_
46
#define _LIBBUTTONS_H_
47

  
48
/* Defines */
49
#define BUTTON1 0
50
#define BUTTON2 1
51
#define BUTTON_PRESSED 1
52

  
53
void libbuttons_init();
54
int event_button(int which_button);
55
int buttons_query(int which_button);
56

  
57
#endif
58

  
scout/motors/manifest.xml
11 11
  <depend package="std_msgs"/>
12 12

  
13 13
  <export>
14
    <cpp cflags="-I${prefix}/include" lflags="-Wl,-rpath,${prefix}/lib -L${prefix}/lib -lmotors"/>
14
    <cpp cflags="-I${prefix}/include" lflags="-Wl,-rpath,${prefix}/lib -L${prefix}/lib"/>
15 15
  </export>
16 16

  
17 17
</package>
scout/scoutsim/manifest.xml
21 21
    <cpp cflags="-I${prefix}/msg/cpp -I${prefix}/srv/cpp"/>
22 22
  </export>-->
23 23
  <export>
24
    <cpp cflags="-I${prefix}/msg/cpp -I${prefix}/srv/cpp -I${prefix}/include" lflags="-Wl,-rpath,${prefix}/lib -L${prefix}/lib -lmotors"/>
24
    <cpp cflags="-I${prefix}/msg/cpp -I${prefix}/srv/cpp -I${prefix}/include" lflags="-Wl,-rpath,${prefix}/lib -L${prefix}/libk"/>
25 25
  </export>
26 26

  
27 27
  <platform os="ubuntu" version="9.04"/>

Also available in: Unified diff