NASA Astrobee Robot Software  0.19.1
Flight software for the Astrobee robots operating inside the International Space Station.
smart_dock_node.h
Go to the documentation of this file.
1 /* Copyright (c) 2017, United States Government, as represented by the
2  * Administrator of the National Aeronautics and Space Administration.
3  *
4  * All rights reserved.
5  *
6  * The Astrobee platform is licensed under the Apache License, Version 2.0
7  * (the "License"); you may not use this file except in compliance with the
8  * License. You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
14  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
15  * License for the specific language governing permissions and limitations
16  * under the License.
17  */
18 
19 
20 #ifndef SMART_DOCK_SMART_DOCK_NODE_H_
21 #define SMART_DOCK_SMART_DOCK_NODE_H_
22 
23 #include <string.h>
24 #include <sys/time.h>
25 
26 #include <iostream>
27 #include <memory>
28 #include <string>
29 #include <map>
30 
31 #include "dds_msgs/AstrobeeConstants.h"
32 
33 #include "ff_common/init.h"
34 
35 #include "dds_msgs/DockStateSupport.h"
36 
37 #include "knDds/DdsEntitiesFactory.h"
38 #include "knDds/DdsEntitiesFactorySvc.h"
39 #include "knDds/DdsEventLoop.h"
40 #include "knDds/DdsSupport.h"
41 #include "knDds/DdsTypedSupplier.h"
42 
43 #include "miro/Configuration.h"
44 #include "miro/Robot.h"
45 #include "miro/Log.h"
46 
47 #include "rapidDds/RapidConstants.h"
48 #include "rapidDds/AckSupport.h"
49 #include "rapidDds/CommandSupport.h"
50 
51 #include "rapidUtil/RapidHelper.h"
52 
53 #include "smart_dock/smart_dock.h"
54 
55 namespace kn {
56  class DdsEntitiesFactorySvc;
57 } // end namespace kn
58 
59 namespace smart_dock {
61  public:
62  // Contructor
63  SmartDockNode(int argc, char** argv, const i2c::Device &i2c_dev,
64  std::string const& name);
65 
66  // Destructor
68 
69  // Callback for the DDS event loop
70  void operator() (rapid::Command const* cmd);
71 
72  // Communcation publish loop
73  void ProcessComms();
74 
75  // Telemetry publish loop (latched)
76  void ProcessTelem();
77 
78  // Register a device (robot) serial to ID mapping
79  bool AddDevice(std::string const& serial, std::string const& name);
80 
81  protected:
82  // Publish an ack
83  void PublishCmdAck(std::string const& cmd_id,
84  rapid::AckStatus status = rapid::ACK_COMPLETED,
85  rapid::AckCompletedStatus completed_status =
86  rapid::ACK_COMPLETED_OK,
87  std::string const& message = "");
88 
89  // Make a DDS timestamp
90  int64_t MakeTimestamp();
91 
92  private:
93  using AckSupplier = kn::DdsTypedSupplier<rapid::Ack>;
94  using DockSupplier = kn::DdsTypedSupplier<rapid::ext::astrobee::DockState>;
95  // Interface to the smart dock
96  SmartDock sd_;
97  // Serial -> Name lookup table
98  std::map<std::string, std::string> devices_;
99  // Various suffixes for messages
100  std::string ack_pub_suffix_, dock_state_pub_suffix_, sub_suffix_;
102  // NB: The order of the variables below is ESSENTIAL. They are destroyed from
103  // the bottom to top. It is essential that the destruction order remains sane
104  // or else we will get weird hanging and segfaults on exit
106  // Entity factory
107  std::shared_ptr<kn::DdsEntitiesFactorySvc> dds_entities_factory_;
108  // Dock state publisher
109  DockSupplier *dock_state_supplier_;
110  // Ack state publisher
111  AckSupplier *ack_state_supplier_;
112  // Messaging event loop
113  kn::DdsEventLoop dds_event_loop_;
114 };
115 
116 } // end namespace smart_dock
117 
118 #endif // SMART_DOCK_SMART_DOCK_NODE_H_
smart_dock.h
smart_dock::SmartDockNode::~SmartDockNode
~SmartDockNode()
Definition: smart_dock_node.cc:126
smart_dock::SmartDockNode
Definition: smart_dock_node.h:60
smart_dock::SmartDockNode::operator()
void operator()(rapid::Command const *cmd)
Definition: smart_dock_node.cc:128
smart_dock
Definition: smart_dock.h:30
smart_dock::SmartDockNode::ProcessComms
void ProcessComms()
Definition: smart_dock_node.cc:184
smart_dock::SmartDockNode::MakeTimestamp
int64_t MakeTimestamp()
Definition: smart_dock_node.cc:258
pmc_actuator::Command
Command
Definition: pmc_actuator.h:53
init.h
name
std::string name
Definition: eps_simulator.cc:48
smart_dock::SmartDock
Definition: smart_dock.h:35
kn
Definition: smart_dock_node.h:55
smart_dock::SmartDockNode::ProcessTelem
void ProcessTelem()
Definition: smart_dock_node.cc:188
smart_dock::SmartDockNode::SmartDockNode
SmartDockNode(int argc, char **argv, const i2c::Device &i2c_dev, std::string const &name)
Definition: smart_dock_node.cc:55
smart_dock::SmartDockNode::AddDevice
bool AddDevice(std::string const &serial, std::string const &name)
Definition: smart_dock_node.cc:177
i2c::Device
Definition: i2c_new.h:82
smart_dock::SmartDockNode::PublishCmdAck
void PublishCmdAck(std::string const &cmd_id, rapid::AckStatus status=rapid::ACK_COMPLETED, rapid::AckCompletedStatus completed_status=rapid::ACK_COMPLETED_OK, std::string const &message="")
Definition: smart_dock_node.cc:266