gp_input.hpp
Go to the documentation of this file.
1 
9 /*****************************************************************************
10 ** Preprocessor
11 *****************************************************************************/
12 
13 #ifndef KOBUKI_GP_INPUT_HPP__
14 #define KOBUKI_GP_INPUT_HPP__
15 
16 /*****************************************************************************
17 ** Include
18 *****************************************************************************/
19 
20 #include <vector>
21 #include "../packet_handler/payload_base.hpp"
22 #include "../packet_handler/payload_headers.hpp"
23 
24 /*****************************************************************************
25 ** Namespace
26 *****************************************************************************/
27 
28 namespace kobuki
29 {
30 
31 /*****************************************************************************
32 ** Interface
33 *****************************************************************************/
34 
35 class GpInput : public packet_handler::payloadBase
36 {
37 public:
38  GpInput() : packet_handler::payloadBase(false, 16) {};
39  struct Data {
40  Data() : analog_input(4) {}
41  uint16_t digital_input;
47  std::vector<uint16_t> analog_input;
48  } data;
49 
50  bool serialise(ecl::PushAndPop<unsigned char> & byteStream)
51  {
53  buildBytes(length, byteStream);
55  for (unsigned int i = 0; i < data.analog_input.size(); ++i)
56  {
57  buildBytes(data.analog_input[i], byteStream);
58  }
59  for (unsigned int i = 0; i < 3; ++i)
60  {
61  buildBytes(0x0000, byteStream); //dummy
62  }
63  return true;
64  }
65 
67  {
68  if (byteStream.size() < length+2)
69  {
70  //std::cout << "kobuki_node: kobuki_inertia: deserialise failed. not enough byte stream." << std::endl;
71  return false;
72  }
73 
74  unsigned char header_id, length_packed;
75  buildVariable(header_id, byteStream);
76  buildVariable(length_packed, byteStream);
77  if( header_id != Header::GpInput ) return false;
78  if( length_packed != length ) return false;
79 
81 
82  //for (unsigned int i = 0; i < data.analog_input.size(); ++i)
83  // It's actually sending seven 16-bit variables.
84  // 0-3 : the analog pin inputs
85  // 4 : ???
86  // 5-6 : 0
87  for (unsigned int i = 0; i < 4; ++i)
88  {
89  buildVariable(data.analog_input[i], byteStream);
90  }
91  for (unsigned int i = 0; i < 3; ++i) {
92  uint16_t dummy;
93  buildVariable(dummy, byteStream);
94  }
95 
96  //showMe();
97  return constrain();
98  }
99 
100  bool constrain()
101  {
102  return true;
103  }
104 
105  void showMe()
106  {
107  }
108 };
109 
110 } // namespace kobuki
111 
112 #endif /* KOBUKI_GP_INPUT_HPP__ */
113 
kobuki::GpInput::serialise
bool serialise(ecl::PushAndPop< unsigned char > &byteStream)
Definition: gp_input.hpp:64
packet_handler::payloadBase::length
const unsigned char length
Definition: payload_base.hpp:73
kobuki
Definition: command.hpp:31
kobuki::GpInput::GpInput
GpInput()
Definition: gp_input.hpp:52
kobuki::GpInput::data
struct kobuki::GpInput::Data data
packet_handler::payloadBase::payloadBase
payloadBase(const bool is_dynamic_=false, const unsigned char length_=0)
Definition: payload_base.hpp:78
kobuki::GpInput::showMe
void showMe()
Definition: gp_input.hpp:119
kobuki::GpInput::Data::digital_input
uint16_t digital_input
Definition: gp_input.hpp:55
kobuki::GpInput::deserialise
bool deserialise(ecl::PushAndPop< unsigned char > &byteStream)
Definition: gp_input.hpp:80
packet_handler::payloadBase
Provides base class for payloads.
Definition: payload_base.hpp:44
kobuki::Header::GpInput
@ GpInput
Definition: payload_headers.hpp:54
kobuki::GpInput::Data::Data
Data()
Definition: gp_input.hpp:54
kobuki::GpInput::Data::analog_input
std::vector< uint16_t > analog_input
Definition: gp_input.hpp:61
packet_handler::payloadBase::buildVariable
void buildVariable(T &V, ecl::PushAndPop< unsigned char > &buffer)
Definition: payload_base.hpp:96
packet_handler::payloadBase::buildBytes
void buildBytes(const T &V, ecl::PushAndPop< unsigned char > &buffer)
Definition: payload_base.hpp:110
ecl::PushAndPop< unsigned char >
kobuki::GpInput::constrain
bool constrain()
Definition: gp_input.hpp:114
packet_handler
Definition: payload_base.hpp:27
ecl::PushAndPop::size
unsigned int size() const


kobuki_driver
Author(s): Daniel Stonier , Younghun Ju , Jorge Santos Simon
autogenerated on Wed Mar 2 2022 00:26:14