Sigslots

Introduction

Sigslots are the primary way to handle events emitted by the kobuki driver (c.f. with the usual function callbacks with void function pointers as arguments). Rather than repeating here a verbose explanation of what they are and how they work, the best option is to go straight to the official documentation - ecl_sigslots.

Sigslot Reference

The kobuki driver establishes a set of signals on uniquely established namespaces. The namespace for each is separated into two parts - the first is the namespace specified by the sigslots_namespace variable in the kobuki::Parameter strucutre. The second uniquely identifies the signal itself.

The following represent the available signals when namespaced under "/kobuki" (default).

  • void : /kobuki/stream_data : informs when a new data packet has arrived from the kobuki
  • std::string : /kobuki/ros_debug : relay debug messages
  • std::string : /kobuki/ros_info : relay info messages
  • std::string : /kobuki/ros_warn : relay warning messages
  • std::string : /kobuki/ros_error : relay error messages
  • kobuki::ButtonEvent : /kobuki/button_event : receive an event when a button state changes
  • kobuki::BumperEvent : /kobuki/bumper_event : receive an event when the bumper state changes
  • kobuki::CliffEvent : /kobuki/cliff_event : receive an event when a cliff sensor state changes
  • kobuki::WheelEvent: /kobuki/wheel_event : receive an event when the wheel state (in/out) changes
  • kobuki::PowerEvent : /kobuki/power_event : receive an event when the power/charging state changes
  • kobuki::InputEvent : /kobuki/input_event : receive an event when the gpio state changes
  • kobuki::RobotEvent : /kobuki/robot_event : receive an event when the robot state changes
  • kobuki::VersionInfo : /kobuki/version_info : receive version info strings on this signal

It does not establish any slots.

Usage

The /kobuki/stream_data is the most important slot. The kobuki sends a single long data packet periodically and when this is received, it emits a signal informing you that it has arrived and is ready to be processed. At this point, you can quiz the kobuki driver for the state ( kobuki::Kobuki::getCoreSensorData) which returns a kobuki::CoreSensors::Data structure holding all the important sensor information for kobuki.

Simple Example - Catching Wheel Odometry

A small example program which processes this signal sending current wheel encoder values to standard output:

#include <ecl/time.hpp>
#include <ecl/sigslots.hpp>
#include <iostream>
public:
slot_stream_data(&KobukiManager::processStreamData, *this) // establish the callback
{
kobuki::Parameters parameters;
parameters.sigslots_namespace = "/kobuki"; // configure the first part of the sigslot namespace
parameters.device_port = "/dev/kobuki"; // the serial port to connect to (windows COM1..)
kobuki.init(parameters);
slot_stream_data.connect("/kobuki/stream_data");
}
void spin() {
ecl::Sleep sleep(1);
while ( true ) {
sleep();
}
}
/*
* Called whenever the kobuki receives a data packet. Up to you from here to process it.
*
* Note that special processing is done for the various events which discretely change
* state (bumpers, cliffs etc) and updates for these are informed via the xxxEvent
* signals provided by the kobuki driver.
*/
kobuki::CoreSensors::Data data = kobuki.getCoreSensorData();
std::cout << "Encoders [" << data.left_encoder << "," << data.right_encoder << "]" << std::endl;
}
private:
};
int main() {
KobukiManager kobuki_manager;
kobuki_manager.spin();
return 0;
}

Other Signals

The other signals will pass a structure of a particular type with the transmitted information. Process the same way, using the event type as the argument to the callback function.

Detailed Example

More detailed example code can be found in the ros kobuki node implementation. See the kobuki_node implementation for a ros platform.

Troubleshooting

While debugging, you may often accidentally leave sigslots dangling, typos for the connection name are a common cause. For this, there is an introspection method available which you can use to quickly print the currently sigslot connections (dangling or otherwise).

A code snippet:

Kobuki kobuki
Parameters parameters;
// configure parameters here
kobuki.init(parameters);
// make some sigslot connections here
kobuki.printSigSlotConnections();

Depending on your sigslot connection configuration, you should see something like the following,

========== Void ==========
Topics
Name: /kobuki/stream_data
# Subscribers: 1
# Publishers : 1
========= String =========
Topics
Name: /kobuki/ros_debug
# Subscribers: 1
# Publishers : 1
Name: /kobuki/ros_error
# Subscribers: 1
# Publishers : 2
Name: /kobuki/ros_info
# Subscribers: 1
# Publishers : 1
Name: /kobuki/ros_warn
# Subscribers: 1
# Publishers : 2
====== Button Event ======
Topics
Name: /kobuki/button_event
# Subscribers: 1
# Publishers : 1
====== Bumper Event ======
Topics
Name: /kobuki/bumper_event
# Subscribers: 1
# Publishers : 1
...

This uses the sigslots manager to retrieve the information. A full example of its use can be found in the ecl_sigslot sources: example cpp program.

kobuki::Parameters::sigslots_namespace
std::string sigslots_namespace
The first part of a sigslot connection namespace ["/kobuki"].
Definition: parameters.hpp:69
ecl::Slot
kobuki::CoreSensors::Data
Definition: core_sensors.hpp:54
kobuki
Definition: command.hpp:31
sigslots.hpp
kobuki::Button
@ Button
Definition: sound.hpp:49
KobukiManager::spin
void spin()
Worker thread loop; sends current velocity command at a fixed rate.
Definition: sigslots.cpp:36
kobuki::CoreSensors::Data::left_encoder
uint16_t left_encoder
Definition: core_sensors.hpp:59
KobukiManager::kobuki
kobuki::Kobuki kobuki
Definition: initialisation.cpp:42
KobukiManager
Keyboard remote control for our robot core (mobile base).
Definition: initialisation.cpp:14
ecl::Slot::connect
void connect(const std::string &topic)
kobuki::Parameters
Parameter list and validator for the kobuki.
Definition: parameters.hpp:42
kobuki.hpp
Device driver core interface.
KobukiManager::processStreamData
void processStreamData()
Definition: sigslots.cpp:50
kobuki::Kobuki
The core kobuki driver class.
Definition: kobuki.hpp:95
KobukiManager::KobukiManager
KobukiManager()
Default constructor, needs initialisation.
Definition: initialisation.cpp:18
kobuki::CoreSensors::Data::right_encoder
uint16_t right_encoder
Definition: core_sensors.hpp:60
time.hpp
KobukiManager::slot_stream_data
ecl::Slot slot_stream_data
Definition: sigslots.cpp:57
kobuki::Parameters::device_port
std::string device_port
The serial device port name [/dev/kobuki].
Definition: parameters.hpp:68
main
int main()
Definition: initialisation.cpp:43


kobuki_driver
Author(s): Daniel Stonier , Younghun Ju , Jorge Santos Simon
autogenerated on Wed Mar 2 2022 00:26:14