34 #include "entry_publisher.h"
35 #include "entry_subscriber.h"
41 int main(
int argc,
char* argv[]) {
45 const std::string busname =
"slcan0";
49 const std::string baudrate =
"500K";
52 if (!master.
start(busname, baudrate)) {
53 ERROR(
"Starting master failed.");
57 std::this_thread::sleep_for(std::chrono::seconds(1));
60 ERROR(
"No devices found.");
71 ERROR(
"This example is intended for use with a CiA 401 device. You plugged a device with profile number "<<std::dec<<profile);
77 DUMP(device.
get_entry(
"Manufacturer device name"));
84 device.
set_entry(
"Write output 8-bit/Digital Outputs 1-8", (uint8_t) 0xFF);
86 ros::init(argc, argv,
"canopen_bridge");
94 auto iopub = std::make_shared<kaco::EntryPublisher>(device,
"Read input 8-bit/Digital Inputs 9-16");
99 auto iosub = std::make_shared<kaco::EntrySubscriber>(device,
"Write output 8-bit/Digital Outputs 1-8");
void print_dictionary() const
Prints the dictionary together with currently cached values to command line.
Device & get_device(size_t index) const
Returns a reference to a slave device object.
const Value & get_entry(const std::string &entry_name, const ReadAccessMethod access_method=ReadAccessMethod::use_default)
Gets the value of a dictionary entry by name internally. If there is no cached value or the entry is ...
This class is a bridge between a ROS network and a CanOpen network.
void start()
Starts the node via NMT protocol and loads mandatory entries, operations, and constants.
size_t num_devices() const
Returns the number of slave devices in the network.
void add_receive_pdo_mapping(uint16_t cob_id, const std::string &entry_name, uint8_t offset)
Adds a receive PDO mapping. This means values sent by the device via PDO are saved into the dictionar...
void stop()
Stops master and core.
void run()
Runs the ROS spinner and blocks until shutdown (e.g. via Ctrl+c).
bool start(const std::string busname, const std::string &baudrate)
Starts master and creates Core.
uint16_t get_device_profile_number()
Returns the CiA profile number.
This class represents a master node. It listens for new slaves and provides access to them via get_sl...
std::string load_dictionary_from_library()
Tries to load the most specific EDS file available in KaCanOpen's internal EDS library. This is either device specific, CiA profile specific, or mandatory CiA 301.
This class represents a CanOpen slave device in the network.
void add_publisher(std::shared_ptr< Publisher > publisher, double loop_rate=10)
Adds a Publisher, advertises it and publishes messages repeatedly.
void set_entry(const std::string &entry_name, const Value &value, const WriteAccessMethod access_method=WriteAccessMethod::use_default)
Sets the value of a dictionary entry by name internally. If the entry is configured to send an SDO on...
void add_subscriber(std::shared_ptr< Subscriber > subscriber)
Adds a Subscriber, which can advertise itself and receive messages on its own.