vulp  2.2.2
observe_servos.cpp
Go to the documentation of this file.
1 // Copyright 2022 Stéphane Caron
2 // SPDX-License-Identifier: Apache-2.0
3 
5 
6 #include <map>
7 #include <string>
8 #include <vector>
9 
10 namespace moteus = vulp::actuation::moteus;
11 
12 using palimpsest::Dictionary;
13 
14 namespace vulp::observation {
15 
16 void observe_servos(Dictionary& observation,
17  const std::map<int, std::string>& servo_joint_map,
18  const std::vector<moteus::ServoReply>& servo_replies) {
19  for (const auto& reply : servo_replies) {
20  const int servo_id = reply.id;
21  auto it = servo_joint_map.find(servo_id);
22  if (it == servo_joint_map.end()) {
23  spdlog::error("Unknown servo ID {} in CAN reply", servo_id);
24  continue;
25  }
26  const auto& joint = it->second;
27 
28  // The moteus convention is that positive angles correspond to clockwise
29  // rotations when looking at the rotor / back of the moteus board. See:
30  // https://jpieper.com/2021/04/30/moteus-direction-configuration/
31  double position_rev = reply.result.position;
32  double velocity_rev_s = reply.result.velocity;
33  double position_rad = (2.0 * M_PI) * position_rev;
34  double velocity_rad_s = (2.0 * M_PI) * velocity_rev_s;
35 
36  auto& servo = observation("servo")(joint);
37  servo("d_current") = reply.result.d_current;
38  servo("fault") = reply.result.fault;
39  servo("mode") = static_cast<unsigned>(reply.result.mode);
40  servo("position") = position_rad;
41  servo("q_current") = reply.result.q_current;
42  servo("temperature") = reply.result.temperature;
43  servo("torque") = reply.result.torque;
44  servo("velocity") = velocity_rad_s;
45  servo("voltage") = reply.result.voltage;
46  }
47 }
48 
49 } // namespace vulp::observation
State observation.
Definition: observe_imu.cpp:8
void observe_servos(Dictionary &observation, const std::map< int, std::string > &servo_joint_map, const std::vector< moteus::ServoReply > &servo_replies)