command.cpp
Go to the documentation of this file.
1 
10 /*****************************************************************************
11 ** Includes
12 *****************************************************************************/
13 
14 #include "../../include/xbot_driver/command.hpp"
15 
16 /*****************************************************************************
17 ** Namespaces
18 *****************************************************************************/
19 
20 namespace xbot {
21 
22 /*****************************************************************************
23 ** Static variables initialization
24 *****************************************************************************/
25 
26 const unsigned char Command::header0 = 0xaa;
27 const unsigned char Command::header1 = 0x55;
28 
29 /*****************************************************************************
30 ** Implementation [Command Generators]
31 *****************************************************************************/
32 
33 
34 
35 
36 
37 
39 {
40  Command outgoing;
41  std::vector<float> velocity_commands = diff_drive.velocityCommands();
42  outgoing.data.speed = velocity_commands[0];
43  outgoing.data.radius = velocity_commands[1];
45  return outgoing;
46 }
47 
48 Command Command::SetVelocityControl(const float &speed, const float &radius)
49 {
50  Command outgoing;
51  outgoing.data.speed = speed;
52  outgoing.data.radius = radius;
54  return outgoing;
55 }
56 
57 Command Command::SetLiftControl(const unsigned char &lift_height)
58 {
59  Command outgoing;
60  outgoing.data.lift_height = lift_height;
61  outgoing.data.command = Command::Lift;
62  return outgoing;
63 
64 
65 }
66 
67 Command Command::SetYawPlatformControl(const int &yaw_platform_degree)
68 {
69  Command outgoing;
70  outgoing.data.yaw_platform_degree = yaw_platform_degree+120;
72  return outgoing;
73 
74 }
75 
76 Command Command::SetPitchPlatformControl(const int &pitch_platform_degree)
77 {
78  Command outgoing;
79  outgoing.data.pitch_platform_degree = pitch_platform_degree+120;
81  return outgoing;
82 
83 }
84 
85 Command Command::SetSoundControl(const bool &sound_state)
86 {
87  Command outgoing;
88  outgoing.data.sound_state = sound_state;
89  outgoing.data.command = Command::Sound;
90  return outgoing;
91 
92 }
93 
94 Command Command::SetLedControl(const unsigned char &led)
95 {
96  Command outgoing;
97  outgoing.data.led = led;
98  outgoing.data.command = Command::StateLed;
99  return outgoing;
100 
101 }
102 
103 
104 Command Command::SetPowerControl(const bool &power_state)
105 {
106  Command outgoing;
107  outgoing.data.power_state = power_state;
108  outgoing.data.command = Command::Power;
109  return outgoing;
110 }
111 
112 /*****************************************************************************
113 ** Implementation [Serialisation]
114 *****************************************************************************/
119  buffer.clear();
120  buffer.resize(64);
121  buffer.push_back(Command::header0);
122  buffer.push_back(Command::header1);
123  buffer.push_back(0); // just initialise, we usually write in the payload here later (size of payload only, not stx, not etx, not length)
124 }
125 
127 {
128  // need to be sure we don't pass through an emum to the Trans'd buildBytes functions.
129  unsigned char cmd = static_cast<unsigned char>(data.command);
130  unsigned char lift_label = 1;
131  switch (data.command)
132  {
133  case Power:
134  buildBytes(cmd, byteStream);
135  buildBytes(data.power_state, byteStream);
136  break;
137  case BaseControl:
138  buildBytes(cmd, byteStream);
139  buildBytes(data.speed, byteStream);
140  buildBytes(data.radius, byteStream);
141  break;
142  case Lift:
143  buildBytes(cmd, byteStream);
144  buildBytes(lift_label, byteStream);
145  buildBytes(data.lift_height, byteStream);
146  break;
147  case YawPlatform:
148  buildBytes(cmd, byteStream);
149  buildBytes(data.yaw_platform_degree, byteStream);
150  break;
151  case PitchPlatform:
152  buildBytes(cmd, byteStream);
154  break;
155  case Sound:
156  buildBytes(cmd, byteStream);
157  buildBytes(data.sound_state, byteStream);
158  break;
159  case StateLed:
160  buildBytes(cmd,byteStream);
161  buildBytes(data.led, byteStream);
162  break;
163  default:
164  return false;
165  break;
166  }
167  return true;
168 }
169 
170 
171 
172 } // namespace xbot
static const unsigned char header1
Definition: command.hpp:122
bool serialise(ecl::PushAndPop< unsigned char > &byteStream)
Definition: command.cpp:126
unsigned char pitch_platform_degree
Definition: command.hpp:88
void velocityCommands(const float &vx, const float &wz)
Definition: diff_drive.cpp:143
static Command SetPowerControl(const bool &power_state)
Definition: command.cpp:104
double radius
void resetBuffer(Buffer &buffer)
Definition: command.cpp:118
static Command SetYawPlatformControl(const int &yaw_platform_degree)
Definition: command.cpp:67
static Command SetLedControl(const unsigned char &led)
Definition: command.cpp:94
unsigned char yaw_platform_degree
Definition: command.hpp:87
static const unsigned char header0
Definition: command.hpp:121
static Command SetSoundControl(const bool &sound_state)
Definition: command.cpp:85
unsigned char lift_height
Definition: command.hpp:86
void push_back(const Type &datum)
static Command SetPitchPlatformControl(const int &pitch_platform_degree)
Definition: command.cpp:76
double speed
unsigned char led
Definition: command.hpp:89
Definition: command.hpp:30
void buildBytes(const T &V, ecl::PushAndPop< unsigned char > &buffer)
static Command SetVelocityControl(DiffDrive &diff_drive)
Definition: command.cpp:38
static Command SetLiftControl(const unsigned char &lift_height)
Definition: command.cpp:57


xbot_driver
Author(s): Roc, wangpeng@droid.ac.cn
autogenerated on Sat Oct 10 2020 03:27:37