Project

General

Profile

Revision a739cdbd

IDa739cdbdf1aa1f24659aae5e11d1401087cfcd65

Added by Alex Zirbel about 12 years ago

Temporary, possibly broken, commit to add EncodersControl.

Sorry - my ros build is broken. I will immediately debug on Priya's machine.

View differences:

scout/libscout/CMakeLists.txt
29 29
#rosbuild_add_executable(example examples/example.cpp)
30 30
#target_link_libraries(example ${PROJECT_NAME})
31 31

  
32
rosbuild_add_executable(libscout src/Behavior.cpp src/behaviors/draw_cw_circle.cpp src/behaviors/draw_ccw_circle.cpp src/BehaviorList.cpp src/BehaviorProcess.cpp src/MotorControl.cpp src/SonarControl.cpp src/HeadlightControl.cpp src/ButtonControl.cpp src/CliffsensorControl.cpp src/WirelessSender.cpp)
32
rosbuild_add_executable(libscout src/Behavior.cpp src/behaviors/draw_cw_circle.cpp src/behaviors/draw_ccw_circle.cpp src/BehaviorList.cpp src/BehaviorProcess.cpp src/MotorControl.cpp src/SonarControl.cpp src/HeadlightControl.cpp src/ButtonControl.cpp src/CliffsensorControl.cpp src/WirelessSender.cpp src/EncodersControl.cpp)
33 33
rosbuild_add_executable(test_encoders src/test_encoders.cpp)
scout/libscout/src/Behavior.cpp
54 54
    buttons = new ButtonControl(node, scoutname);
55 55
    sonar = new SonarControl(node, scoutname);
56 56
    cliffsensor = new CliffsensorControl(node, scoutname);
57
    encoders = new EncodersControl(node, scoutname);
57 58

  
58 59
    loop_rate = new ros::Rate(10);
59 60
}
scout/libscout/src/Behavior.h
44 44
#include "ButtonControl.h"
45 45
#include "SonarControl.h"
46 46
#include "CliffsensorControl.h"
47
#include "EncodersControl.h"
47 48
#include "constants.h"
48 49

  
49 50
class Behavior
......
66 67
        ButtonControl * buttons;
67 68
        SonarControl * sonar;
68 69
        CliffsensorControl * cliffsensor;
70
        EncodersControl * encoders;
69 71

  
70 72
        // Wrappers for ROS functions
71 73
        bool ok();
scout/libscout/src/EncodersControl.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
 * @file EncodersControl.cpp
28
 * @brief Contains encoder function implementation
29
 * 
30
 * @author Colony Project, CMU Robotics Club
31
 * @author Alex Zirbel
32
 */
33

  
34
#include "SonarControl.h"
35

  
36
using namespace std;
37

  
38
/**
39
 * @brief Initialize the encoders module of libscout.
40
 */
41
EncodersControl::EncodersControl(const ros::NodeHandle& libscout_node,
42
                                 string scoutname)
43
    : node(libscout_node)
44
{
45
    query_client =
46
        node.serviceClient<encoders::query_encoders>(scoutname+"/query_encoders");
47
}
48

  
49
/**
50
 * @brief Returns the current tick count of the encoders.
51
 */
52
encoder_readings EncodersControl::query()
53
{
54
    // Set scan range
55
    encoders::query_encoders srv;
56

  
57
    encoders_readings cur_readings;
58

  
59
    if (!query_client.call(srv))
60
    {
61
        ROS_ERROR("EncodersControl query failed.");
62
    }
63

  
64
    cur_readings.fl_ticks = srv.response.fl_distance;
65
    cur_readings.fr_ticks = srv.response.fr_distance;
66
    cur_readings.bl_ticks = srv.response.bl_distance;
67
    cur_readings.br_ticks = srv.response.br_distance;
68

  
69
    return cur_readings;
70
}
71

  
scout/libscout/src/EncodersControl.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
 * @file EncodersControl.h
28
 * @brief Contains encoder declarations and functions
29
 *
30
 * @author Colony Project, CMU Robotics Club
31
 * @author Alex Zirbel
32
 **/
33

  
34
#ifndef _SONAR_CONTROL_H_
35
#define _SONAR_CONTROL_H_
36

  
37
#include <ros/ros.h>
38
#include <encoders/query_encoders.h>
39

  
40
#include "constants.h"
41

  
42
typedef struct encoder_readings
43
{
44
    unsigned int fl_distance;
45
    unsigned int fr_distance;
46
    unsigned int bl_ticks;
47
    unsigned int br_ticks;
48
} encoder_readings;
49

  
50
class EncodersControl
51
{
52
    public:
53
        /** Set up the encoders class and prepare to communicate over ROS */
54
        EncodersControl(const ros::NodeHandle& libscout_node,
55
                        std::string scoutname);
56

  
57
        /** Use ROS to get the current encoder position. */
58
        void query();
59

  
60
    private:
61

  
62
        /* ROS publisher and client declaration */
63
        ros::ServiceClient query_client;
64
        ros::NodeHandle node;
65
};
66

  
67
#endif
68

  
scout/libscout/src/behaviors/draw_cw_circle.cpp
31 31
    {
32 32
        motors->set_sides(20, 80, MOTOR_ABSOLUTE);
33 33

  
34
        encoder_readings readings = encoders->query();
35

  
36
        ROS_INFO("Encoders: %d %d %d %d", readings.fl_ticks, readings.fr_ticks, readings.bl_ticks, readings.br_ticks);
37

  
34 38
        spinOnce();
35 39
        loop_rate->sleep();
36 40
    }

Also available in: Unified diff