/usr/include/Aria/ArSonarMTX.h is in libaria-dev 2.8.0+repack-1ubuntu2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 | /*
Adept MobileRobots Robotics Interface for Applications (ARIA)
Copyright (C) 2004, 2005 ActivMedia Robotics LLC
Copyright (C) 2006, 2007, 2008, 2009, 2010 MobileRobots Inc.
Copyright (C) 2011, 2012, 2013 Adept Technology
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
If you wish to redistribute ARIA under different terms, contact
Adept MobileRobots for information about a commercial version of ARIA at
robots@mobilerobots.com or
Adept MobileRobots, 10 Columbia Drive, Amherst, NH 03031; +1-603-881-7960
*/
#ifndef ARSONARMTX_H
#define ARSONARMTX_H
#include "ariaTypedefs.h"
#include "ArRangeDevice.h"
#include "ArFunctor.h"
#include "ArRobot.h"
#include "ArRobotPacket.h"
// Packets are in the format of
// 2 bytes header (0xfa 0xfb)
// 1 byte length
// 1 byte command
// xx bytes command specific / args
// 2 bytes checksum
//
// Alive packet
// request - 0xfa 0xfb 0x03 0x00 0x00 0x00
// response - 0xfa 0xfb 0x03 0x00 0x00 0x00
//
// Start Scan packet
// request - 0xfa 0xfb 0x03 0x01 0x00 0x01
// reading - 0xfa 0xfb 0x07 0x01 0x0b 0x00 0xff 0xff 0x02 0xf5
//
// Stop Scan packet
// request - 0xfa 0xfb 0x03 0x02 0x00 0x02
//
// Reset packet
// request - 0xfa 0xfb 0x03 0x03 0x00 0x03
//
// Get Number of Transducers (12 here)
// request - 0xfa 0xfb 0x03 0x11 0x00 0x11
// response - 0xfa 0xfb 0x04 0x11 0x0c 0x11 0x0c
//
// Get Echo Sample Size packet (also called max range)
// request - 0xfa 0xfb 0x04 0x14 0x00 0x14 0x00
// response - 0xfa 0xfb 0x06 0x14 0x01 0x00 0x01 0x14 0x01
// note: byte 5 (0x01) is transducer # (starts at 0)
// note: bytes 6 & 7 are value
//
// Get Gain packet
// request - 0xfa 0xfb 0x04 0x17 0x00 0x17 0x00
// response - 0xfa 0xfb 0x05 0x17 0x00 0x05 0x17 0x04
// note: byte 5 (0x01) is transducer # (starts at 0)
// note: bytes 6 is gain
//
// Get Mask
// request - 0xfa 0xfb 0x03 0x12 0x00 0x12
// response - 0xfa 0xfb 0x05 0x12 0xff 0x0f 0x12 0xf0
//
// Get Number of Thresholds
// request - 0xfa 0xfb 0x03 0x18 0x00 0x18
// response - 0xfa 0xfb 0x04 0x18 0x03 0x18 0x03
//
// Get Sonar Delay
// request - 0xfa 0xfb 0x03 0x13 0x00 0x13
// response - 0xfa 0xfb 0x04 0x13 0x01 0x13 0x01
//
// Get Thresholds
// request - 0xfa 0xfb 0x04 0x19 0x00 0x19 0x00
// response - 0xfa 0xfb 0x0a 0x19 0x00 0xb8 0x0b 0xdc 0x05 0xd0 0x07 0x7d 0x17
// note: byte 5 (0x00) is transducer #
//
// Get Version
// request - 0xfa 0xfb 0x03 0x10 0x00 0x10
// response - 0xfa 0xfb 0x04 0x10 0x01 0x10 0x01
//
// Set Echo Sample Size (also set max range)
// request - 0xfa 0xfb 0x06 0x24 0x00 0x02 0x00 0x26 0x00
// note: byte 5 (0x00) is transducer #
// note: there is no response - use get echo sample size to test
//
// Set Gain
// request - 0xfa 0xfb 0x05 0x27 0x00 0x05 0x27 0x05
// note: byte 5 (0x00) is transducer #, gain is byte 6
// note: there is no response - use get gain to test
//
// Set Mask
// request - 0xfa 0xfb 0x05 0x22 0xc0 0x81 0x22 0x41
// note: byte 5 & 6 are the masks
// note: there is no response - use get mask test
//
// Set Sonar Delay
// request - 0xfa 0xfb 0x04 0x23 0xd9 0x23 0xd9
// note: there is no response - use get sonar delay to test
//
// Set Thresholds
// request - 0xfa 0xfb 0x0a 0x29 0x00 0x38 0xae 0x06 0xaf 0xc9 0x63 0x31 0xc0
// note: byte 5 is transducer number
// note: there is no response - use get thresholds to test
//
/// Receives sonar data from an MTX robot
/// Use ArSonarConnector to establish the connection and create and initiate the ArSonarMTX thread.
/// @since 2.8.0
class ArSonarMTX : public ArASyncTask
{
public:
/// Constructor
AREXPORT ArSonarMTX(
int sonarBoardNum = 0,
const char * name = "MTXSonar", ArDeviceConnection *conn = NULL,
ArRobot *robot = NULL);
/// Destructor
AREXPORT virtual ~ArSonarMTX();
/// Sets the robot pointer, also attaches its process function to the
/// robot as a Sensor Interpretation task.
AREXPORT virtual void setRobot(ArRobot *robot);
AREXPORT int getBoardNum(void)
{ return myBoardNum; }
/// Sets the device this instance receives packets from
AREXPORT void setDeviceConnection(ArDeviceConnection *conn);
/// Gets the device this instance receives packets from
AREXPORT ArDeviceConnection *getDeviceConnection(void);
/// Very Internal call that gets the packet sender, shouldn't be used
ArRobotPacketSender *getPacketSender(void)
{ return mySender; }
/// Very Internal call that gets the packet sender, shouldn't be used
ArRobotPacketReceiver *getPacketReceiver(void)
{ return myReceiver; }
AREXPORT virtual bool blockingConnect(bool sendTracking, bool recvTracking);
/// Connect used for debug replay
AREXPORT virtual bool fakeConnect();
AREXPORT virtual bool disconnect(void);
AREXPORT virtual bool isConnected(void) { return myIsConnected; }
AREXPORT virtual bool isTryingToConnect (void)
{
if (myStartConnect)
return true;
else if (myTryingToConnect)
return true;
else
return false;
}
/// Logs the information about the sensor
AREXPORT void log(void);
/// Lock this device
AREXPORT virtual int lockDevice() { return(myDeviceMutex.lock());}
/// Try to lock this device
AREXPORT virtual int tryLockDevice() {return(myDeviceMutex.tryLock());}
/// Unlock this device
AREXPORT virtual int unlockDevice() {return(myDeviceMutex.unlock());}
AREXPORT virtual const char *getName(void) const;
AREXPORT virtual const char *getNameWithBoard(void) const;
AREXPORT void setInfoLogLevel(ArLog::LogLevel infoLogLevel)
{ myInfoLogLevel = infoLogLevel; }
/// Gets the default port type for the sonar
const char *getDefaultPortType(void) { return myDefaultPortType.c_str(); }
/// Gets the default port type for the sonar
const char *getDefaultTcpPort(void) { return myDefaultTcpPort.c_str(); }
/// Sets the numter of seconds without a response until connection assumed lost
AREXPORT virtual void setConnectionTimeoutSeconds(double seconds)
{ ArLog::log(ArLog::Normal,
"%s::setConnectionTimeoutSeconds: Setting timeout to %g secs",
getName(), seconds);
myLastReading.setToNow(); myTimeoutSeconds = seconds; }
/// Gets the number of seconds without a response until connection assumed lost
AREXPORT virtual double getConnectionTimeoutSeconds(void)
{return myTimeoutSeconds; }
/// check for lost connections
AREXPORT bool checkLostConnection(void);
/// disconnect
AREXPORT void disconnectOnError(void);
/// Gets the time data was last receieved
ArTime getLastReadingTime(void) { return myLastReading; }
/// Gets the number of sonar readings received in the last second
AREXPORT int getReadingCount(void);
// Function called in sensorInterp to indicate that a
// reading was received
AREXPORT virtual void internalGotReading(void);
AREXPORT bool sendAlive();
AREXPORT bool sendReset();
AREXPORT bool sendStart();
AREXPORT bool sendStop();
AREXPORT bool sendGetTransducerCount();
AREXPORT bool sendGetGain(unsigned char transducerNumber);
AREXPORT bool sendSetGain(unsigned char transducerNumber, unsigned char gain);
AREXPORT bool sendGetMaxRange(unsigned char transducerNumber);
AREXPORT bool sendSetMaxRange(unsigned char transducerNumber, int echoSampleSize);
AREXPORT bool sendGetThresholds(unsigned char transducerNumber);
AREXPORT bool sendSetThresholds(unsigned char transducerNumber, int thres);
AREXPORT bool sendGetNumThresholdRanges();
/*
AREXPORT bool sendGetNoiseDelta(unsigned char transducerNumber);
AREXPORT bool sendSetNoiseDelta(unsigned char transducerNumber, int noiseDelta);
*/
AREXPORT bool sendGetDelay();
AREXPORT bool sendSetDelay(unsigned char delay);
AREXPORT bool sendSetMask(unsigned char maskLsb, unsigned char maskMsb);
AREXPORT bool sendGetMask();
AREXPORT bool validateTransducers();
AREXPORT bool validateGain();
AREXPORT bool validateDelay();
AREXPORT bool validateThresholds();
AREXPORT bool validateMaxRange();
/*
AREXPORT bool validateNoiseDelta();
*/
AREXPORT bool validateNumThresholdRanges();
AREXPORT bool requestFirmwareVersion();
AREXPORT bool queryFirmwareVersion();
/// Adds a callback for when disconnection happens because of an error
void addDisconnectOnErrorCB(ArFunctor *functor,
int position = 51)
{ myDisconnectOnErrorCBList.addCallback(functor, position); }
/// Removes a callback for when disconnection happens because of an error
void remDisconnectOnErrorCB(ArFunctor *functor)
{ myDisconnectOnErrorCBList.remCallback(functor); }
/// Number of Transducers from board query
int getNumTransducers(void) const
{ return myNumTransducers; }
/// Number of Configured Transducers
int getNumConfiguredTransducers(void) const
{ return myNumConfiguredTransducers; }
/// Board Delay
int getBoardDelay(void) const
{ return myBoardDelay; }
///
int getBoardGain(void) const
{ return myBoardGain; }
///
/*
int getBoardNoiseDelta(void) const
{ return myBoardNoiseDelta; }
*/
///
int getBoardDetectionThreshold(void) const
{ return myBoardDetectionThreshold; }
///
int getBoardMaxRange(void) const
{ return myBoardMaxRange; }
bool getBoardUseForAutonomousDriving(void) const
{ return myBoardUseForAutonomousDriving; }
///
int getUnitMapping(int unit) const
{
std::map<int, std::map<int, int> >::const_iterator iter =
mySonarMap.find(unit);
if (iter == mySonarMap.end())
return -1;
else {
std::map<int, int>unitMap = iter->second;
return unitMap[SONAR_MAPPING];
} }
///
int getUnitX(int unit) const
{
std::map<int, std::map<int, int> >::const_iterator iter =
mySonarMap.find(unit);
if (iter == mySonarMap.end())
return -1;
else {
std::map<int, int>unitMap = iter->second;
return unitMap[SONAR_X];
} }
///
int getUnitY(int unit) const
{
std::map<int, std::map<int, int> >::const_iterator iter =
mySonarMap.find(unit);
if (iter == mySonarMap.end())
return -1;
else {
std::map<int, int>unitMap = iter->second;
return unitMap[SONAR_Y];
} }
///
int getUnitTh(int unit) const
{
std::map<int, std::map<int, int> >::const_iterator iter =
mySonarMap.find(unit);
if (iter == mySonarMap.end())
return -1;
else {
std::map<int, int>unitMap = iter->second;
return unitMap[SONAR_TH];
} }
///
int getUnitGain(int unit) const
{
std::map<int, std::map<int, int> >::const_iterator iter =
mySonarMap.find(unit);
if (iter == mySonarMap.end())
return -1;
else {
std::map<int, int>unitMap = iter->second;
return unitMap[SONAR_GAIN];
} }
///
int getUnitDetectionThres(int unit) const
{
std::map<int, std::map<int, int> >::const_iterator iter =
mySonarMap.find(unit);
if (iter == mySonarMap.end())
return -1;
else {
std::map<int, int>unitMap = iter->second;
return unitMap[SONAR_DETECTION_THRES];
} }
///
/*
int getUnitNoiseDelta(int unit) const
{
std::map<int, std::map<int, int> >::const_iterator iter =
mySonarMap.find(unit);
if (iter == mySonarMap.end())
return -1;
else {
std::map<int, int>unitMap = iter->second;
return unitMap[SONAR_NOISE_DELTA];
} }
*/
#if 0
///
int getUnitThresClose(int unit) const
{
std::map<int, std::map<int, int> >::const_iterator iter =
mySonarMap.find(unit);
if (iter == mySonarMap.end())
return -1;
else {
std::map<int, int>unitMap = iter->second;
return unitMap[SONAR_THRES_CLOSE];
} }
///
int getUnitThresMed(int unit) const
{
std::map<int, std::map<int, int> >::const_iterator iter =
mySonarMap.find(unit);
if (iter == mySonarMap.end())
return -1;
else {
std::map<int, int>unitMap = iter->second;
return unitMap[SONAR_THRES_MED];
} }
///
int getUnitThresFar(int unit) const
{
std::map<int, std::map<int, int> >::const_iterator iter =
mySonarMap.find(unit);
if (iter == mySonarMap.end())
return -1;
else {
std::map<int, int>unitMap = iter->second;
return unitMap[SONAR_THRES_FAR];
} }
#endif
///
int getUnitLastReading(int unit) const
{
std::map<int, std::map<int, int> >::const_iterator iter =
mySonarMap.find(unit);
if (iter == mySonarMap.end())
return -1;
else {
std::map<int, int>unitMap = iter->second;
return unitMap[SONAR_LAST_READING];
} }
int getFirmwareVersion(void) const
{ return myFirmwareVersion; }
bool turnOnTransducers();
bool turnOffTransducers();
bool disableForAutonomousDriving();
enum Headers {
HEADER1=0xfa,
//HEADER2=0xfb
HEADER2=0xf5
};
protected:
ArDeviceConnection *myConn;
std::string myName;
char myNameWithBoard[100];
std::string myDefaultPortType;
std::string myDefaultTcpPort;
double myTimeoutSeconds;
bool myRobotRunningAndConnected;
bool myTransducersAreOn;
ArTime myLastReading;
// packet count
time_t myTimeLastReading;
int myReadingCurrentCount;
int myReadingCount;
ArCallbackList myDisconnectOnErrorCBList;
ArRobot *myRobot;
ArFunctorC<ArSonarMTX> myProcessCB;
AREXPORT virtual void sonarSetName(const char *name);
AREXPORT virtual void * runThread(void *arg);
void sensorInterp(void);
void failedToConnect(void);
void clear(void);
bool myIsConnected;
bool myTryingToConnect;
bool myStartConnect;
int myBoardNum;
int myNumTransducers;
int myNumConfiguredTransducers;
unsigned char myVersion;
//unsigned char mySonarDelay;
bool myWarnedAboutExtraSonar;
unsigned int myBoardDelay;
unsigned int myBoardGain;
/*
unsigned int myBoardNoiseDelta;
*/
unsigned int myBoardDetectionThreshold;
unsigned int myBoardMaxRange;
bool myBoardUseForAutonomousDriving;
unsigned char myTransducerMaskLSB;
unsigned char myTransducerMaskMSB;
unsigned char myAutonomousDrivingTransducerMaskLSB;
unsigned char myAutonomousDrivingTransducerMaskMSB;
// first index is transducer reletive to this board
// second index is defined below
std::map<int, std::map<int, int> > mySonarMap;
enum SonarInfo
{
SONAR_IS_CONFIGURED,
SONAR_MAPPING,
SONAR_X,
SONAR_Y,
SONAR_TH,
SONAR_GAIN,
/*
SONAR_NOISE_DELTA,
*/
SONAR_DETECTION_THRES,
SONAR_MAX_RANGE,
SONAR_USE_FOR_AUTONOMOUS_DRIVING,
SONAR_LAST_READING
};
enum Sizes {
maxTransducers=16
};
enum Commands {
ALIVE=0x00,
START_SCAN=0x01,
STOP_SCAN=0x02,
RESET=0x03,
TAKE_SELF_ECHO=0x04,
GET_VERSION=0x10,
GET_NUM_TRANDUCERS=0x11,
GET_TRANSDUCER_MASK=0x12,
SET_TRANSDUCER_MASK=0x22,
GET_SONAR_DELAY=0x13,
SET_SONAR_DELAY=0x23,
GET_ECHO_SAMPLE_SIZE=0x14,
SET_ECHO_SAMPLE_SIZE=0x24,
GET_GAIN=0x17,
SET_GAIN=0x27,
NUM_THRESHOLD_RANGES=0x18,
GET_THRESHOLDS=0x19,
SET_THRESHOLDS=0x29,
GET_NOISE_DELTA=0x1A,
SET_NOISE_DELTA=0x2A
};
bool mySendTracking;
bool myRecvTracking;
ArLog::LogLevel myLogLevel;
//ArSonarMTXPacketReceiver myReceiver;
ArRobotPacketReceiver *myReceiver;
ArRobotPacketSender *mySender;
ArMutex myPacketsMutex;
ArMutex myDataMutex;
ArMutex myDeviceMutex;
ArLog::LogLevel myInfoLogLevel;
//std::list<ArSonarMTXPacket *> myPackets;
std::list<ArRobotPacket *> myPackets;
int myFirmwareVersion;
ArTime myPrevSensorIntTime;
ArFunctorC<ArSonarMTX> mySensorInterpTask;
ArRetFunctorC<bool, ArSonarMTX> myAriaExitCB;
};
#endif // ARSONARDEVICE_H
|