walter
bot.h
Go to the documentation of this file.
1 #pragma once
2 #include "unitree_legged_sdk/unitree_legged_sdk.h"
3 #include <Eigen/Dense>
4 #include <functional>
5 #include <cmath>
6 #include "utils.h"
7 
8 namespace a1 = UNITREE_LEGGED_SDK;
9 constexpr double pi = M_PI;
10 
12  a1::HighCmd cmd;
13  bool done;
14 };
15 
21 using Instruction = std::function<InstructionOutput(Pose, a1::HighState)>;
22 
23 class Bot
24 {
25  a1::Safety safe;
26  a1::UDP udp;
27  a1::HighCmd cmd = {0};
28  a1::HighState state = {0};
30  int motiontime = 0;
31  float dt = 0.002;
32  int index = 0;
33  bool executing = false;
34 
40  std::vector<Instruction> instructions;
41 
46  void UDPRecv();
47 
52  void UDPSend();
53 
58  void RobotControl();
59 
63  Pose estimate_pose(Pose prev, a1::HighState state);
67  bool validate_cmd(a1::HighCmd cmd);
68 
69 public:
70  Bot(): safe(a1::LeggedType::A1), udp(a1::HIGHLEVEL){
71  udp.InitCmdData(cmd);
72  }
73 
79  void execute();
80 
84  State get_state();
85 
91  void move_x(float distance, float velocity);
92 
98  void move_y(float distance, float velocity);
99 
105  void move(Eigen::Vector2f position, Eigen::Vector2f velocity);
106 
114  void smooth_move(Eigen::Vector2f position, float velocity, float omega = 1*pi/3);
115 
116  void spline_move();
117 
123  void rotate(float theta, float omega);
124 
130  [[deprecated("unsafe")]] void set_led(std::vector<Eigen::Vector3i> lights);
131 
135  [[deprecated]] void set_pyr(Eigen::Vector3d pitch, Eigen::Vector3d yaw, Eigen::Vector3d roll);
139  [[deprecated]] void set_height(float h, float v);
140 };
Definition: bot.h:11
a1::HighCmd cmd
Definition: bot.h:12
Pose initial_pose
Initial pose of current instruction.
Definition: bot.h:29
bool done
Definition: bot.h:13
Definition: utils.h:20
a1::UDP udp
UDP struct that stores payloads to send/recv.
Definition: bot.h:26
Definition: utils.h:13
a1::Safety safe
Specifies operation mode?
Definition: bot.h:25
Definition: bot.h:23
std::vector< Instruction > instructions
List of Instructions to be executed sequentially by the A1.
Definition: bot.h:40
std::function< InstructionOutput(Pose, a1::HighState)> Instruction
Lambda that takes in initial state and current state (in that order) and outputs a command for the cu...
Definition: bot.h:21
Bot()
Definition: bot.h:70
Definition: utils.h:30
constexpr double pi
Definition: bot.h:9