Project

General

Profile

Statistics
| Branch: | Revision:

root / scout / scoutsim / src / scout.h @ 144137a1

History | View | Annotate | Download (3.53 KB)

1
/*
2
 * This package was developed by the CMU Robotics Club project using code
3
 * from Willow Garage, Inc.  Please see licensing.txt for details.
4
 *
5
 * All rights reserved.
6
 *
7
 * @file scout.h
8
 * @author Colony Project, CMU Robotics Club
9
 * @author Alex Zirbel
10
 */
11

    
12
#ifndef _SCOUTSIM_SCOUT_H_
13
#define _SCOUTSIM_SCOUT_H_
14

    
15
#include <ros/ros.h>
16
#include <boost/shared_ptr.hpp>
17

    
18
#include <motors/set_motors.h>
19

    
20
#include <scoutsim/Pose.h>
21
#include <scoutsim/SetPen.h>
22
#include <scoutsim/TeleportRelative.h>
23
#include <scoutsim/TeleportAbsolute.h>
24
#include <scoutsim/Color.h>
25

    
26
#include <wx/wx.h>
27

    
28
#define PI 3.14159265
29
/// The scale factor so the speed of scout robots is reasonable for the sim
30
#define SPEED_SCALE_FACTOR 0.05
31

    
32
namespace scoutsim
33
{
34
    struct Vector2
35
    {
36
        Vector2()
37
            : x(0.0)
38
              , y(0.0)
39
        {}
40

    
41
        Vector2(float new_x, float new_y)
42
            : x(new_x)
43
              , y(new_y)
44
        {}
45

    
46
        bool operator==(const Vector2& rhs)
47
        {
48
            return x == rhs.x && y == rhs.y;
49
        }
50

    
51
        bool operator!=(const Vector2& rhs)
52
        {
53
            return x != rhs.x || y != rhs.y;
54
        }
55

    
56
        float x;
57
        float y;
58
    };
59

    
60
    class Scout
61
    {
62
        public:
63
            Scout(const ros::NodeHandle& nh, const wxImage& scout_image,
64
                  const Vector2& pos, float orient);
65

    
66
            void update(double dt, wxMemoryDC& path_dc,
67
                        const wxImage& path_image, wxColour background_color,
68
                        float canvas_width, float canvas_height);
69
            void paint(wxDC& dc);
70

    
71
        private:
72
            void setMotors(const motors::set_motors::ConstPtr& msg);
73
            bool setPenCallback(scoutsim::SetPen::Request&,
74
                                scoutsim::SetPen::Response&);
75
            bool teleportRelativeCallback(scoutsim::TeleportRelative::Request&,
76
                                          scoutsim::TeleportRelative::Response&);
77
            bool teleportAbsoluteCallback(scoutsim::TeleportAbsolute::Request&,
78
                                          scoutsim::TeleportAbsolute::Response&);
79

    
80
            ros::NodeHandle node;
81

    
82
            wxImage scout_image;
83
            wxBitmap scout;
84

    
85
            Vector2 pos;
86
            float orient;
87

    
88
            // Keep track of the last commanded speeds sent to the sim
89
            int motor_fl_speed;
90
            int motor_fr_speed;
91
            int motor_bl_speed;
92
            int motor_br_speed;
93

    
94
            float lin_vel;
95
            float ang_vel;
96
            bool pen_on;
97
            wxPen pen;
98

    
99
            ros::Subscriber motors_sub;
100
            ros::Publisher pose_pub;
101
            ros::Publisher color_pub;
102
            ros::ServiceServer set_pen_srv;
103
            ros::ServiceServer teleport_relative_srv;
104
            ros::ServiceServer teleport_absolute_srv;
105

    
106
            ros::WallTime last_command_time;
107

    
108
            float meter;
109

    
110
            struct TeleportRequest
111
            {
112
                TeleportRequest(float x, float y, float new_theta,
113
                                float new_linear, bool new_relative)
114
                    : pos(x, y)
115
                      , theta(new_theta)
116
                      , linear(new_linear)
117
                      , relative(new_relative)
118
                {}
119

    
120
                Vector2 pos;
121
                float theta;
122
                float linear;
123
                bool relative;
124
            };
125

    
126
            typedef std::vector<TeleportRequest> V_TeleportRequest;
127
            V_TeleportRequest teleport_requests;
128
    };
129
    typedef boost::shared_ptr<Scout> ScoutPtr;
130

    
131
}
132

    
133
#endif