Project

General

Profile

Revision 2d21076d

ID2d21076ddc0e3746bd79e9dcfe122f640a726ff2
Parent 71ae6e3f
Child 3232c4a7

Added by Hui Jun Tay over 10 years ago

Updated files needed for emitters to work

View differences:

scout/.gitignore
38 38
libscout/cmake_install.cmake
39 39

  
40 40
*.swp
41
*~
scout/libscout/src/BehaviorList.cpp
1
/**
2
 ******************************************************************************
3
 * WARNING: THIS IS AN AUTOGENERATED FILE!
4
 *
5
 * Editing this file is USELESS. It will be overwritten during the build.
6
 * To properly edit this file, edit its corresponding *.template.* file, which
7
 * a script run by CMake uses to generate this file.
8
 *
9
 * This file was generated via rules in src/generate_behavior_lists.py.
10
 *
11
 * Please see that file for a description of syntax and procedure for
12
 * creating auto-generated files.
13
 *
14
 * THIS WARNING IS LONG TO MAKE SURE IT GETS YOUR ATTENTION!
15
 * THANK YOU.
16
 *****************************************************************************
17
 */
18

  
19
#include "BehaviorList.h"
20

  
21
BehaviorList::BehaviorList()
22
{
23
  behavior_list.push_back(behavior<pause_scout>);
24
  behavior_list.push_back(behavior<danger_marking>);
25
  behavior_list.push_back(behavior<draw_ccw_circle>);
26
  behavior_list.push_back(behavior<draw_cw_circle>);
27
  behavior_list.push_back(behavior<line_follow>);
28
  behavior_list.push_back(behavior<maze_solve>);
29
  behavior_list.push_back(behavior<maze_solve_simple>);
30
  behavior_list.push_back(behavior<navigationMap>);
31
  behavior_list.push_back(behavior<Odometry>);
32
  behavior_list.push_back(behavior<Odometry_new>);
33
  behavior_list.push_back(behavior<Scheduler>);
34
  behavior_list.push_back(behavior<smart_runaround>);
35
  behavior_list.push_back(behavior<WH_Robot>);
36
  behavior_list.push_back(behavior<wl_test>);
37
  return;
38
}
39

  
40
BehaviorList::~BehaviorList()
41
{
42
  while(!behavior_list.empty())
43
    behavior_list.pop_back();
44
}
scout/scoutsim/src/emitter.cpp
1
/**
2
 BETA version of Emitter object for use in BOM simulator
3
 */
4

  
5
#include "emitter.h"
6

  
7
#include <wx/wx.h>
8

  
9
#define DEFAULT_PEN_R 0xb3
10
#define DEFAULT_PEN_G 0xb8
11
#define DEFAULT_PEN_B 0xff
12

  
13
using namespace std;
14

  
15
namespace scoutsim
16
{
17
    /**
18
     * The emitter object, which is responsible for refreshing itself and
19
     * updating its position.
20
     *
21
     */
22
    Emitter::Emitter(const ros::NodeHandle& nh,
23
                 const wxImage& emitter_image,
24
                 const Vector2& pos,
25
                 wxBitmap *path_bitmap,
26
                 float orient,
27
                 float aperture, 
28
                 int distance)
29
        : path_bitmap(path_bitmap)
30
          , ignore_behavior(false)
31
          , node (nh)
32
          , emitter_image(emitter_image)
33
          , pos(pos)
34
          , orient(orient)
35
          , aperture(aperture)
36
          , distance(distance)
37
          , pen_on(true)
38
          , pen(wxColour(DEFAULT_PEN_R, DEFAULT_PEN_G, DEFAULT_PEN_B))
39
    {
40
        pen.SetWidth(3);
41
        emitter = wxBitmap(emitter_image);
42
        color_pub = node.advertise<Color>("color_sensor", 1);
43
        set_pen_srv = node.advertiseService("set_pen",
44
                                            &Emitter::setPenCallback,
45
                                            this);
46
        // Init latch
47
        teleop_latch = 0;
48
    }
49

  
50
   
51
    bool Emitter::setPenCallback(scoutsim::SetPen::Request& req,
52
                               scoutsim::SetPen::Response&)
53
    {
54
        pen_on = !req.off;
55
        if (req.off)
56
        {
57
            return true;
58
        }
59

  
60
        wxPen pen(wxColour(req.r, req.g, req.b));
61
        if (req.width != 0)
62
        {
63
            pen.SetWidth(req.width);
64
        }
65

  
66
        pen = pen;
67
        return true;
68
    }
69

  
70
    // Scale to linesensor value
71
    unsigned int Emitter::rgb_to_grey(unsigned char r,
72
                                    unsigned char g,
73
                                    unsigned char b)
74
    {
75
        // Should be 0 to 255
76
        unsigned int grey = ((unsigned int) r + (unsigned int) g + (unsigned int) b) / 3;
77

  
78
        /// @todo Convert to the proper range
79
        return 255 - grey;
80
    }
81

  
82
    /// Sends back the position of this emitter so scoutsim can save
83
    /// the world state
84
    /// @todo remove dt param
85
    geometry_msgs::Pose2D Emitter::update(double dt, wxMemoryDC& path_dc,
86
                                        const wxImage& path_image,
87
                                        const wxImage& lines_image,
88
                                        const wxImage& walls_image,
89
                                        wxColour background_color,
90
                                        world_state state)
91
    {
92

  
93
        pos.x = min(max(pos.x, 0.0f), state.canvas_width);
94
        pos.y = min(max(pos.y, 0.0f), state.canvas_height);
95

  
96
        //int canvas_x = pos.x * PIX_PER_METER;
97
        //int canvas_y = pos.y * PIX_PER_METER;
98

  
99

  
100
        {
101
            wxImage rotated_image =
102
                emitter_image.Rotate(orient - PI/2.0,
103
                                   wxPoint(emitter_image.GetWidth() / 2,
104
                                           emitter_image.GetHeight() / 2),
105
                                   false);
106

  
107
            for (int y = 0; y < rotated_image.GetHeight(); ++y)
108
            {
109
                for (int x = 0; x < rotated_image.GetWidth(); ++x)
110
                {
111
                    if (rotated_image.GetRed(x, y) == 255
112
                            && rotated_image.GetBlue(x, y) == 255
113
                            && rotated_image.GetGreen(x, y) == 255)
114
                    {
115
                        rotated_image.SetAlpha(x, y, 0);
116
                    }
117
                }
118
            }
119

  
120
            emitter = wxBitmap(rotated_image);
121
        }
122

  
123
        geometry_msgs::Pose2D my_pose;
124
        my_pose.x = pos.x;
125
        my_pose.y = pos.y;
126
        my_pose.theta = orient;
127

  
128
        return my_pose;
129
    }
130

  
131
    geometry_msgs::Pose2D Emitter::get_pos()
132
    {
133

  
134
        geometry_msgs::Pose2D my_pose;
135
        my_pose.x = pos.x;
136
        my_pose.y = pos.y;
137
        my_pose.theta = orient;
138

  
139
        return my_pose;
140
    }
141

  
142
    void Emitter::paint(wxDC& dc)
143
    {
144
        wxSize emitter_size = wxSize(emitter.GetWidth(), emitter.GetHeight());
145
        dc.DrawBitmap(emitter, pos.x * PIX_PER_METER - (emitter_size.GetWidth() / 2),
146
                      pos.y * PIX_PER_METER - (emitter_size.GetHeight() / 2), true);
147
    }
148

  
149
    void Emitter::set_emitter_visual(bool on)
150
    {
151
        emitter_visual_on = on;
152
    }
153
}
154

  
155
/** @} */
scout/scoutsim/src/emitter.h
1
#ifndef _SCOUTSIM_EMITTER_H_
2
#define _SCOUTSIM_EMITTER_H_
3

  
4
#include <ros/ros.h>
5
#include <vector>
6
#include <boost/shared_ptr.hpp>
7

  
8
#include <scoutsim/Pose.h>
9
#include <scoutsim/SetPen.h>
10
#include <scoutsim/Color.h>
11

  
12
#include <geometry_msgs/Pose2D.h>
13

  
14
#include <wx/wx.h>
15

  
16
#include "scout.h"
17
#include "scoutsim_internal.h"
18
#include "scout_constants.h"
19

  
20
#define PI 3.14159265
21

  
22
#define NUM_LINESENSORS 8
23

  
24
// Distance, pixels, from center of robot to the linesensors.
25
#define LNSNSR_D 20
26

  
27
namespace scoutsim
28
{
29

  
30
    class Emitter
31
    {
32
        public:
33
            Emitter(const ros::NodeHandle& nh,const wxImage& emitter_image,
34
                  const Vector2& pos, wxBitmap *path_bitmap, float orient,
35
                  float aperture, int distance);
36

  
37
            geometry_msgs::Pose2D update(double dt, wxMemoryDC& path_dc,
38
                                         const wxImage& path_image,
39
                                         const wxImage& lines_image,
40
                                         const wxImage& walls_image,
41
                                         wxColour background_color,
42
                                         world_state state);
43

  
44
            geometry_msgs::Pose2D get_pos();
45
            void paint(wxDC& dc);
46
            void set_emitter_visual(bool on);
47

  
48
        private:
49
            float absolute_to_mps(int absolute_speed);
50
            bool setPenCallback(scoutsim::SetPen::Request&,
51
                                scoutsim::SetPen::Response&);
52
            void setMotors(const messages::set_motors::ConstPtr& msg);
53
            unsigned int rgb_to_grey(unsigned char r,
54
                                     unsigned char g,
55
                                     unsigned char b);
56
            bool isFront;
57
            
58
            int teleop_latch;
59

  
60
	        wxBitmap *path_bitmap;
61
	        bool ignore_behavior;
62
            
63
            //std::string current_teleop_scout;
64

  
65
            ros::NodeHandle node;
66

  
67
            wxImage emitter_image;
68
            wxBitmap emitter;
69

  
70
            Vector2 pos;
71
            float orient;
72

  
73
            // Each emitter has a unique id number, which is also displayed on its image.
74
            int emitter_id;
75

  
76
            float aperture;
77
            int distance;
78

  
79
            bool pen_on;
80
            bool emitter_visual_on;
81
            wxPen pen;
82

  
83
            ros::Publisher color_pub;
84
            ros::ServiceServer set_pen_srv;
85

  
86
            ros::WallTime last_command_time;
87
    };
88
    typedef boost::shared_ptr<Emitter> EmitterPtr;
89
}
90

  
91
#endif

Also available in: Unified diff