47 #include <boost/function.hpp> 48 #include <boost/thread.hpp> 51 #if defined(_WIN32) && !defined(__MINGW32__) 52 typedef unsigned int uint32_t;
62 #define DEFINE_EXCEPTION(ClassName, Prefix, Message) \ 63 class ClassName : public std::exception { \ 64 void operator=(const ClassName &); \ 65 const ClassName & operator=( ClassName ); \ 69 ClassName(const char * file, const int ln, \ 70 const char * msg = Message, const int id = -1) : id_(id) { \ 71 std::stringstream ss; \ 72 ss << #ClassName " occurred at line " << ln \ 73 << " of `" << file << "`: " << Prefix << msg; \ 74 what_ = ss.str().c_str(); \ 76 virtual const char* what () const throw () { return what_; } \ 77 const int error_number() { return this->id_; } \ 80 #define RMP_THROW(ExceptionClass) \ 81 throw ExceptionClass(__FILE__, __LINE__) 83 #define RMP_THROW_MSG(ExceptionClass, Message) \ 84 throw ExceptionClass(__FILE__, __LINE__, (Message) ) 86 #define RMP_THROW_MSG_AND_ID(ExceptionClass, Message, Id) \ 87 throw ExceptionClass(__FILE__, __LINE__, (Message), (Id) ) 92 #define MAX_SEGWAYSTATUS_QUEUE_SIZE 100 206 std::queue<boost::shared_ptr<T> >
queue_;
213 : size_(size), canceled_(false) {}
217 boost::mutex::scoped_lock(mutex_);
218 return queue_.size();
222 return this->size() == 0;
226 bool dropped_element =
false;
228 boost::lock_guard<boost::mutex> lock(mutex_);
229 if (queue_.size() == size_) {
231 dropped_element =
true;
233 queue_.push(element);
235 condition_variable_.notify_one();
236 return dropped_element;
240 boost::unique_lock<boost::mutex> lock(mutex_);
241 while (queue_.empty()) {
242 condition_variable_.wait(lock);
243 if (this->canceled_) {
244 return boost::shared_ptr<T>();
247 boost::shared_ptr<T> element = queue_.front();
254 boost::lock_guard<boost::mutex> lock(mutex_);
255 this->canceled_ =
true;
257 condition_variable_.notify_all();
262 boost::lock_guard<boost::mutex> lock(mutex_);
263 this->canceled_ =
false;
265 condition_variable_.notify_all();
325 typedef boost::shared_ptr<SegwayStatus>
Ptr;
358 configureSerial(std::string port,
int baudrate = 460800);
370 configureUSBBySerial(std::string serial_number,
371 int baudrate = 460800);
383 configureUSBByDescription(std::string description,
int baudrate = 460800);
396 configureUSBByIndex(
int device_index,
int baudrate = 460800);
404 connect(
bool reset_integrators =
true);
421 moveCounts(
short int linear_counts,
short int angular_counts);
433 move(
float linear_velocity,
float angular_velocity);
462 setBalanceModeLocking(
bool state =
true);
470 resetAllIntegrators();
481 setMaxVelocityScaleFactor(
double scalar = 1.0);
492 setMaxAccelerationScaleFactor(
double scalar = 1.0);
503 setMaxTurnScaleFactor(
double scalar = 1.0);
514 setCurrentLimitScaleFactor(
double scalar = 1.0);
562 setStatusCallback(SegwayStatusCallback callback);
614 setLogMsgCallback(std::string log_level, LogMsgCallback callback);
676 setTimestampCallback(GetTimeCallback callback);
729 setExceptionCallback(ExceptionCallback callback);
757 LogMsgCallback debug_,
info_, error_;
762 void ReadContinuously_();
763 void ExecuteCallbacks_();
764 void StartReadingContinuously_();
765 void StopReadingContinuously_();
771 void ProcessPacket_(
Packet &packet);
775 DEFINE_EXCEPTION(NoHighPerformanceTimersException,
"",
"This system does not " 776 "appear to have a High Precision Event Timer (HPET) device.");
779 "SegwayRMP: ",
"Unspecified");
790 DEFINE_EXCEPTION(ConfigurationException,
"Error configuring the SegwayRMP: ",
SegwayRMPType segway_rmp_type_
boost::function< void(SegwayStatus::Ptr)> SegwayStatusCallback
boost::shared_ptr< SegwayStatus > Ptr
ExceptionCallback handle_exception_
~FiniteConcurrentSharedQueue()
boost::shared_ptr< T > dequeue()
GetTimeCallback get_time_
DEFINE_EXCEPTION(PacketRetrievalException,"Error retrieving a packet from the"" SegwayRMP: ","Unspecified")
SegwayStatusCallback status_callback_
std::queue< boost::shared_ptr< T > > queue_
bool enqueue(boost::shared_ptr< T > element)
boost::function< SegwayTime(void)> GetTimeCallback
ControllerGainSchedule controller_gain_schedule
boost::thread read_thread_
float integrated_left_wheel_position
SegwayStatus::Ptr segway_status_
boost::function< void(const std::exception &)> ExceptionCallback
float powerbase_battery_voltage
InterfaceType interface_type_
bool continuously_reading_
float integrated_right_wheel_position
FiniteConcurrentSharedQueue(size_t size=1024)
SegwayTime(uint32_t sec=0, uint32_t nsec=0)
OperationalMode operational_mode
float integrated_turn_position
boost::condition_variable condition_variable_
float integrated_forward_position
FiniteConcurrentSharedQueue< SegwayStatus > ss_queue_
boost::thread callback_execution_thread_
boost::function< void(const std::string &)> LogMsgCallback