Aria  2.8.0
ArSonarMTX Class Reference

Receives sonar data from an MTX robot Use ArSonarConnector to establish the connection and create and initiate the ArSonarMTX thread. More...

#include <ArSonarMTX.h>

Inherits ArASyncTask.

Public Types

enum  Headers { HEADER1 =0xfa, HEADER2 =0xf5 }
 
- Public Types inherited from ArThread
typedef std::map< ThreadType, ArThread * > MapType
 
enum  Status {
  STATUS_FAILED =1, STATUS_NORESOURCE, STATUS_NO_SUCH_THREAD, STATUS_INVALID,
  STATUS_JOIN_SELF, STATUS_ALREADY_DETATCHED
}
 
typedef pthread_t ThreadType
 

Public Member Functions

void addDisconnectOnErrorCB (ArFunctor *functor, int position=51)
 Adds a callback for when disconnection happens because of an error.
 
 ArSonarMTX (int sonarBoardNum=0, const char *name="MTXSonar", ArDeviceConnection *conn=NULL, ArRobot *robot=NULL)
 Constructor.
 
virtual bool blockingConnect (bool sendTracking, bool recvTracking)
 
bool checkLostConnection (void)
 check for lost connections More...
 
bool disableForAutonomousDriving ()
 
virtual bool disconnect (void)
 
void disconnectOnError (void)
 disconnect
 
virtual bool fakeConnect ()
 Connect used for debug replay.
 
int getBoardDelay (void) const
 Board Delay.
 
int getBoardDetectionThreshold (void) const
 
int getBoardGain (void) const
 
int getBoardMaxRange (void) const
 
int getBoardNum (void)
 
bool getBoardUseForAutonomousDriving (void) const
 
virtual double getConnectionTimeoutSeconds (void)
 Gets the number of seconds without a response until connection assumed lost.
 
const char * getDefaultPortType (void)
 Gets the default port type for the sonar.
 
const char * getDefaultTcpPort (void)
 Gets the default port type for the sonar.
 
ArDeviceConnectiongetDeviceConnection (void)
 Gets the device this instance receives packets from.
 
int getFirmwareVersion (void) const
 
ArTime getLastReadingTime (void)
 Gets the time data was last receieved.
 
virtual const char * getName (void) const
 
virtual const char * getNameWithBoard (void) const
 
int getNumConfiguredTransducers (void) const
 Number of Configured Transducers.
 
int getNumTransducers (void) const
 Number of Transducers from board query.
 
ArRobotPacketReceivergetPacketReceiver (void)
 Very Internal call that gets the packet sender, shouldn't be used.
 
ArRobotPacketSendergetPacketSender (void)
 Very Internal call that gets the packet sender, shouldn't be used.
 
int getReadingCount (void)
 Gets the number of sonar readings received in the last second.
 
int getUnitDetectionThres (int unit) const
 
int getUnitGain (int unit) const
 
int getUnitLastReading (int unit) const
 
int getUnitMapping (int unit) const
 
int getUnitTh (int unit) const
 
int getUnitX (int unit) const
 
int getUnitY (int unit) const
 
virtual void internalGotReading (void)
 
virtual bool isConnected (void)
 
virtual bool isTryingToConnect (void)
 
virtual int lockDevice ()
 Lock this device.
 
void log (void)
 Logs the information about the sensor.
 
bool queryFirmwareVersion ()
 
void remDisconnectOnErrorCB (ArFunctor *functor)
 Removes a callback for when disconnection happens because of an error.
 
bool requestFirmwareVersion ()
 
bool sendAlive ()
 
bool sendGetDelay ()
 
bool sendGetGain (unsigned char transducerNumber)
 
bool sendGetMask ()
 
bool sendGetMaxRange (unsigned char transducerNumber)
 
bool sendGetNumThresholdRanges ()
 
bool sendGetThresholds (unsigned char transducerNumber)
 
bool sendGetTransducerCount ()
 
bool sendReset ()
 
bool sendSetDelay (unsigned char delay)
 
bool sendSetGain (unsigned char transducerNumber, unsigned char gain)
 
bool sendSetMask (unsigned char maskLsb, unsigned char maskMsb)
 
bool sendSetMaxRange (unsigned char transducerNumber, int echoSampleSize)
 
bool sendSetThresholds (unsigned char transducerNumber, int thres)
 
bool sendStart ()
 
bool sendStop ()
 
virtual void setConnectionTimeoutSeconds (double seconds)
 Sets the numter of seconds without a response until connection assumed lost.
 
void setDeviceConnection (ArDeviceConnection *conn)
 Sets the device this instance receives packets from.
 
void setInfoLogLevel (ArLog::LogLevel infoLogLevel)
 
virtual void setRobot (ArRobot *robot)
 Sets the robot pointer, also attaches its process function to the robot as a Sensor Interpretation task. More...
 
virtual int tryLockDevice ()
 Try to lock this device.
 
bool turnOffTransducers ()
 
bool turnOnTransducers ()
 
virtual int unlockDevice ()
 Unlock this device.
 
bool validateDelay ()
 
bool validateGain ()
 
bool validateMaxRange ()
 
bool validateNumThresholdRanges ()
 
bool validateThresholds ()
 
bool validateTransducers ()
 
virtual ~ArSonarMTX ()
 Destructor.
 
- Public Member Functions inherited from ArASyncTask
 ArASyncTask ()
 Constructor.
 
virtual int create (bool joinable=true, bool lowerPriority=true)
 Create the task and start it going.
 
virtual const char * getThreadActivity (void)
 Gets a string that describes what the thread is doing, or NULL if it doesn't know. More...
 
virtual void run (void)
 Run without creating a new thread. More...
 
virtual void runAsync (void)
 Run in its own thread.
 
virtual void * runInThisThread (void *arg=0)
 Internal function used with system threading system to run the new thread. More...
 
virtual void stopRunning (void)
 Stop the thread.
 
virtual ~ArASyncTask ()
 Destructor.
 
- Public Member Functions inherited from ArThread
 ArThread (bool blockAllSignals=true)
 Constructor.
 
 ArThread (ThreadType thread, bool joinable, bool blockAllSignals=true)
 Constructor - starts the thread.
 
 ArThread (ArFunctor *func, bool joinable=true, bool blockAllSignals=true)
 Constructor - starts the thread.
 
virtual void cancel (void)
 Cancel the thread.
 
virtual int detach (void)
 Detatch the thread so it cant be joined.
 
bool getBlockAllSignals (void)
 Do we block all process signals at startup?
 
virtual ArFunctorgetFunc (void) const
 Get the functor that the thread runs.
 
virtual bool getJoinable (void) const
 Get the joinable status of the thread.
 
virtual ThreadType getOSThread (void) const
 Get the underlying os thread type.
 
pid_t getPID (void)
 
virtual bool getRunning (void) const
 Get the running status of the thread.
 
virtual bool getRunningWithLock (void)
 Get the running status of the thread, locking around the variable.
 
virtual const ThreadType * getThread (void) const
 Get the underlying thread type.
 
virtual const char * getThreadName (void)
 Gets the name of the thread.
 
pid_t getTID (void)
 
virtual bool isThreadFinished () const
 Returns whether the thread has been completed and can be deleted. More...
 
virtual bool isThreadStarted () const
 Returns whether the thread has been started. More...
 
virtual int join (void **ret=NULL)
 Join on the thread.
 
int lock (void)
 Lock the thread instance. More...
 
virtual void logThreadInfo (void)
 Logs the information about this thread.
 
virtual void setRunning (bool running)
 Set the running value on the thread.
 
virtual void setThreadName (const char *name)
 Sets the name of the thread.
 
virtual void threadFinished (void)
 Marks the thread as finished and logs useful debugging information. More...
 
virtual void threadStarted (void)
 Marks the thread as started and logs useful debugging information. More...
 
int tryLock (void)
 Try to lock the thread instance without blocking. More...
 
int unlock (void)
 Unlock the thread instance. More...
 
virtual ~ArThread ()
 Destructor.
 

Protected Types

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
}
 
enum  Sizes { maxTransducers =16 }
 
enum  SonarInfo {
  SONAR_IS_CONFIGURED, SONAR_MAPPING, SONAR_X, SONAR_Y,
  SONAR_TH, SONAR_GAIN, SONAR_DETECTION_THRES, SONAR_MAX_RANGE,
  SONAR_USE_FOR_AUTONOMOUS_DRIVING, SONAR_LAST_READING
}
 

Protected Member Functions

void clear (void)
 
void failedToConnect (void)
 
virtual void * runThread (void *arg)
 
void sensorInterp (void)
 
virtual void sonarSetName (const char *name)
 
- Protected Member Functions inherited from ArThread
virtual int doJoin (void **ret=NULL)
 

Protected Attributes

ArRetFunctorC< bool, ArSonarMTXmyAriaExitCB
 
unsigned char myAutonomousDrivingTransducerMaskLSB
 
unsigned char myAutonomousDrivingTransducerMaskMSB
 
unsigned int myBoardDelay
 
unsigned int myBoardDetectionThreshold
 
unsigned int myBoardGain
 
unsigned int myBoardMaxRange
 
int myBoardNum
 
bool myBoardUseForAutonomousDriving
 
ArDeviceConnectionmyConn
 
ArMutex myDataMutex
 
std::string myDefaultPortType
 
std::string myDefaultTcpPort
 
ArMutex myDeviceMutex
 
ArCallbackList myDisconnectOnErrorCBList
 
int myFirmwareVersion
 
ArLog::LogLevel myInfoLogLevel
 
bool myIsConnected
 
ArTime myLastReading
 
ArLog::LogLevel myLogLevel
 
std::string myName
 
char myNameWithBoard [100]
 
int myNumConfiguredTransducers
 
int myNumTransducers
 
std::list< ArRobotPacket * > myPackets
 
ArMutex myPacketsMutex
 
ArTime myPrevSensorIntTime
 
ArFunctorC< ArSonarMTXmyProcessCB
 
int myReadingCount
 
int myReadingCurrentCount
 
ArRobotPacketReceivermyReceiver
 
bool myRecvTracking
 
ArRobotmyRobot
 
bool myRobotRunningAndConnected
 
ArRobotPacketSendermySender
 
bool mySendTracking
 
ArFunctorC< ArSonarMTXmySensorInterpTask
 
std::map< int, std::map< int, int > > mySonarMap
 
bool myStartConnect
 
time_t myTimeLastReading
 
double myTimeoutSeconds
 
unsigned char myTransducerMaskLSB
 
unsigned char myTransducerMaskMSB
 
bool myTransducersAreOn
 
bool myTryingToConnect
 
unsigned char myVersion
 
bool myWarnedAboutExtraSonar
 
- Protected Attributes inherited from ArThread
bool myBlockAllSignals
 
bool myFinished
 
ArFunctormyFunc
 
bool myJoinable
 
ArMutex myMutex
 
std::string myName
 
pid_t myPID
 
bool myRunning
 State variable to denote when the thread should continue or exit.
 
bool myStarted
 
ArStrMap myStrMap
 
ThreadType myThread
 
pid_t myTID
 

Additional Inherited Members

- Static Public Member Functions inherited from ArThread
static void cancelAll (void)
 Cancel all threads.
 
static ArLog::LogLevel getLogLevel (void)
 Gets the logging level for thread information.
 
static ThreadType getThisOSThread (void)
 Get the underlying os thread type of this thread.
 
static const ThreadType * getThisThread (void)
 Get the underlying thread type of this thread.
 
static const char * getThisThreadName (void)
 Gets the name of the this thread.
 
static void init (void)
 Initialize the internal book keeping structures. More...
 
static void joinAll (void)
 Join on all threads.
 
static ThreadType osSelf (void)
 Returns the os self of the current thread. More...
 
static ArThreadself (void)
 Returns the instance of your own thread (the current one) More...
 
static void setLogLevel (ArLog::LogLevel level)
 Sets the logging level for thread information.
 
static void shutdown ()
 Shuts down and deletes the last remaining thread; call after joinAll.
 
static void stopAll ()
 Stop all threads.
 
static void yieldProcessor (void)
 Yield the processor to another thread.
 
- Static Protected Member Functions inherited from ArThread
static void addThreadToMap (ThreadType pt, ArThread *at)
 
static ArThreadfindThreadInMap (ThreadType t)
 
static void removeThreadFromMap (ThreadType t)
 
- Static Protected Attributes inherited from ArThread
static ArLog::LogLevel ourLogLevel = ArLog::Verbose
 
static MapType ourThreads
 
static ArMutex ourThreadsMutex
 
static std::string ourUnknownThreadName = "unknown"
 

Detailed Description

Receives sonar data from an MTX robot Use ArSonarConnector to establish the connection and create and initiate the ArSonarMTX thread.

Since
2.8.0

Member Function Documentation

◆ blockingConnect()

bool ArSonarMTX::blockingConnect ( bool  sendTracking,
bool  recvTracking 
)
virtual

MPL added these lines to help someone debug sonar ESD stuff

◆ checkLostConnection()

bool ArSonarMTX::checkLostConnection ( void  )

check for lost connections

This will check if the sonar has lost connection.

If there is no robot it is a straightforward check of last reading time against getConnectionTimeoutSeconds. If there is a robot then it will not start the check until the sonar is running and connected.

◆ setRobot()

void ArSonarMTX::setRobot ( ArRobot robot)
virtual

Sets the robot pointer, also attaches its process function to the robot as a Sensor Interpretation task.


The documentation for this class was generated from the following files: