Message_cmd.cpp
Go to the documentation of this file.
00001 
00046 #include "husky_base/horizon_legacy/Message_cmd.h"
00047 
00048 #include <cstring>
00049 #include <iostream>
00050 #include <typeinfo>
00051 
00052 using namespace std;
00053 
00054 #include "husky_base/horizon_legacy/Number.h"
00055 // Conditions on the below to handle compiling for nonstandard hardware
00056 #ifdef LOGGING_AVAIL
00057 #include "husky_base/horizon_legacy/Logger.h"
00058 #endif
00059 
00060 namespace clearpath
00061 {
00062 
00063   long CmdMessage::total_destroyed = 0;
00064   long CmdMessage::total_sent = 0;
00065 
00066   CmdMessage::~CmdMessage()
00067   {
00068     ++total_destroyed;
00069     if (!is_sent)
00070     {
00071 #ifdef LOGGING_AVAIL
00072         CPR_WARN() << "Command message destroyed without being sent. Type: "
00073             << "0x" << hex << getType() << dec 
00074             << ". Total unsent: " << (total_destroyed-total_sent) << endl;
00075 #endif
00076     }
00077     else
00078     {
00079       total_sent++;
00080     }
00081   }
00082 
00083 
00084   CmdProcessorReset::CmdProcessorReset() : CmdMessage()
00085   {
00086     setPayloadLength(2);
00087     utob(getPayloadPointer(), 2, (uint16_t) 0x3A18);
00088     setType(CMD_PROCESSOR_RESET);
00089     makeValid();
00090   }
00091 
00092   CmdProcessorReset::CmdProcessorReset(const CmdProcessorReset &other) : CmdMessage(other)
00093   {
00094   }
00095 
00096 
00097   CmdRestoreSettings::CmdRestoreSettings(enum restoreFlags flags) : CmdMessage()
00098   {
00099     setPayloadLength(3);
00100 
00101     utob(getPayloadPointer(), 2, (uint16_t) (0x3a18));
00102     *getPayloadPointer(2) = (uint8_t) (flags);
00103     setType(CMD_RESTORE_SETTINGS);
00104 
00105     makeValid();
00106   }
00107 
00108   CmdRestoreSettings::CmdRestoreSettings(const CmdRestoreSettings &other) : CmdMessage(other)
00109   {
00110   }
00111 
00112 
00113   CmdStoreSettings::CmdStoreSettings() : CmdMessage()
00114   {
00115     setPayloadLength(2);
00116 
00117     utob(getPayloadPointer(), 2, (uint16_t) (0x3a18));
00118     setType(CMD_STORE_SETTINGS);
00119 
00120     makeValid();
00121   }
00122 
00123   CmdStoreSettings::CmdStoreSettings(const CmdStoreSettings &other) : CmdMessage(other)
00124   {
00125   }
00126 
00127 
00128   SetAckermannOutput::SetAckermannOutput(double steer, double throt, double brake) : CmdMessage()
00129   {
00130     setPayloadLength(PAYLOAD_LEN);
00131 
00132     ftob(getPayloadPointer(STEERING), 2, steer, 100);
00133     ftob(getPayloadPointer(THROTTLE), 2, throt, 100);
00134     ftob(getPayloadPointer(BRAKE), 2, brake, 100);
00135 
00136     setType(SET_ACKERMANN_SETPT);
00137     makeValid();
00138   }
00139 
00140   SetAckermannOutput::SetAckermannOutput(const SetAckermannOutput &other) : CmdMessage(other)
00141   {
00142   }
00143 
00144 
00145   SetDifferentialControl::SetDifferentialControl(
00146       double p,
00147       double i,
00148       double d,
00149       double feedfwd,
00150       double stic,
00151       double int_lim)
00152       : CmdMessage()
00153   {
00154     setPayloadLength(PAYLOAD_LEN);
00155 
00156     ftob(getPayloadPointer(LEFT_P), 2, p, 100);
00157     ftob(getPayloadPointer(LEFT_I), 2, i, 100);
00158     ftob(getPayloadPointer(LEFT_D), 2, d, 100);
00159     ftob(getPayloadPointer(LEFT_FEEDFWD), 2, feedfwd, 100);
00160     ftob(getPayloadPointer(LEFT_STIC), 2, stic, 100);
00161     ftob(getPayloadPointer(LEFT_INT_LIM), 2, int_lim, 100);
00162 
00163     ftob(getPayloadPointer(RIGHT_P), 2, p, 100);
00164     ftob(getPayloadPointer(RIGHT_I), 2, i, 100);
00165     ftob(getPayloadPointer(RIGHT_D), 2, d, 100);
00166     ftob(getPayloadPointer(RIGHT_FEEDFWD), 2, feedfwd, 100);
00167     ftob(getPayloadPointer(RIGHT_STIC), 2, stic, 100);
00168     ftob(getPayloadPointer(RIGHT_INT_LIM), 2, int_lim, 100);
00169 
00170     setType(SET_DIFF_CTRL_CONSTS);
00171     makeValid();
00172   }
00173 
00174   SetDifferentialControl::SetDifferentialControl(
00175       double left_p,
00176       double left_i,
00177       double left_d,
00178       double left_feedfwd,
00179       double left_stic,
00180       double left_int_lim,
00181       double right_p,
00182       double right_i,
00183       double right_d,
00184       double right_feedfwd,
00185       double right_stic,
00186       double right_int_lim)
00187       : CmdMessage()
00188   {
00189     setPayloadLength(PAYLOAD_LEN);
00190 
00191     ftob(getPayloadPointer(LEFT_P), 2, left_p, 100);
00192     ftob(getPayloadPointer(LEFT_I), 2, left_i, 100);
00193     ftob(getPayloadPointer(LEFT_D), 2, left_d, 100);
00194     ftob(getPayloadPointer(LEFT_FEEDFWD), 2, left_feedfwd, 100);
00195     ftob(getPayloadPointer(LEFT_STIC), 2, left_stic, 100);
00196     ftob(getPayloadPointer(LEFT_INT_LIM), 2, left_int_lim, 100);
00197 
00198     ftob(getPayloadPointer(RIGHT_P), 2, right_p, 100);
00199     ftob(getPayloadPointer(RIGHT_I), 2, right_i, 100);
00200     ftob(getPayloadPointer(RIGHT_D), 2, right_d, 100);
00201     ftob(getPayloadPointer(RIGHT_FEEDFWD), 2, right_feedfwd, 100);
00202     ftob(getPayloadPointer(RIGHT_STIC), 2, right_stic, 100);
00203     ftob(getPayloadPointer(RIGHT_INT_LIM), 2, right_int_lim, 100);
00204 
00205     setType(SET_DIFF_CTRL_CONSTS);
00206     makeValid();
00207   }
00208 
00209   SetDifferentialControl::SetDifferentialControl(const SetDifferentialControl &other)
00210       : CmdMessage(other)
00211   {
00212   }
00213 
00214 
00215   SetDifferentialOutput::SetDifferentialOutput(double left, double right) : CmdMessage()
00216   {
00217     setPayloadLength(PAYLOAD_LEN);
00218     ftob(getPayloadPointer(LEFT), 2, left, 100);
00219     ftob(getPayloadPointer(RIGHT), 2, right, 100);
00220 
00221     setType(SET_DIFF_WHEEL_SETPTS);
00222     makeValid();
00223   }
00224 
00225   SetDifferentialOutput::SetDifferentialOutput(const SetDifferentialOutput &other)
00226       : CmdMessage(other)
00227   {
00228   }
00229 
00230 
00231   SetDifferentialSpeed::SetDifferentialSpeed(double left_speed, double right_speed,
00232       double left_accel, double right_accel)
00233       : CmdMessage()
00234   {
00235     setPayloadLength(PAYLOAD_LEN);
00236 
00237     ftob(getPayloadPointer(LEFT_SPEED), 2, left_speed, 100);
00238     ftob(getPayloadPointer(LEFT_ACCEL), 2, left_accel, 100);
00239     ftob(getPayloadPointer(RIGHT_SPEED), 2, right_speed, 100);
00240     ftob(getPayloadPointer(RIGHT_ACCEL), 2, right_accel, 100);
00241 
00242     setType(SET_DIFF_WHEEL_SPEEDS);
00243     makeValid();
00244   }
00245 
00246   SetDifferentialSpeed::SetDifferentialSpeed(const SetDifferentialSpeed &other) : CmdMessage(other)
00247   {
00248   }
00249 
00250 
00251   SetGear::SetGear(uint8_t gear) : CmdMessage()
00252   {
00253     setPayloadLength(1);
00254     getPayloadPointer()[0] = gear;
00255     setType(SET_GEAR_SETPOINT);
00256     makeValid();
00257   }
00258 
00259   SetGear::SetGear(const SetGear &other) : CmdMessage(other)
00260   {
00261   }
00262 
00263 
00264   SetMaxAccel::SetMaxAccel(double max_fwd, double max_rev) : CmdMessage()
00265   {
00266     setPayloadLength(PAYLOAD_LEN);
00267 
00268     ftob(getPayloadPointer(MAX_FWD), 2, max_fwd, 100);
00269     ftob(getPayloadPointer(MAX_REV), 2, max_rev, 100);
00270 
00271     setType(SET_MAX_ACCEL);
00272     makeValid();
00273   }
00274 
00275   SetMaxAccel::SetMaxAccel(const SetMaxAccel &other) : CmdMessage(other)
00276   {
00277   }
00278 
00279 
00280   SetMaxSpeed::SetMaxSpeed(double max_fwd, double max_rev) : CmdMessage()
00281   {
00282     setPayloadLength(PAYLOAD_LEN);
00283 
00284     ftob(getPayloadPointer(MAX_FWD), 2, max_fwd, 100);
00285     ftob(getPayloadPointer(MAX_REV), 2, max_rev, 100);
00286 
00287     setType(SET_MAX_SPEED);
00288     makeValid();
00289   }
00290 
00291   SetMaxSpeed::SetMaxSpeed(const SetMaxSpeed &other) : CmdMessage(other)
00292   {
00293   }
00294 
00295 
00296   SetPlatformName::SetPlatformName(const char *name) : CmdMessage()
00297   {
00298     size_t cpy_len = strlen(name);
00299     size_t max_len = MAX_MSG_LENGTH - HEADER_LENGTH - CRC_LENGTH - 1 /* for size field */;
00300     if (cpy_len > max_len) { cpy_len = max_len; }
00301 
00302     setPayloadLength(cpy_len + 1);
00303     getPayloadPointer()[0] = cpy_len;
00304     memcpy(getPayloadPointer(1), name, cpy_len);
00305 
00306     setType(SET_PLATFORM_NAME);
00307 
00308     makeValid();
00309   }
00310 
00311   SetPlatformName::SetPlatformName(const SetPlatformName &other) : CmdMessage(other)
00312   {
00313   }
00314 
00315 
00316   SetPlatformTime::SetPlatformTime(uint32_t time) : CmdMessage()
00317   {
00318     setPayloadLength(4);
00319     utob(getPayloadPointer(), 4, time);
00320     setType(SET_PLATFORM_TIME);
00321     makeValid();
00322   }
00323 
00324   SetPlatformTime::SetPlatformTime(const SetPlatformTime &other) : CmdMessage(other)
00325   {
00326   }
00327 
00328 
00329   SetSafetySystem::SetSafetySystem(uint16_t flags) : CmdMessage()
00330   {
00331     setPayloadLength(2);
00332     utob(getPayloadPointer(), 2, flags);
00333     setType(SET_SAFETY_SYSTEM);
00334     makeValid();
00335   }
00336 
00337   SetSafetySystem::SetSafetySystem(const SetSafetySystem &other) : CmdMessage(other)
00338   {
00339   }
00340 
00341 
00342   SetTurn::SetTurn(double trans, double rad, double accel) : CmdMessage()
00343   {
00344     setPayloadLength(PAYLOAD_LEN);
00345 
00346     ftob(getPayloadPointer(TRANSLATIONAL), 2, trans, 100);
00347     ftob(getPayloadPointer(TURN_RADIUS), 2, rad, 100);
00348     ftob(getPayloadPointer(TRANS_ACCEL), 2, accel, 100);
00349 
00350     setType(SET_TURN_SETPT);
00351     makeValid();
00352   }
00353 
00354   SetTurn::SetTurn(const SetTurn &other) : CmdMessage(other)
00355   {
00356   }
00357 
00358 
00359   SetVelocity::SetVelocity(double trans, double rot, double accel) : CmdMessage()
00360   {
00361     setPayloadLength(PAYLOAD_LEN);
00362 
00363     ftob(getPayloadPointer(TRANSLATIONAL), 2, trans, 100);
00364     ftob(getPayloadPointer(ROTATIONAL), 2, rot, 100);
00365     ftob(getPayloadPointer(TRANS_ACCEL), 2, accel, 100);
00366 
00367     setType(SET_VELOCITY_SETPT);
00368     makeValid();
00369   }
00370 
00371   SetVelocity::SetVelocity(const SetVelocity &other) : CmdMessage(other)
00372   {
00373   }
00374 
00375 
00376 }; // namespace clearpath
00377 


husky_base
Author(s): Mike Purvis , Paul Bovbel
autogenerated on Sat Jun 8 2019 18:26:01