mbasedriver Class Reference
Inheritance diagram for mbasedriver:
Inheritance graph
Collaboration diagram for mbasedriver:
Collaboration graph

Public Member Functions

 mbasedriver (ConfigFile *cf, int section)
 
virtual int Subscribe (player_devaddr_t id)
 Subscribe. More...
 
virtual int Unsubscribe (player_devaddr_t id)
 Unsubscribe.
 
virtual void Main ()
 Main. More...
 
virtual int Setup ()
 Setup. More...
 
virtual int Shutdown ()
 Shutdown. More...
 
virtual int ProcessMessage (QueuePointer &resp_queue, player_msghdr *hdr, void *data)
 ProcessMessage. More...
 
- Public Member Functions inherited from Driver
bool HasSubscriptions ()
 
virtual void Publish (player_devaddr_t addr, QueuePointer &queue, uint8_t type, uint8_t subtype, void *src=NULL, size_t deprecated=0, double *timestamp=NULL, bool copy=true)
 Publish a message via one of this driver's interfaces. More...
 
virtual void Publish (player_devaddr_t addr, uint8_t type, uint8_t subtype, void *src=NULL, size_t deprecated=0, double *timestamp=NULL, bool copy=true)
 Publish a message via one of this driver's interfaces. More...
 
virtual void Publish (QueuePointer &queue, player_msghdr_t *hdr, void *src, bool copy=true)
 Publish a message via one of this driver's interfaces. More...
 
virtual void Publish (player_msghdr_t *hdr, void *src, bool copy=true)
 Publish a message via one of this driver's interfaces. More...
 
 Driver (ConfigFile *cf, int section, bool overwrite_cmds, size_t queue_maxlen, int interf)
 Constructor for single-interface drivers. More...
 
 Driver (ConfigFile *cf, int section, bool overwrite_cmds=true, size_t queue_maxlen=PLAYER_MSGQUEUE_DEFAULT_MAXLEN)
 Constructor for multiple-interface drivers. More...
 
virtual ~Driver ()
 Destructor.
 
int GetError ()
 Get last error value. More...
 
virtual int Subscribe (QueuePointer &, player_devaddr_t)
 Subscribe to this driver. More...
 
virtual int Unsubscribe (QueuePointer &, player_devaddr_t)
 Unsubscribe from this driver. More...
 
virtual int Terminate ()
 Terminate the driver. More...
 
void ProcessMessages (int maxmsgs)
 Process pending messages. More...
 
void ProcessMessages (void)
 Process pending messages. More...
 
virtual void Update ()
 Update non-threaded drivers. More...
 
virtual int ProcessInternalMessages (QueuePointer &resp_queue, player_msghdr *hdr, void *data)
 Internal message handler. More...
 
virtual bool RegisterProperty (const char *key, Property *property, ConfigFile *cf, int section)
 Property registration. More...
 
virtual bool RegisterProperty (Property *property, ConfigFile *cf, int section)
 Property registration. More...
 

Private Member Functions

int Connect ()
 Connect. More...
 
int Disconnect ()
 Disconnect. More...
 
void ResetRawPositions ()
 ResetRawPositions. More...
 
void ToggleMotorPower (unsigned char val)
 ToggleMotorPower. More...
 
void ToggleAIn (unsigned char val)
 ToggleAIn. More...
 
void ToggleSonar (unsigned char val)
 ToggleSonar. More...
 
int HandleConfig (QueuePointer &resp_queue, player_msghdr *hdr, void *data)
 HandleConfig. More...
 
int HandleCommand (player_msghdr *hdr, void *data)
 HandleCommand. More...
 
void HandlePositionCommand (player_position2d_cmd_vel_t position_cmd)
 HandlePositionCommand. More...
 
void PublishAllData ()
 PublishAllData.
 
void PublishPosition2D ()
 PublishPosition2D.
 
void PublishPower ()
 PublishPower.
 
void PublishAIn ()
 PublishAIn.
 
void PublishIR ()
 PublishIR.
 
void PublishSonar ()
 PublishSonar.
 
void StartThreads ()
 StrarThreads. More...
 
void StopThreads ()
 StopThreads.
 
void Send (mbasedriverPacket *packet)
 Send. More...
 
void SendThread ()
 SendThread.
 
void ReceiveThread ()
 ReceiveThread. More...
 
int getms ()
 getms More...
 

Static Private Member Functions

static void * SendThreadDummy (void *driver)
 SedThreadDummy.
 
static void * ReceiveThreadDummy (void *driver)
 ReceiveThreadDummy.
 

Private Attributes

int mcount
 
player_mbasedriver_data_t mbasedriver_data
 
player_devaddr_t position_id
 
player_devaddr_t power_id
 
player_devaddr_t aio_id
 
player_devaddr_t ir_id
 
player_devaddr_t sonar_id
 
int position_subscriptions
 
int aio_ir_subscriptions
 
int sonar_subscriptions
 
mbasedriverMotorPacketmotor_packet
 
pthread_mutex_t motor_packet_mutex
 
int read_fd
 
int write_fd
 
const char * psos_serial_port
 
player_position2d_cmd_vel_t last_position_cmd
 
player_position2d_cmd_car_t last_car_cmd
 
std::queue< mbasedriverPacket * > send_queue
 
pthread_mutex_t send_queue_mutex
 
pthread_cond_t send_queue_cond
 
pthread_t send_thread
 
pthread_t receive_thread
 
bool print_all_packets
 
int param_idx
 
int motor_max_speed
 
int motor_max_turnspeed
 
int motor_trans_acel
 
int motor_rot_acel
 
int trans_ant
 
int rot_ant
 
int16_t pid_p
 
int16_t pid_v
 
int16_t pid_i
 
int16_t driffactor
 
int16_t dist_ejes
 
int16_t diametro
 
bool debug_usuario
 
bool ir_analog
 

Additional Inherited Members

- Public Attributes inherited from Driver
QueuePointer ret_queue
 Last requester's queue. More...
 
player_devaddr_t device_addr
 Default device address (single-interface drivers)
 
int entries
 Total number of entries in the device table using this driver. More...
 
bool alwayson
 Always on flag. More...
 
QueuePointer InQueue
 Queue for all incoming messages for this driver.
 
- Protected Member Functions inherited from Driver
int AddInterface (player_devaddr_t addr)
 Add an interface. More...
 
int AddInterface (player_devaddr_t *addr, ConfigFile *cf, int section, int code, const char *key=NULL)
 Add an interface. More...
 
void SetError (int code)
 Set/reset error code.
 
virtual bool Wait (double TimeOut=0.0)
 Wait for new data to arrive on the driver's queue. More...
 
int AddFileWatch (int fd, bool ReadWatch=true, bool WriteWatch=false, bool ExceptWatch=true)
 Wake up the driver if the specified event occurs on the file descriptor.
 
int RemoveFileWatch (int fd, bool ReadWatch=true, bool WriteWatch=false, bool ExceptWatch=true)
 Remove a previously added watch, call with the same arguments as when adding the watch.
 
virtual void Lock (void)
 Lock access between the server and driver threads. More...
 
virtual void Unlock (void)
 Unlock access to driver internals. More...
 
virtual void SubscriptionLock (void)
 Lock to protect the subscription count for the driver.
 
virtual void SubscriptionUnlock (void)
 Unlock to protect the subscription count for the driver. More...
 
virtual void TestCancel ()
 enable thread cancellation and test for cancellation More...
 

Constructor & Destructor Documentation

◆ mbasedriver()

mbasedriver::mbasedriver ( ConfigFile cf,
int  section 
)
  • Constructor of the driver from configuration entry

Leyendo los datos del fichero cfg y asignando valores a los parámetros correspondientes.

References ConfigFile::ReadDeviceAddr().

Here is the call graph for this function:

Member Function Documentation

◆ Connect()

int mbasedriver::Connect ( )
private

Connect.

  • Establishes connection and starts threads

Envío mensajes de configuración a la placa de control IOM

  • OPEN_CONTROLLER
  • STOP
  • SET_TRANS_ACEL, si no se envía al menos una vez la plataforma no se moverá
  • SET_ROT_ACEL -> No se envia porque el IOM no lo reconoce

if(this->motor_rot_acel > 0) { accel_packet = new mbasedriverPacket(); accel_command[0] = (command_e)set_rot_acel; accel_command[1] = (argtype_e)argint; accel_command[2] = this->motor_rot_acel & 0x00FF; accel_command[3] = (this->motor_rot_acel & 0xFF00) >> 8; if(debug_send) printf("__ build SET_ROT_ACEL\n"); accel_packet->Build(accel_command, 4); this->Send(accel_packet); }

  • SET_DRIFFACTOR
  • SET_ROBOT_WIDTH
  • SET_ROBOT_WHEEL
  • SET_PID_P
  • SET_PID_I
  • SET_PID_D

References mbasedriverPacket::Build(), mbasedriverPacket::Receive(), mbasedriverPacket::Send(), and Send().

Here is the call graph for this function:

◆ Disconnect()

int mbasedriver::Disconnect ( )
private

Disconnect.

  • Is theoretically able to disconnect, but we don't do that

References mbasedriverPacket::Build(), mbasedriverPacket::Send(), and StopThreads().

Here is the call graph for this function:

◆ getms()

int mbasedriver::getms ( )
private

getms

  • function to get the time in ms

Referenced by HandlePositionCommand().

◆ HandleCommand()

int mbasedriver::HandleCommand ( player_msghdr hdr,
void *  data 
)
private

HandleCommand.

  • Switchboard for robot commands, called from ProcessMessage
  • Note that these don't perform a response...

References HandlePositionCommand(), Message::MatchMessage(), PLAYER_MSGTYPE_CMD, and PLAYER_POSITION2D_CMD_VEL.

Referenced by ProcessMessage().

Here is the call graph for this function:

◆ HandleConfig()

◆ HandlePositionCommand()

void mbasedriver::HandlePositionCommand ( player_position2d_cmd_vel_t  position_cmd)
private

HandlePositionCommand.

  • Handles one Player command detailing a velocity

References mbasedriverPacket::Build(), getms(), player_pose2d::pa, player_pose2d::px, Send(), and player_position2d_cmd_vel::vel.

Referenced by HandleCommand().

Here is the call graph for this function:

◆ Main()

void mbasedriver::Main ( void  )
virtual

Main.

  • Main entry point for the worker thread

if(!last_position_subscrcount && this->position_subscriptions) { this->ToggleMotorPower(0); this->ResetRawPositions(); } else if(last_position_subscrcount && !(this->position_subscriptions)) { enable motor power this->ToggleMotorPower(1); }

if(!last_aio_ir_subscriptions && this->aio_ir_subscriptions) this->ToggleAIn(1); else if(last_aio_ir_subscriptions && !(this->aio_ir_subscriptions)) this->ToggleAIn(0);

  if(!last_sonar_subscriptions && this->sonar_subscriptions)
   this->ToggleSonar(1);

else if(last_sonar_subscriptions && !(this->sonar_subscriptions)) this->ToggleSonar(0);

References MessageQueue::Empty(), Driver::InQueue, and Driver::ProcessMessages().

Here is the call graph for this function:

◆ ProcessMessage()

int mbasedriver::ProcessMessage ( QueuePointer resp_queue,
player_msghdr hdr,
void *  data 
)
virtual

ProcessMessage.

  • Gets called from ProcessMessages to handle one message

Reimplemented from Driver.

References HandleCommand(), HandleConfig(), PLAYER_MSGTYPE_CMD, PLAYER_MSGTYPE_REQ, and player_msghdr::type.

Here is the call graph for this function:

◆ ReceiveThread()

void mbasedriver::ReceiveThread ( )
private

◆ ResetRawPositions()

void mbasedriver::ResetRawPositions ( )
private

ResetRawPositions.

  • Tells the robot to reset the odometry center

References mbasedriverPacket::Build(), and Send().

Here is the call graph for this function:

◆ Send()

void mbasedriver::Send ( mbasedriverPacket packet)
private

◆ Setup()

int mbasedriver::Setup ( void  )
virtual

Setup.

  • Called by player when the driver is asked to connect

Reimplemented from Driver.

◆ Shutdown()

int mbasedriver::Shutdown ( void  )
virtual

Shutdown.

  • Called by player when the driver is supposed to disconnect

Reimplemented from Driver.

◆ StartThreads()

void mbasedriver::StartThreads ( )
private

StrarThreads.

  • These call the supplied Driver::StartThread() method, but adds additional threads

References ReceiveThreadDummy(), and SendThreadDummy().

Here is the call graph for this function:

◆ Subscribe()

int mbasedriver::Subscribe ( player_devaddr_t  id)
virtual

Subscribe.

  • Subscription is overridden to add a subscription count of our own

Reimplemented from Driver.

References Device::MatchDeviceAddress(), Driver::Subscribe(), ToggleAIn(), ToggleMotorPower(), and ToggleSonar().

Here is the call graph for this function:

◆ ToggleAIn()

void mbasedriver::ToggleAIn ( unsigned char  val)
private

ToggleAIn.

  • Enable or disable analog input reporting

References mbasedriverPacket::Build(), and Send().

Referenced by Subscribe(), and Unsubscribe().

Here is the call graph for this function:

◆ ToggleMotorPower()

void mbasedriver::ToggleMotorPower ( unsigned char  val)
private

ToggleMotorPower.

  • Enable or disable motors

References mbasedriverPacket::Build(), and Send().

Referenced by HandleConfig(), Subscribe(), and Unsubscribe().

Here is the call graph for this function:

◆ ToggleSonar()

void mbasedriver::ToggleSonar ( unsigned char  val)
private

ToggleSonar.

  • Enable or disable sonar reporting

References mbasedriverPacket::Build(), and Send().

Referenced by Subscribe(), and Unsubscribe().

Here is the call graph for this function:

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