Project

General

Profile

Revision c406f16b

IDc406f16b21285b126852e134d95e7eb421f6d4a2
Child 0121ead7

Added by Ben over 12 years ago

Created first version of git repository; added libscout and motors packages.

The repository root is the ros directory, which contains the ROS stack for the scout project.
The included files are those that ROS creates with a new stack or package, and those created manually. Files created during compilation are not included.
Please do not commit files that are created during compilation.

View differences:

scout/CMakeLists.txt
1
cmake_minimum_required(VERSION 2.4.6)
2
include($ENV{ROS_ROOT}/core/rosbuild/rosbuild.cmake)
3

  
4
# Append to CPACK_SOURCE_IGNORE_FILES a semicolon-separated list of
5
# directories (or patterns, but directories should suffice) that should
6
# be excluded from the distro.  This is not the place to put things that
7
# should be ignored everywhere, like "build" directories; that happens in
8
# rosbuild/rosbuild.cmake.  Here should be listed packages that aren't
9
# ready for inclusion in a distro.
10
#
11
# This list is combined with the list in rosbuild/rosbuild.cmake.  Note
12
# that CMake 2.6 may be required to ensure that the two lists are combined
13
# properly.  CMake 2.4 seems to have unpredictable scoping rules for such
14
# variables.
15
#list(APPEND CPACK_SOURCE_IGNORE_FILES /core/experimental)
16

  
17
rosbuild_make_distribution(0.1.0)
scout/Makefile
1
include $(shell rospack find mk)/cmake_stack.mk
scout/libscout/CMakeLists.txt
1
cmake_minimum_required(VERSION 2.4.6)
2
include($ENV{ROS_ROOT}/core/rosbuild/rosbuild.cmake)
3

  
4
# Set the build type.  Options are:
5
#  Coverage       : w/ debug symbols, w/o optimization, w/ code-coverage
6
#  Debug          : w/ debug symbols, w/o optimization
7
#  Release        : w/o debug symbols, w/ optimization
8
#  RelWithDebInfo : w/ debug symbols, w/ optimization
9
#  MinSizeRel     : w/o debug symbols, w/ optimization, stripped binaries
10
#set(ROS_BUILD_TYPE RelWithDebInfo)
11

  
12
rosbuild_init()
13

  
14
#set the default path for built executables to the "bin" directory
15
set(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin)
16
#set the default path for built libraries to the "lib" directory
17
set(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/lib)
18

  
19
#uncomment if you have defined messages
20
#rosbuild_genmsg()
21
#uncomment if you have defined services
22
#rosbuild_gensrv()
23

  
24
#common commands for building c++ executables and libraries
25
#rosbuild_add_library(${PROJECT_NAME} src/example.cpp)
26
#target_link_libraries(${PROJECT_NAME} another_library)
27
#rosbuild_add_boost_directories()
28
#rosbuild_link_boost(${PROJECT_NAME} thread)
29
#rosbuild_add_executable(example examples/example.cpp)
30
#target_link_libraries(example ${PROJECT_NAME})
31

  
32
rosbuild_add_executable(libscout_node src/libscout.cpp src/libmotors.cpp)
scout/libscout/Makefile
1
include $(shell rospack find mk)/cmake.mk
scout/libscout/mainpage.dox
1
/**
2
\mainpage
3
\htmlinclude manifest.html
4

  
5
\b libscout is the primary libarary of the Colony Scout platform. 
6

  
7
<!-- 
8
Provide an overview of your package.
9
-->
10

  
11

  
12
\section codeapi Code API
13

  
14
<!--
15
Provide links to specific auto-generated API documentation within your
16
package that is of particular interest to a reader. Doxygen will
17
document pretty much every part of your code, so do your best here to
18
point the reader to the actual API.
19

  
20
If your codebase is fairly large or has different sets of APIs, you
21
should use the doxygen 'group' tag to keep these APIs together. For
22
example, the roscpp documentation has 'libros' group.
23
-->
24

  
25

  
26
*/
scout/libscout/manifest.xml
1
<package>
2
  <description brief="libscout">
3

  
4
     libscout
5

  
6
  </description>
7
  <author>Ben</author>
8
  <license>BSD</license>
9
  <review status="unreviewed" notes=""/>
10
  <url>http://ros.org/wiki/libscout</url>
11
  <depend package="std_msgs"/>
12
  <depend package="roscpp"/>
13
  <depend package="motors"/>
14

  
15
</package>
16

  
17

  
scout/libscout/src/constants.h
1
/**
2
 * Copyright (c) 2007 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 constants.h
29
 * @brief Contains top level scout library constants
30
 * 
31
 * Contains constants for use in libscout
32
 *
33
 * @author Colony Project, CMU Robotics Club
34
 **/
35

  
36
/* Author: Ben Wasserman
37
*/
38

  
39

  
40
#ifndef _CONSTANTS_H_
41
#define _CONSTANTS_H_
42

  
43
#include "ros/ros.h"
44

  
45
/* Libscout Defines */
46

  
47
/* Init defines */
48
const int LIB_ALL = ~0;
49
const int LIB_MOTORS = 0x1;
50
const int LIB_SONAR = 0x2;
51
const int LIB_CLIFFSENSORS = 0x4;
52
const int LIB_HEADLIGHTS = 0x8;
53

  
54
/* Status defines */
55
const int LIB_ERROR = ~0;
56
const int LIB_OK = 0;
57

  
58
/* Global objects */
59
ros::NodeHandle libscout_node;
60

  
61
#endif
scout/libscout/src/libmotors.cpp
1
/**
2
 * Copyright (c) 2007 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 libmotors.cpp
29
 * @brief Contains motor declarations and functions
30
 * 
31
 * Contains functions and definitions for the use of
32
 * motors
33
 *
34
 * @author Colony Project, CMU Robotics Club
35
 **/
36

  
37
/* Author: Ben Wasserman
38
*/
39

  
40
#include "libmotors.h"
41

  
42
void libmotors_init(){
43
  set_motors_publisher = libscout_node.advertise<motors::set_motors>("libmotors", 10);
44
  query_motors_client = libscout_node.serviceClient<motors::query_motors>("libmotors");
45
}
46

  
47
int motors_set(int speed, int which){
48
  /** \todo Set fields of the message based on params */
49
  
50
  if(!ros::ok()){
51
    return LIB_ERROR;
52
  }
53
  
54
  motors::set_motors msg;
55
  msg.fl_speed = speed;
56
  msg.fr_speed = speed;
57
  msg.bl_speed = speed;
58
  msg.br_speed = speed;
59

  
60
//  set_motors_publisher.publish(msg);
61
  ros::spinOnce();
62

  
63
  return LIB_OK;
64
}
65

  
66
int motors_speed_set(int speed, int which){
67
  return LIB_OK;
68
}
69

  
70
int motors_query(int which){
71
  motors::query_motors srv;
72
  if(query_motors_client.call(srv)){
73
    switch(which){
74
      case MOTOR_FL:
75
        return srv.response.fl_speed;
76
      case MOTOR_FR:
77
        return srv.response.fr_speed;
78
      case MOTOR_BL:
79
        return srv.response.bl_speed;
80
      case MOTOR_BR:
81
        return srv.response.br_speed;
82
      default:{
83
        ROS_WARN("Bad WHICH in motors_query.");
84
        return LIB_ERROR;
85
      }
86
    }
87
  }else{
88
    ROS_ERROR("Failed to call service query_motors");
89
    return LIB_ERROR;
90
  }
91

  
92
  return 0;
93
}
scout/libscout/src/libmotors.h
1
/**
2
 * Copyright (c) 2007 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 libmotors.h
29
 * @brief Contains motor declarations and functions
30
 * 
31
 * Contains functions and definitions for the use of
32
 * motors
33
 *
34
 * @author Colony Project, CMU Robotics Club
35
 **/
36

  
37
/* Author: Ben Wasserman
38
*/
39

  
40
#include "ros/ros.h"
41
#include "constants.h"
42
#include "motors/query_motors.h"
43
#include "motors/set_motors.h"
44

  
45

  
46
#ifndef _LIBMOTORS_H_
47
#define _LIBMOTORS_H_
48

  
49
/* Defines */
50
const int MOTOR_FL = 0x8;
51
const int MOTOR_FR = 0x4;
52
const int MOTOR_BL = 0x2;
53
const int MOTOR_BR = 0x1;
54

  
55

  
56
ros::Publisher set_motors_publisher;
57
ros::ServiceClient query_motors_client;
58

  
59
void libmotors_init();
60
int motors_set(int speed, int which);
61
int motors_speed_set(int speed, int which);
62
int motors_query(int which);
63

  
64
#endif
scout/libscout/src/libscout.cpp
1
/**
2
 * Copyright (c) 2007 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 libscout.cpp
29
 * @brief Contains top level scout library functions
30
 * 
31
 * Contains functions and definitions for the use of
32
 * libscout
33
 *
34
 * @author Colony Project, CMU Robotics Club
35
 **/
36

  
37
/* Author: Ben Wasserman
38
*/
39

  
40
#include "libscout.h"
41

  
42
/** \todo Decide how to call user behaviors
43
  * I'm thinking that there be a function call in main that calls the "main"
44
  fn in the user behavior. However, their "main" function will not be called 
45
  main. However, this has to be able to point to different functions by 
46
  changing as little code in this file as possible. Also, the user behaviors
47
  should live in a different directory (possibly a different package).
48
  However, this other package should not be executed as a separate node,
49
  because that is the job of the libscout node/package to handle all the ROS 
50
  stuff, and keep it under the lid. The user only has to call normal c 
51
  functions. I also want to reduce the need to recompile this package when the 
52
  user behavior, or any other package that works below the surface.
53
**/
54

  
55

  
56
int main(int argc, char **argv){
57
  ros::init(argc, argv, "libscout");
58

  
59
  init(LIB_ALL);
60
  /** \todo remove this test code **/
61
//  motors_set(100, 0);
62
//  ROS_INFO("%d", motors_query(0));
63

  
64
  return 0;
65
}
66

  
67
int init(int modules){
68
  if(modules & LIB_MOTORS){
69
    libmotors_init();
70
  }
71
  /** \todo Add other lib inits **/
72
  return 0;
73
}
scout/libscout/src/libscout.h
1
/**
2
 * Copyright (c) 2007 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 libscout.h
29
 * @brief Contains top level scout library functions
30
 * 
31
 * Contains functions and definitions for the use of
32
 * libscout
33
 *
34
 * @author Colony Project, CMU Robotics Club
35
 **/
36

  
37
/* Author: Ben Wasserman
38
*/
39

  
40
#ifndef _LIBSCOUT_H_
41
#define _LIBSCOUT_H_
42

  
43
#include "ros/ros.h"
44
#include "constants.h"
45
#include "libmotors.h"
46

  
47

  
48
/* Libscout functions */
49
int main(int argc, char **argv);
50
int init(int modules);
51

  
52
#endif
scout/libscout/src/tags
1
LIB_ALL	constants.h	47
2
LIB_CLIFFSENSORS	constants.h	50
3
LIB_ERROR	constants.h	54
4
LIB_HEADLIGHTS	constants.h	51
5
LIB_MOTORS	constants.h	48
6
LIB_OK	constants.h	55
7
LIB_SONAR	constants.h	49
8
MOTOR_BL	libmotors.h	51
9
MOTOR_BR	libmotors.h	52
10
MOTOR_FL	libmotors.h	49
11
MOTOR_FR	libmotors.h	50
12
Mlibscout.cpp	libscout.cpp	/^int main(int argc, char **argv){$/
13
_CONSTANTS_H_	constants.h	40
14
_LIBMOTORS_H_	libmotors.h	41
15
_LIBSCOUT_H_	libscout.h	41
16
init	libscout.cpp	/^int init(int modules){$/
17
libmotors_init	libmotors.cpp	/^void libmotors_init(){$/
18
libscout_node	constants.h	58
19
motors_query	libmotors.cpp	/^int motors_query(char which){$/
20
motors_set	libmotors.cpp	/^void motors_set(int speed, char which){$/
21
motors_speed_set	libmotors.cpp	/^void motors_speed_set(int speed, char which){$/
22
query_motors_client	libmotors.h	56
23
set_motors_publisher	libmotors.h	55
scout/motors/CMakeLists.txt
1
cmake_minimum_required(VERSION 2.4.6)
2
include($ENV{ROS_ROOT}/core/rosbuild/rosbuild.cmake)
3

  
4
# Set the build type.  Options are:
5
#  Coverage       : w/ debug symbols, w/o optimization, w/ code-coverage
6
#  Debug          : w/ debug symbols, w/o optimization
7
#  Release        : w/o debug symbols, w/ optimization
8
#  RelWithDebInfo : w/ debug symbols, w/ optimization
9
#  MinSizeRel     : w/o debug symbols, w/ optimization, stripped binaries
10
#set(ROS_BUILD_TYPE RelWithDebInfo)
11

  
12
rosbuild_init()
13

  
14
#set the default path for built executables to the "bin" directory
15
set(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin)
16
#set the default path for built libraries to the "lib" directory
17
set(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/lib)
18

  
19
#uncomment if you have defined messages
20
rosbuild_genmsg()
21
#uncomment if you have defined services
22
rosbuild_gensrv()
23

  
24
#common commands for building c++ executables and libraries
25
#rosbuild_add_library(${PROJECT_NAME} src/example.cpp)
26
#target_link_libraries(${PROJECT_NAME} another_library)
27
#rosbuild_add_boost_directories()
28
#rosbuild_link_boost(${PROJECT_NAME} thread)
29
#rosbuild_add_executable(example examples/example.cpp)
30
#target_link_libraries(example ${PROJECT_NAME})
31

  
32
rosbuild_add_executable(motors_node src/motors.cpp)
scout/motors/Makefile
1
include $(shell rospack find mk)/cmake.mk
scout/motors/mainpage.dox
1
/**
2
\mainpage
3
\htmlinclude manifest.html
4

  
5
\b motors is ... 
6

  
7
<!-- 
8
Provide an overview of your package.
9
-->
10

  
11

  
12
\section codeapi Code API
13

  
14
<!--
15
Provide links to specific auto-generated API documentation within your
16
package that is of particular interest to a reader. Doxygen will
17
document pretty much every part of your code, so do your best here to
18
point the reader to the actual API.
19

  
20
If your codebase is fairly large or has different sets of APIs, you
21
should use the doxygen 'group' tag to keep these APIs together. For
22
example, the roscpp documentation has 'libros' group.
23
-->
24

  
25

  
26
*/
scout/motors/manifest.xml
1
<package>
2
  <description brief="motors">
3

  
4
     motors
5

  
6
  </description>
7
  <author>Ben</author>
8
  <license>BSD</license>
9
  <review status="unreviewed" notes=""/>
10
  <url>http://ros.org/wiki/motors</url>
11
  <depend package="roscpp"/>
12
  <depend package="std_msgs"/>
13

  
14
</package>
15

  
16

  
scout/motors/msg/set_motors.msg
1
Header header
2
int8 fl_speed
3
int8 fr_speed
4
int8 bl_speed
5
int8 br_speed
scout/motors/src/motors.cpp
1
/**
2
 * Copyright (c) 2007 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 motors.cpp
29
 * @brief Motors
30
 *
31
 * Implementation of functions for motor use.
32
 *
33
 * @author Colony Project, CMU Robotics Club
34
 * @author Benjamin Wasserman
35
 **/
36

  
37
#include "ros/ros.h"
38
#include "motors.h"
39
#include <cstdlib>
40

  
41
/**
42
 * @defgroup motors Motors
43
 * @brief Functions for using the motors
44
 *
45
 * @{
46
 **/
47

  
48
/*!
49
 * \brief Motors driver. This is a ROS node that controls motor speeds.
50
 *
51
 * This is the main function for the motors node. It is run when the node
52
 * starts and initializes the motors. It then subscribes to the
53
 * set_motors, and set_motor_speeds topics, and advertises the
54
 * query_motors service.
55
 * 
56
 * \param argc The number of command line arguments (should be 1)
57
 * \param argv The array of command line arguments
58
 **/
59
int main(int argc, char **argv){
60
  /* Initialize in ROS the motors driver node */
61
  ros::init(argc, argv, "motors_driver");
62
  
63
  /* Advertise that this serves the query_motors service */
64
  ros::NodeHandle n;
65
  ros::ServiceServer service = n.advertiseService("query_motors", motors_query);
66

  
67
  /* Subscribe to the set_motors topic */
68
  ros::Subscriber sub0 = n.subscribe("set_motors", 4, motors_set);
69

  
70
  /* Initialize hardware for motors */
71
  // Hardware init functions here
72

  
73
  ROS_INFO("Ready to set motors.");
74
  ros::spin();
75

  
76
  return 0;
77
}
78

  
79
/*!
80
 * \brief Sets motor speed
81
 *
82
 * Sets the motor speeds based on subscription to the set_motors topic.
83
 *
84
 * \param msg The message from the set_motors topic, containing speeds and
85
 *  motor configuration settings.
86
 */
87
void motors_set(const motors::set_motors::ConstPtr& msg){
88
  /** \todo Edit to only set requested motors, not all */ 
89
  motor_fl_speed = msg->fl_speed;
90
  motor_fr_speed = msg->fr_speed;
91
  motor_bl_speed = msg->bl_speed;
92
  motor_br_speed = msg->br_speed;
93
}
94

  
95
/*!
96
 * \brief Outputs current motor speeds
97
 *
98
 * Serves the service query_motors by responding to service requests with the
99
 * speeds of the motors.
100
 * \param req The request. Should be empty.
101
 * \param res The response. The fields will be filled with values.
102
 */
103
bool motors_query(motors::query_motors::Request &req,
104
    motors::query_motors::Response &res){
105
  
106
  res.fl_speed = motor_fl_speed;
107
  res.fr_speed = motor_fr_speed;
108
  res.bl_speed = motor_bl_speed;
109
  res.br_speed = motor_br_speed;
110

  
111
  ROS_INFO("Motor speeds queried");
112
  return true;
113
}
114

  
115

  
116
/**
117
 * }
118
 **/
scout/motors/src/motors.h
1
/**
2
 *Copyright (c) 2007 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 motors.h
29
 * @brief Contains motor declarations and functions
30
 * 
31
 * Contains functions and definitions for the use of
32
 * motors
33
 *
34
 * @author Colony Project, CMU Robotics Club
35
 **/
36

  
37
/* Author: Ben Wasserman
38
*/
39

  
40
#ifndef _MOTORS_H_
41
#define _MOTORS_H_
42

  
43
#include "motors/query_motors.h"
44
#include "motors/set_motors.h"
45

  
46
/* Motor state variables */
47
int motor_fl_speed; /**< The current speed of the front left motor. */
48
int motor_fr_speed; /**< The current speed of the front right motor. */
49
int motor_bl_speed; /**< The current speed of the back left motor. */
50
int motor_br_speed; /**< The current speed of the back right motor. */
51

  
52
/** @brief Initialize the motors module and driver **/
53
int main(int argc, char **argv);
54
/** @brief Responds to topic to set motor speeds and configs **/
55
void motors_set(const motors::set_motors::ConstPtr& msg);
56
/** @brief Responds to service to query motor speeds **/
57
bool motors_query(motors::query_motors::Request &req,
58
    motors::query_motors::Response &res);
59

  
60
#endif
scout/motors/srv/query_motors.srv
1
---
2
int8 fl_speed
3
int8 fr_speed
4
int8 bl_speed
5
int8 br_speed
scout/stack.xml
1
<stack>
2
  <description brief="scout">scout</description>
3
  <author>Maintained by Ben</author>
4
  <license>BSD</license>  
5
  <review status="unreviewed" notes=""/>
6
  <url>http://ros.org/wiki/scout</url>
7
  <depend stack="ros" />
8

  
9
</stack>

Also available in: Unified diff