ASCO Aerial Autonomy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
arm_system.h
Go to the documentation of this file.
1 #pragma once
2 
3 // Html table writer
5 // Base robot system
7 // Arm hardware
8 #include <arm_parsers/arm_parser.h>
9 
10 #include <iomanip>
11 #include <sstream>
12 
18 class ArmSystem : public virtual BaseRobotSystem {
19 
20 private:
24  ArmParser &arm_hardware_;
25 
26 public:
35  ArmSystem(ArmParser &arm_hardware)
36  : BaseRobotSystem(), arm_hardware_(arm_hardware) {}
37 
41  Eigen::Matrix4d getEndEffectorPose() {
42  return arm_hardware_.getEndEffectorTransform();
43  }
44 
51  bool grip(bool grip_action) {
52  if (grip_action) {
53  //\todo Gowtham Change arm plugins to update gripping strategy
54  int grip_position = 1000;
55  return arm_hardware_.grip(grip_position);
56  } else {
57  //\todo Gowtham Change arm plugins to update gripping strategy
58  int grip_position = 2000;
59  return arm_hardware_.grip(grip_position);
60  }
61  }
62 
68  void power(bool state) {
69  if (state) {
70  arm_hardware_.sendCmd(ArmParser::POWER_ON);
71  } else {
72  arm_hardware_.sendCmd(ArmParser::POWER_OFF);
73  }
74  }
75 
79  void foldArm() { arm_hardware_.sendCmd(ArmParser::FOLD_ARM); }
80 
84  void rightArm() { arm_hardware_.sendCmd(ArmParser::RIGHT_ARM); }
85 
93  std::string getSystemStatus() const {
94  HtmlTableWriter table_writer;
95  table_writer.beginRow();
96  table_writer.addHeader("Arm Status:", Colors::blue, 4);
97  table_writer.beginRow();
98  table_writer.addCell("Joint Angles: ");
99  for (double q : arm_hardware_.getJointAngles()) {
100  table_writer.addCell(q);
101  }
102  table_writer.beginRow();
103  table_writer.addCell("Joint Velocities: ");
104  for (double q : arm_hardware_.getJointVelocities()) {
105  table_writer.addCell(q);
106  }
107  Eigen::Matrix4d ee_transform = arm_hardware_.getEndEffectorTransform();
108  table_writer.beginRow();
109  table_writer.addCell("End effector translation: ");
110  for (int i = 0; i < 3; ++i) {
111  table_writer.addCell(ee_transform(i, 3));
112  }
113  Eigen::Matrix3d ee_rotation = ee_transform.topLeftCorner(3, 3);
114  Eigen::Vector3d euler_angles = ee_rotation.eulerAngles(2, 1, 0);
115  table_writer.beginRow();
116  table_writer.addCell("End effector RPY: ");
117  for (int i = 0; i < 3; ++i) {
118  table_writer.addCell(euler_angles[i]);
119  }
120  table_writer.beginRow();
121  std::string command_status = (getCommandStatus() ? "True" : "False");
122  std::string command_status_color =
124  table_writer.addCell(command_status, "CommandStatus", command_status_color,
125  2);
126  table_writer.beginRow();
127  std::string arm_enabled = (enabled() ? "True" : "False");
128  std::string enabled_color = (enabled() ? Colors::green : Colors::red);
129  table_writer.addCell(arm_enabled, "Enabled", enabled_color, 2);
130  return table_writer.getTableString();
131  }
132 
138  bool getCommandStatus() const { return arm_hardware_.getCommandStatus(); }
139 
145  bool enabled() const {
146  return arm_hardware_.state == ArmParser::ENABLED ? true : false;
147  }
148 };
static constexpr const char * green
Green color hex code.
Definition: html_utils.h:18
std::string getTableString()
Get the html table in string format.
Definition: html_utils.h:170
std::string getSystemStatus() const
Provide the current state of arm system.
Definition: arm_system.h:93
void foldArm()
Set the arm joints to a known folded configuration.
Definition: arm_system.h:79
bool grip(bool grip_action)
Public API call to grip/ungrip an object.
Definition: arm_system.h:51
Provides functions to switch between active controllers and get goals.
Definition: base_robot_system.h:16
static constexpr const char * blue
Blue color hex code.
Definition: html_utils.h:22
bool getCommandStatus() const
Verify the status of grip/power on/off and fold/rightArm commands.
Definition: arm_system.h:138
bool enabled() const
If arm is enabled return.
Definition: arm_system.h:145
void addCell(const DataT &data, std::string header="", std::string bg_color=Colors::white, int colspan=1)
Add a cell to the table. Should be called after beginning a row. Otherwise will throw an exception...
Definition: html_utils.h:116
void beginRow()
Begin a new row in the table.
Definition: html_utils.h:135
Eigen::Matrix4d getEndEffectorPose()
Public API call to get end effector transform.
Definition: arm_system.h:41
void addHeader(std::string header, std::string text_color=Colors::black, int colspan=1)
Add a table header. Should be called after beginning a row.
Definition: html_utils.h:152
void rightArm()
Set the arm joints to a known L shaped configuration.
Definition: arm_system.h:84
Owns, initializes, and facilitates communication between different hardware/software components...
Definition: arm_system.h:18
Helper class to write html tables to text format.
Definition: html_utils.h:91
void power(bool state)
Power the arm on/off.
Definition: arm_system.h:68
ArmSystem(ArmParser &arm_hardware)
Constructor.
Definition: arm_system.h:35
static constexpr const char * red
Red color hex code.
Definition: html_utils.h:14