Goby Underwater Autonomy Project
Series: 1.1, revision: 163, released on 2013-02-06 14:23:27 -0500
|
Table of Contents for libamac:
Return to goby-acomms: Overview of Acoustic Communications Libraries.
The Medium Access Control schemes provided by libamac are based on Time Division Multiple Access (TDMA) where different communicators share the same bandwidth but transmit at different times to avoid conflicts. Time is divided into slots and each vehicle is given a slot to transmit on. The set of slots comprising all the vehicles is referred to here as a cycle, which repeats itself when it reaches the end. The two variations on this scheme provided by libamac are:
To use the goby::acomms::MACManager, you need to instantiate it (optionally with a std::ostream pointer to a location to log to):
goby::acomms::MACManager mac(&std::clog);
Then you need to provide a slot for initiated transmissions for the signal goby::acomms::MACManager::signal_initiate_transmission. This signal will be called when the goby::acomms::MACManager determines it is time to send a message. If using libmodemdriver, simply call goby::acomms::bind(goby::acomms::MACManager&, goby::acomms::ModemDriverBase&) to bind this callback to the modem driver.
Next you need to decide which type of MAC to use: decentralized auto-discovery, decentralized fixed or centralized polling and set the type of the goby::acomms::protobuf::MACConfig with the corresponding goby::acomms::protobuf::MACType. We also need to give goby::acomms::MACManager the vehicle's modem id (like all the other components of goby-acomms):
using namespace goby::acomms;
protobuf::MACConfig mac_cfg;
mac_cfg.set_type(protobuf::MAC_FIXED_DECENTRALIZED);
mac_cfg.set_modem_id(1);
The usage of the goby::acomms::MACManager depends now on the type:
mac_cfg.set_rate(0); mac_cfg.set_slot_seconds(10); mac_cfg.set_expire_cycles(2);
// poll ourselves (for commands, perhaps) goby::acomms::protobuf::Slot slot; slot.set_src(1); slot.set_dest(goby::acomms::QUERY_DESTINATION_ID); slot.set_rate(0); slot.set_type(goby::acomms::protobuf::SLOT_DATA); slot.set_seconds(10); mac_cfg.add_slot(10); // 1->-1@0 wait 10 // reuse slot slot.set_src(3); slot.set_dest(goby::acomms::BROADCAST_ID); mac_cfg.add_slot(slot); // 3->0@0 wait 10 slot.set_rate(5); mac_cfg.add_slot(slot); // 3->0@5 wait 10 slot.set_src(4); slot.set_rate(0); mac_cfg.add_slot(slot); // 4->0@0 wait 10
goby::acomms::protobuf::Slot slot; slot.set_src(1); slot.set_dest(goby::acomms::QUERY_DESTINATION_ID); slot.set_rate(0); slot.set_type(goby::acomms::protobuf::SLOT_DATA); slot.set_seconds(10); mac_cfg.add_slot(10); // 1->-1@0 wait 10 slot.set_src(3); mac_cfg.add_slot(slot); // 3->-1@0 wait 10 slot.set_rate(5); mac_cfg.add_slot(slot); // 3->-1@5 wait 10 slot.set_src(4); slot.set_rate(0); mac_cfg.add_slot(slot); // 4->-1@0 wait 10
Then, for either MAC scheme, start the goby::acomms::MACManager running (goby::acomms::MACManager::startup with the goby::acomms::protobuf::MACConfig object), and call goby::acomms::MACManager::do_work() periodically (5 Hz is ok, 10 Hz is better).