Revision dbbad8ed scout/encoders/src/encoders.cpp

View differences:

scout/encoders/src/encoders.cpp
39 39
 * @{
40 40
 **/
41 41

  
42
#include <fstream>
42 43
#include <ros/ros.h>
43 44
#include "encoders.h"
44 45

  
......
70 71
int Encoder::get_ticks()
71 72
{
72 73
    // open device file
73
    fticks.open(filename, std::ios::in);
74
    std::fstream fticks(filename, std::ios::in);
74 75

  
75 76
    int ticks;
76 77
    fticks >> ticks;
77 78

  
78
    fticks.close();
79 79
    return ticks;
80 80
}
81 81

  
82 82
/**
83
 * @brief Resets the encoder
84
 *
85
 * Sets the encoder's ticks value back to 0
86
 */
87
void Encoder::reset()
88
{
89
    std::fstream fticks(filename, std::ios::out);
90
    fticks << 0;
91
}
92

  
93
/**
83 94
 * @brief Outputs current encoder data
84 95
 *
85 96
 * Serves the service query_encoders by responding to service requests with the
......
104 115
}
105 116

  
106 117
/**
118
 * @brief Resets all four encoders
119
 *
120
 * Serves the service reset_encoders
121
 * @param req The request. Empty.
122
 * @param res The response. Empty.
123
 */
124
bool handle_reset_query(::messages::reset_encoders::Request &req,
125
                        ::messages::reset_encoders::Response &res)
126
{
127
    encoder_fl.reset();
128
    encoder_fr.reset();
129
    encoder_bl.reset();
130
    encoder_br.reset();
131
    return true;
132
}
133

  
134
/**
107 135
 * @brief Encoders driver. This is a ROS node that controls encoders.
108 136
 *
109 137
 * This is the main function for the encoders node. It is run when the node

Also available in: Unified diff