~shadowrobot/sr-ros-interface/stable

« back to all changes in this revision

Viewing changes to shadow_robot/sr_hand/include/sr_hand/sr_publisher.h

  • Committer: Ugo Cupcic
  • Date: 2011-11-21 16:31:23 UTC
  • mfrom: (1.1.164 sr-ros-interface)
  • Revision ID: ugo@shadowrobot.com-20111121163123-k5q6e8l00w81f5hx
0.1.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
3
3
 * @author Ugo Cupcic <ugo@shadowrobot.com>, Contact <contact@shadowrobot.com>
4
4
 * @date   Thu Apr 22 10:26:41 2010
5
5
 * 
 
6
*
 
7
* Copyright 2011 Shadow Robot Company Ltd.
 
8
*
 
9
* This program is free software: you can redistribute it and/or modify it
 
10
* under the terms of the GNU General Public License as published by the Free
 
11
* Software Foundation, either version 2 of the License, or (at your option)
 
12
* any later version.
 
13
*
 
14
* This program is distributed in the hope that it will be useful, but WITHOUT
 
15
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 
16
* FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
 
17
* more details.
 
18
*
 
19
* You should have received a copy of the GNU General Public License along
 
20
* with this program.  If not, see <http://www.gnu.org/licenses/>.
 
21
*
6
22
 * @brief  This class reads and publishes data concerning the
7
23
 * shadowhand / shadowarm. To publish those data, just call the publish()
8
24
 * function. 
20
36
#include <boost/smart_ptr.hpp>
21
37
 
22
38
#include <ros/ros.h>
23
 
#include "sr_hand/hand/shadowhand.h"
 
39
#include "sr_hand/hand/sr_articulated_robot.h"
24
40
 
25
41
using namespace ros;
26
 
using namespace shadowhand;
 
42
using namespace shadowrobot;
27
43
 
28
 
namespace shadowhand_publisher{
 
44
namespace shadowrobot
 
45
{
29
46
/**
30
47
 * This class publishes data concerning the shadowhand /shadowarm, like position, targets, forces, ... on different
31
48
 * topics. To publish those data, just call the publish() function.
35
52
 * (a ROS package). This is useful to visualize the data in rviz (part of ROS). A third topic is
36
53
 * \/prefix\/shadowhand_data. The messages published on this last topic are better formatted for our hardware.
37
54
 */
38
 
class ShadowhandPublisher
 
55
class SRPublisher
39
56
{
40
 
 public:
41
 
  /**
42
 
   * Constructor initializing the ROS node, and setting the topic to which it publishes.
43
 
   * The frequency at which this node will publish data is set by a parameter, read from ROS parameter server.
44
 
   *
45
 
   * @param sh A Shadowhand or Shadowarm object, where the information to be published comes from.
46
 
   */
47
 
  ShadowhandPublisher(boost::shared_ptr<Shadowhand> sh);
48
 
  
49
 
  /// Destructor
50
 
  ~ShadowhandPublisher();
51
 
 
52
 
  /**
53
 
   * The callback method which is called at a given frequency. Gets the data from the shadowhand/shadowarm object.
54
 
   */
55
 
  void publish();
56
 
  
57
 
 private:
58
 
  ///ros node handle
59
 
  NodeHandle node, n_tilde;
60
 
  ///the rate at which the data will be published. This can be set by a parameter in the launch file.
61
 
  Rate publish_rate;
62
 
 
63
 
  ///The shadowhand object (can be either an object connected to the real robot or a virtual hand).
64
 
  boost::shared_ptr<Shadowhand> shadowhand;
65
 
 
66
 
  ///The publisher which publishes the data to the \/{prefix}\/position\/joint_states topic.
67
 
  Publisher shadowhand_jointstate_pos_pub;
68
 
  ///The publisher which publishes the data to the \/{prefix}\/target\/joint_states topic.
69
 
  Publisher shadowhand_jointstate_target_pub;
70
 
  ///The publisher which publishes the data to the \/{prefix}\/shadowhand_data topic.
71
 
  Publisher shadowhand_pub;
72
 
 
73
 
  /**
74
 
   * Convert an angle in degree to an angle in radians.
75
 
   * @param deg the angle in degrees
76
 
   * @return the value in rads.
77
 
   */
78
 
  inline double toRad(double deg)
79
 
  {
80
 
    return deg * 3.14159265 / 180.0;
81
 
  }
 
57
public:
 
58
    /**
 
59
     * Constructor initializing the ROS node, and setting the topic to which it publishes.
 
60
     * The frequency at which this node will publish data is set by a parameter, read from ROS parameter server.
 
61
     *
 
62
     * @param sh A Shadowhand or Shadowarm object, where the information to be published comes from.
 
63
     */
 
64
    SRPublisher( boost::shared_ptr<SRArticulatedRobot> sr_art_robot );
 
65
 
 
66
    /// Destructor
 
67
    ~SRPublisher();
 
68
 
 
69
    /**
 
70
     * The callback method which is called at a given frequency. Gets the data from the shadowhand/shadowarm object.
 
71
     */
 
72
    void publish();
 
73
 
 
74
private:
 
75
    ///ros node handle
 
76
    NodeHandle node, n_tilde;
 
77
    ///the rate at which the data will be published. This can be set by a parameter in the launch file.
 
78
    Rate publish_rate;
 
79
 
 
80
    ///The shadowhand object (can be either an object connected to the real robot or a virtual hand).
 
81
    boost::shared_ptr<SRArticulatedRobot> sr_articulated_robot;
 
82
 
 
83
    ///The publisher which publishes the data to the \/{prefix}\/position\/joint_states topic.
 
84
    Publisher sr_jointstate_pos_pub;
 
85
    ///The publisher which publishes the data to the \/{prefix}\/target\/joint_states topic.
 
86
    Publisher sr_jointstate_target_pub;
 
87
    ///The publisher which publishes the data to the \/{prefix}\/shadowhand_data topic.
 
88
    Publisher sr_pub;
 
89
 
 
90
    /**
 
91
     * Convert an angle in degree to an angle in radians.
 
92
     * @param deg the angle in degrees
 
93
     * @return the value in rads.
 
94
     */
 
95
    inline double toRad( double deg )
 
96
    {
 
97
        return deg * 3.14159265 / 180.0;
 
98
    }
82
99
}; // end class ShadowhandPublisher
83
100
 
84
101
} // end namespace