diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile new file mode 100644 index 0000000..64887d8 --- /dev/null +++ b/.devcontainer/Dockerfile @@ -0,0 +1,31 @@ +FROM ros:humble +ENV DEBIAN_FRONTEND=noninteractive +SHELL ["/bin/bash", "-c"] +RUN apt-get update && apt-get install -y -qq --no-install-recommends \ + libglvnd-dev \ + libgl1-mesa-dev \ + libegl1-mesa-dev \ + libgles2-mesa-dev \ + libxext6 \ + libx11-6 \ + freeglut3-dev \ + git \ + python3-pip \ + ros-humble-rmw-cyclonedds-cpp ros-humble-rosidl-generator-dds-idl \ + libyaml-cpp-dev \ + ros-humble-xacro \ + libboost-all-dev\ + build-essential \ + cmake \ + && rm -rf /var/lib/apt/lists/* + + +RUN pip3 install mujoco pin matplotlib + +RUN cd / && git clone https://github.com/unitreerobotics/unitree_ros2 && cd /unitree_ros2/cyclonedds_ws/src && \ +git clone https://github.com/ros2/rmw_cyclonedds -b humble && git clone https://github.com/eclipse-cyclonedds/cyclonedds -b releases/0.10.x &&\ +cd .. && colcon build --packages-select cyclonedds && source /opt/ros/humble/setup.bash && colcon build + +# Env vars for the nvidia-container-runtime. +ENV NVIDIA_VISIBLE_DEVICES all +ENV NVIDIA_DRIVER_CAPABILITIES graphics,utility,compute \ No newline at end of file diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 0000000..14e7378 --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,13 @@ +// https://containers.dev/implementors/json_reference/ +{ + "name": "go2py", + "dockerComposeFile": "docker-compose.yaml", + "workspaceFolder": "/home/Go2Py", + "service": "go2py-dev", + "remoteUser": "root", + "customizations": { + "vscode": { + "extensions": ["dbaeumer.vscode-eslint"] + } + } +} \ No newline at end of file diff --git a/.devcontainer/docker-compose.yaml b/.devcontainer/docker-compose.yaml new file mode 100644 index 0000000..54d71e4 --- /dev/null +++ b/.devcontainer/docker-compose.yaml @@ -0,0 +1,17 @@ +version: "3.9" +services: + go2py-dev: + build: . + container_name: go2py-dev + network_mode: host + privileged: true + command: bash + volumes: + - /tmp/.X11-unix:/tmp/.X11-unix + - ..:/home/Go2Py + environment: + - DISPLAY=${DISPLAY} + - QT_X11_NO_MITSHM=1 + runtime: nvidia + stdin_open: true + tty: true \ No newline at end of file diff --git a/README.md b/README.md index ec54651..0d990ca 100644 --- a/README.md +++ b/README.md @@ -1,50 +1,68 @@ # Go2Py -Python interface, example controllers, and calibration tools for the Unitree Go2 robot. -## System Setup +Go2Py is a Pythonic interface and driver for low-level and high-level control of Unitree Go2 quadruped robots. The motivation of this project is to remove the burden of developing interface, safety systems, and basic components required for starting locomotion reserach using the Go2 quadruped robot. It provides a modular pipeline for real-time communication with the robot in both simulated and real world environment with a unified interface. -The GO2 EDU comes with an onbard Jetson Orin NX, a Hessai LX-16 LiDAR sensor, and an intel Realsense D435i camera. This setup procedure targets the onboard Jetson Orin with IP `192.168.123.18` and presents the installation proceudures of nodes for reading the sensors and robot states and publisheing them as ROS2 topics plus some basic configurations for setting up the autostart services and sharing internet. The architecture of the GO2 system is illustrated in the following image: -TODO: add image +
+ +
-### Internet Sharing +This project is comprised of the following components: +- **C++ Bridge:** A dockerized ROS2 bridge built upon the [unitree_ros2](https://github.com/unitreerobotics/unitree_ros2) that implements a remote controlled emergency stop and publishes the robot states as standard ROS2 topics usable by upstream systems such as NAV2. +- **Robot Interface:** A simple Python class that represents the robot and communicates with the C++ bridge through either DDS (ROS independent) or ROS2 interfaces. +- **Robot Management FSM:** A finite state machine for controlling the behavior of the robot up to the point of handover to the user low-level controller (sitting down, standing up) with safety monitors (motor temperatures, emergency stops). +- **Robot Model:** A simple to use [Pinocchio](https://github.com/stack-of-tasks/pinocchio) wrapper for computing the kinematics and dynamics parameters of the robot. +- **Simulation Interface:** Simulation environments based on Mujoco and Nvidia Orbit (To be added) with a Python interface identical to the real robot. -In order to access internet on the Jetson computer, we hook the robot to a host development computer with internet access and configure it to share its connection with the robot. To cofigure the host computer, the follwoing steps should be taken: -#### Host Computer -The following steps configures the host computer to share its intentrent with the robot. -##### Enable IP forwarding: +## How Does Using it Look Like? +Communication with the robot will be as simple as importing a Python class: +```python +from Go2Py.robot.interface.dds import GO2Real +from Go2Py.robot.model import Go2Model +robot = GO2Real(mode='lowlevel') +model = Go2Model() +robot.standDownReset() +while running: + joint_state = robot.getJointStates() + imu = robot.getIMU() + remote = robot.getRemoteState() + model.update(state['q'], state['dq'],T,vel) # T and vel from the EKF + info = model.getInfo() + + #User control computations ... -```bash -sudo sysctl -w net.ipv4.ip_forward=1 + robot.setCommands(q_des, dq_des, kp, kd, tau_ff) ``` -##### Configure the iptables: +An identical workflow is can be followed for simulation: +```python +from Go2Py.sim.mujoco import Go2Sim +from Go2Py.robot.model import Go2Model +robot = Go2Sim() +model = Go2Model() +robot.standDownReset() +while running: + joint_state = robot.getJointStates() + imu = robot.getIMU() + remote = robot.getRemoteState() + model.update(state['q'], state['dq'],T,vel) # T and vel from the EKF + info = model.getInfo() -```bash -sudo iptables -t nat -A POSTROUTING -o wlan0 -j MASQUERADE -sudo iptables -A FORWARD -i wlan0 -o eth0 -m state --state RELATED,ESTABLISHED -j ACCEPT -sudo iptables -A FORWARD -i eth0 -o wlan0 -j ACCEPT + #User control computations ... + + robot.setCommands(q_des, dq_des, kp, kd, tau_ff) + robot.step() ``` -Note that `wlan0` should be replaced with the actual name of the network interface over which the internet is provided to the host computer, and eth0 should be replaced with the name of the Ethernet interface connected to the robot and having a local IP address in robot's network range. +## Installation +Follow through the steps in here to [setup](docs/setup.md) the robot and Go2Py. -##### Storing the Settings -Make the iptables rules persistent by installing the `iptables-persistent`: - -```bash -sudo apt-get install iptables-persistent -sudo iptables-save > /etc/iptables/rules.v4 -sudo ip6tables-save > /etc/iptables/rules.v6 -``` -#### Robot -Now tell the computer on the robot to use the internet shared by the host computer. SSH into the robot's computer with IP address `192.168.123.18`, username `unitree` and password `123`. Note that the host computer's IP reange should have already been set to static mode with an IP in `192.168.123.*` range. - -```bash -sudo ip route add default via// -----------------------------------------------------------------------------\n",
+ "// This file was autogenerated by symforce from template:\n",
+ "// function/FUNCTION.h.jinja\n",
+ "// Do NOT modify by hand.\n",
+ "// -----------------------------------------------------------------------------\n",
+ "\n",
+ "#pragma once\n",
+ "\n",
+ "#include <Eigen/Dense>\n",
+ "\n",
+ "namespace sym {\n",
+ "\n",
+ "/**\n",
+ " * This function was autogenerated from a symbolic function. Do not modify by hand.\n",
+ " *\n",
+ " * Symbolic function: compute_measurement\n",
+ " *\n",
+ " * Args:\n",
+ " * state: Matrix28_1\n",
+ " * epsilon: Scalar\n",
+ " *\n",
+ " * Outputs:\n",
+ " * res: Matrix15_1\n",
+ " * res_D_state: (15x28) jacobian of res (15) wrt arg state (28)\n",
+ " */\n",
+ "template <typename Scalar>\n",
+ "Eigen::Matrix<Scalar, 15, 1> ComputeMeasurementWithJacobian0(\n",
+ " const Eigen::Matrix<Scalar, 28, 1>& state, const Scalar epsilon,\n",
+ " Eigen::Matrix<Scalar, 15, 28>* const res_D_state = nullptr) {\n",
+ " // Total ops: 339\n",
+ "\n",
+ " // Unused inputs\n",
+ " (void)epsilon;\n",
+ "\n",
+ " // Input arrays\n",
+ "\n",
+ " // Intermediate terms (99)\n",
+ " const Scalar _tmp0 = 2 * state(1, 0);\n",
+ " const Scalar _tmp1 = _tmp0 * state(0, 0);\n",
+ " const Scalar _tmp2 = 2 * state(2, 0);\n",
+ " const Scalar _tmp3 = _tmp2 * state(3, 0);\n",
+ " const Scalar _tmp4 = _tmp1 + _tmp3;\n",
+ " const Scalar _tmp5 = _tmp2 * state(0, 0);\n",
+ " const Scalar _tmp6 = _tmp0 * state(3, 0);\n",
+ " const Scalar _tmp7 = _tmp5 - _tmp6;\n",
+ " const Scalar _tmp8 = 2 * std::pow(state(1, 0), Scalar(2));\n",
+ " const Scalar _tmp9 = 2 * std::pow(state(2, 0), Scalar(2)) - 1;\n",
+ " const Scalar _tmp10 = _tmp8 + _tmp9;\n",
+ " const Scalar _tmp11 = -_tmp10;\n",
+ " const Scalar _tmp12 = _tmp1 - _tmp3;\n",
+ " const Scalar _tmp13 = 2 * state(3, 0);\n",
+ " const Scalar _tmp14 = _tmp13 * state(0, 0);\n",
+ " const Scalar _tmp15 = _tmp0 * state(2, 0);\n",
+ " const Scalar _tmp16 = _tmp14 + _tmp15;\n",
+ " const Scalar _tmp17 = 2 * std::pow(state(0, 0), Scalar(2));\n",
+ " const Scalar _tmp18 = _tmp17 + _tmp9;\n",
+ " const Scalar _tmp19 = -_tmp18;\n",
+ " const Scalar _tmp20 = _tmp5 + _tmp6;\n",
+ " const Scalar _tmp21 = _tmp14 - _tmp15;\n",
+ " const Scalar _tmp22 = -_tmp21;\n",
+ " const Scalar _tmp23 = _tmp17 + _tmp8 - 1;\n",
+ " const Scalar _tmp24 = -_tmp23;\n",
+ " const Scalar _tmp25 = -state(5, 0);\n",
+ " const Scalar _tmp26 = _tmp25 + state(17, 0);\n",
+ " const Scalar _tmp27 = -state(6, 0);\n",
+ " const Scalar _tmp28 = _tmp27 + state(18, 0);\n",
+ " const Scalar _tmp29 = -state(4, 0);\n",
+ " const Scalar _tmp30 = _tmp29 + state(16, 0);\n",
+ " const Scalar _tmp31 = _tmp25 + state(20, 0);\n",
+ " const Scalar _tmp32 = _tmp27 + state(21, 0);\n",
+ " const Scalar _tmp33 = _tmp29 + state(19, 0);\n",
+ " const Scalar _tmp34 = _tmp25 + state(23, 0);\n",
+ " const Scalar _tmp35 = _tmp27 + state(24, 0);\n",
+ " const Scalar _tmp36 = _tmp29 + state(22, 0);\n",
+ " const Scalar _tmp37 = _tmp25 + state(26, 0);\n",
+ " const Scalar _tmp38 = _tmp27 + state(27, 0);\n",
+ " const Scalar _tmp39 = _tmp29 + state(25, 0);\n",
+ " const Scalar _tmp40 = _tmp0 * state(8, 0);\n",
+ " const Scalar _tmp41 = _tmp2 * state(9, 0);\n",
+ " const Scalar _tmp42 = 4 * state(0, 0);\n",
+ " const Scalar _tmp43 = _tmp13 * state(9, 0);\n",
+ " const Scalar _tmp44 = -_tmp2 * state(7, 0);\n",
+ " const Scalar _tmp45 = _tmp13 * state(8, 0);\n",
+ " const Scalar _tmp46 = _tmp0 * _tmp26;\n",
+ " const Scalar _tmp47 = _tmp2 * _tmp28;\n",
+ " const Scalar _tmp48 = _tmp13 * _tmp28;\n",
+ " const Scalar _tmp49 = -_tmp2 * _tmp30;\n",
+ " const Scalar _tmp50 = _tmp13 * _tmp26;\n",
+ " const Scalar _tmp51 = _tmp0 * _tmp31;\n",
+ " const Scalar _tmp52 = _tmp2 * _tmp32;\n",
+ " const Scalar _tmp53 = _tmp13 * _tmp32;\n",
+ " const Scalar _tmp54 = -_tmp2 * _tmp33;\n",
+ " const Scalar _tmp55 = _tmp13 * _tmp31;\n",
+ " const Scalar _tmp56 = _tmp0 * _tmp34;\n",
+ " const Scalar _tmp57 = _tmp2 * _tmp35;\n",
+ " const Scalar _tmp58 = _tmp13 * _tmp35;\n",
+ " const Scalar _tmp59 = -_tmp2 * _tmp36;\n",
+ " const Scalar _tmp60 = _tmp13 * _tmp34;\n",
+ " const Scalar _tmp61 = _tmp0 * _tmp37;\n",
+ " const Scalar _tmp62 = _tmp2 * _tmp38;\n",
+ " const Scalar _tmp63 = _tmp13 * _tmp38;\n",
+ " const Scalar _tmp64 = -_tmp2 * _tmp39;\n",
+ " const Scalar _tmp65 = _tmp13 * _tmp37;\n",
+ " const Scalar _tmp66 = 2 * state(0, 0);\n",
+ " const Scalar _tmp67 = _tmp66 * state(8, 0);\n",
+ " const Scalar _tmp68 = 4 * state(1, 0);\n",
+ " const Scalar _tmp69 = _tmp66 * state(7, 0);\n",
+ " const Scalar _tmp70 = _tmp13 * state(7, 0);\n",
+ " const Scalar _tmp71 = _tmp26 * _tmp66;\n",
+ " const Scalar _tmp72 = _tmp30 * _tmp66;\n",
+ " const Scalar _tmp73 = _tmp13 * _tmp30;\n",
+ " const Scalar _tmp74 = _tmp31 * _tmp66;\n",
+ " const Scalar _tmp75 = _tmp33 * _tmp66;\n",
+ " const Scalar _tmp76 = _tmp13 * _tmp33;\n",
+ " const Scalar _tmp77 = _tmp34 * _tmp66;\n",
+ " const Scalar _tmp78 = _tmp36 * _tmp66;\n",
+ " const Scalar _tmp79 = _tmp13 * _tmp36;\n",
+ " const Scalar _tmp80 = _tmp37 * _tmp66;\n",
+ " const Scalar _tmp81 = _tmp39 * _tmp66;\n",
+ " const Scalar _tmp82 = _tmp13 * _tmp39;\n",
+ " const Scalar _tmp83 = _tmp66 * state(9, 0);\n",
+ " const Scalar _tmp84 = 4 * state(2, 0);\n",
+ " const Scalar _tmp85 = _tmp0 * state(9, 0);\n",
+ " const Scalar _tmp86 = _tmp28 * _tmp66;\n",
+ " const Scalar _tmp87 = _tmp0 * _tmp28;\n",
+ " const Scalar _tmp88 = _tmp32 * _tmp66;\n",
+ " const Scalar _tmp89 = _tmp0 * _tmp32;\n",
+ " const Scalar _tmp90 = _tmp35 * _tmp66;\n",
+ " const Scalar _tmp91 = _tmp0 * _tmp35;\n",
+ " const Scalar _tmp92 = _tmp38 * _tmp66;\n",
+ " const Scalar _tmp93 = _tmp0 * _tmp38;\n",
+ " const Scalar _tmp94 = -_tmp12;\n",
+ " const Scalar _tmp95 = -_tmp20;\n",
+ " const Scalar _tmp96 = -_tmp4;\n",
+ " const Scalar _tmp97 = -_tmp7;\n",
+ " const Scalar _tmp98 = -_tmp16;\n",
+ "\n",
+ " // Output terms (2)\n",
+ " Eigen::Matrix<Scalar, 15, 1> _res;\n",
+ "\n",
+ " _res(0, 0) = _tmp11 * state(7, 0) + _tmp4 * state(8, 0) + _tmp7 * state(9, 0);\n",
+ " _res(1, 0) = _tmp12 * state(7, 0) + _tmp16 * state(9, 0) + _tmp19 * state(8, 0);\n",
+ " _res(2, 0) = _tmp20 * state(7, 0) + _tmp22 * state(8, 0) + _tmp24 * state(9, 0);\n",
+ " _res(3, 0) = _tmp11 * _tmp30 + _tmp26 * _tmp4 + _tmp28 * _tmp7;\n",
+ " _res(4, 0) = _tmp12 * _tmp30 + _tmp16 * _tmp28 + _tmp19 * _tmp26;\n",
+ " _res(5, 0) = _tmp20 * _tmp30 + _tmp22 * _tmp26 + _tmp24 * _tmp28;\n",
+ " _res(6, 0) = _tmp11 * _tmp33 + _tmp31 * _tmp4 + _tmp32 * _tmp7;\n",
+ " _res(7, 0) = _tmp12 * _tmp33 + _tmp16 * _tmp32 + _tmp19 * _tmp31;\n",
+ " _res(8, 0) = _tmp20 * _tmp33 + _tmp22 * _tmp31 + _tmp24 * _tmp32;\n",
+ " _res(9, 0) = _tmp11 * _tmp36 + _tmp34 * _tmp4 + _tmp35 * _tmp7;\n",
+ " _res(10, 0) = _tmp12 * _tmp36 + _tmp16 * _tmp35 + _tmp19 * _tmp34;\n",
+ " _res(11, 0) = _tmp20 * _tmp36 + _tmp22 * _tmp34 + _tmp24 * _tmp35;\n",
+ " _res(12, 0) = _tmp11 * _tmp39 + _tmp37 * _tmp4 + _tmp38 * _tmp7;\n",
+ " _res(13, 0) = _tmp12 * _tmp39 + _tmp16 * _tmp38 + _tmp19 * _tmp37;\n",
+ " _res(14, 0) = _tmp20 * _tmp39 + _tmp22 * _tmp37 + _tmp24 * _tmp38;\n",
+ "\n",
+ " if (res_D_state != nullptr) {\n",
+ " Eigen::Matrix<Scalar, 15, 28>& _res_D_state = (*res_D_state);\n",
+ "\n",
+ " _res_D_state.setZero();\n",
+ "\n",
+ " _res_D_state(0, 0) = _tmp40 + _tmp41;\n",
+ " _res_D_state(1, 0) = _tmp0 * state(7, 0) - _tmp42 * state(8, 0) + _tmp43;\n",
+ " _res_D_state(2, 0) = -_tmp42 * state(9, 0) - _tmp44 - _tmp45;\n",
+ " _res_D_state(3, 0) = _tmp46 + _tmp47;\n",
+ " _res_D_state(4, 0) = _tmp0 * _tmp30 - _tmp26 * _tmp42 + _tmp48;\n",
+ " _res_D_state(5, 0) = -_tmp28 * _tmp42 - _tmp49 - _tmp50;\n",
+ " _res_D_state(6, 0) = _tmp51 + _tmp52;\n",
+ " _res_D_state(7, 0) = _tmp0 * _tmp33 - _tmp31 * _tmp42 + _tmp53;\n",
+ " _res_D_state(8, 0) = -_tmp32 * _tmp42 - _tmp54 - _tmp55;\n",
+ " _res_D_state(9, 0) = _tmp56 + _tmp57;\n",
+ " _res_D_state(10, 0) = _tmp0 * _tmp36 - _tmp34 * _tmp42 + _tmp58;\n",
+ " _res_D_state(11, 0) = -_tmp35 * _tmp42 - _tmp59 - _tmp60;\n",
+ " _res_D_state(12, 0) = _tmp61 + _tmp62;\n",
+ " _res_D_state(13, 0) = _tmp0 * _tmp39 - _tmp37 * _tmp42 + _tmp63;\n",
+ " _res_D_state(14, 0) = -_tmp38 * _tmp42 - _tmp64 - _tmp65;\n",
+ " _res_D_state(0, 1) = -_tmp43 + _tmp67 - _tmp68 * state(7, 0);\n",
+ " _res_D_state(1, 1) = _tmp41 + _tmp69;\n",
+ " _res_D_state(2, 1) = _tmp2 * state(8, 0) - _tmp68 * state(9, 0) + _tmp70;\n",
+ " _res_D_state(3, 1) = -_tmp30 * _tmp68 - _tmp48 + _tmp71;\n",
+ " _res_D_state(4, 1) = _tmp47 + _tmp72;\n",
+ " _res_D_state(5, 1) = _tmp2 * _tmp26 - _tmp28 * _tmp68 + _tmp73;\n",
+ " _res_D_state(6, 1) = -_tmp33 * _tmp68 - _tmp53 + _tmp74;\n",
+ " _res_D_state(7, 1) = _tmp52 + _tmp75;\n",
+ " _res_D_state(8, 1) = _tmp2 * _tmp31 - _tmp32 * _tmp68 + _tmp76;\n",
+ " _res_D_state(9, 1) = -_tmp36 * _tmp68 - _tmp58 + _tmp77;\n",
+ " _res_D_state(10, 1) = _tmp57 + _tmp78;\n",
+ " _res_D_state(11, 1) = _tmp2 * _tmp34 - _tmp35 * _tmp68 + _tmp79;\n",
+ " _res_D_state(12, 1) = -_tmp39 * _tmp68 - _tmp63 + _tmp80;\n",
+ " _res_D_state(13, 1) = _tmp62 + _tmp81;\n",
+ " _res_D_state(14, 1) = _tmp2 * _tmp37 - _tmp38 * _tmp68 + _tmp82;\n",
+ " _res_D_state(0, 2) = _tmp45 + _tmp83 - _tmp84 * state(7, 0);\n",
+ " _res_D_state(1, 2) = -_tmp70 - _tmp84 * state(8, 0) + _tmp85;\n",
+ " _res_D_state(2, 2) = _tmp40 + _tmp69;\n",
+ " _res_D_state(3, 2) = -_tmp30 * _tmp84 + _tmp50 + _tmp86;\n",
+ " _res_D_state(4, 2) = -_tmp26 * _tmp84 - _tmp73 + _tmp87;\n",
+ " _res_D_state(5, 2) = _tmp46 + _tmp72;\n",
+ " _res_D_state(6, 2) = -_tmp33 * _tmp84 + _tmp55 + _tmp88;\n",
+ " _res_D_state(7, 2) = -_tmp31 * _tmp84 - _tmp76 + _tmp89;\n",
+ " _res_D_state(8, 2) = _tmp51 + _tmp75;\n",
+ " _res_D_state(9, 2) = -_tmp36 * _tmp84 + _tmp60 + _tmp90;\n",
+ " _res_D_state(10, 2) = -_tmp34 * _tmp84 - _tmp79 + _tmp91;\n",
+ " _res_D_state(11, 2) = _tmp56 + _tmp78;\n",
+ " _res_D_state(12, 2) = -_tmp39 * _tmp84 + _tmp65 + _tmp92;\n",
+ " _res_D_state(13, 2) = -_tmp37 * _tmp84 - _tmp82 + _tmp93;\n",
+ " _res_D_state(14, 2) = _tmp61 + _tmp81;\n",
+ " _res_D_state(0, 3) = -_tmp85 + 2 * state(2, 0) * state(8, 0);\n",
+ " _res_D_state(1, 3) = _tmp44 + _tmp83;\n",
+ " _res_D_state(2, 3) = -_tmp67 + 2 * state(1, 0) * state(7, 0);\n",
+ " _res_D_state(3, 3) = 2 * _tmp26 * state(2, 0) - _tmp87;\n",
+ " _res_D_state(4, 3) = _tmp49 + _tmp86;\n",
+ " _res_D_state(5, 3) = 2 * _tmp30 * state(1, 0) - _tmp71;\n",
+ " _res_D_state(6, 3) = 2 * _tmp31 * state(2, 0) - _tmp89;\n",
+ " _res_D_state(7, 3) = _tmp54 + _tmp88;\n",
+ " _res_D_state(8, 3) = 2 * _tmp33 * state(1, 0) - _tmp74;\n",
+ " _res_D_state(9, 3) = 2 * _tmp34 * state(2, 0) - _tmp91;\n",
+ " _res_D_state(10, 3) = _tmp59 + _tmp90;\n",
+ " _res_D_state(11, 3) = 2 * _tmp36 * state(1, 0) - _tmp77;\n",
+ " _res_D_state(12, 3) = 2 * _tmp37 * state(2, 0) - _tmp93;\n",
+ " _res_D_state(13, 3) = _tmp64 + _tmp92;\n",
+ " _res_D_state(14, 3) = 2 * _tmp39 * state(1, 0) - _tmp80;\n",
+ " _res_D_state(3, 4) = _tmp10;\n",
+ " _res_D_state(4, 4) = _tmp94;\n",
+ " _res_D_state(5, 4) = _tmp95;\n",
+ " _res_D_state(6, 4) = _tmp10;\n",
+ " _res_D_state(7, 4) = _tmp94;\n",
+ " _res_D_state(8, 4) = _tmp95;\n",
+ " _res_D_state(9, 4) = _tmp10;\n",
+ " _res_D_state(10, 4) = _tmp94;\n",
+ " _res_D_state(11, 4) = _tmp95;\n",
+ " _res_D_state(12, 4) = _tmp10;\n",
+ " _res_D_state(13, 4) = _tmp94;\n",
+ " _res_D_state(14, 4) = _tmp95;\n",
+ " _res_D_state(3, 5) = _tmp96;\n",
+ " _res_D_state(4, 5) = _tmp18;\n",
+ " _res_D_state(5, 5) = _tmp21;\n",
+ " _res_D_state(6, 5) = _tmp96;\n",
+ " _res_D_state(7, 5) = _tmp18;\n",
+ " _res_D_state(8, 5) = _tmp21;\n",
+ " _res_D_state(9, 5) = _tmp96;\n",
+ " _res_D_state(10, 5) = _tmp18;\n",
+ " _res_D_state(11, 5) = _tmp21;\n",
+ " _res_D_state(12, 5) = _tmp96;\n",
+ " _res_D_state(13, 5) = _tmp18;\n",
+ " _res_D_state(14, 5) = _tmp21;\n",
+ " _res_D_state(3, 6) = _tmp97;\n",
+ " _res_D_state(4, 6) = _tmp98;\n",
+ " _res_D_state(5, 6) = _tmp23;\n",
+ " _res_D_state(6, 6) = _tmp97;\n",
+ " _res_D_state(7, 6) = _tmp98;\n",
+ " _res_D_state(8, 6) = _tmp23;\n",
+ " _res_D_state(9, 6) = _tmp97;\n",
+ " _res_D_state(10, 6) = _tmp98;\n",
+ " _res_D_state(11, 6) = _tmp23;\n",
+ " _res_D_state(12, 6) = _tmp97;\n",
+ " _res_D_state(13, 6) = _tmp98;\n",
+ " _res_D_state(14, 6) = _tmp23;\n",
+ " _res_D_state(0, 7) = _tmp11;\n",
+ " _res_D_state(1, 7) = _tmp12;\n",
+ " _res_D_state(2, 7) = _tmp20;\n",
+ " _res_D_state(0, 8) = _tmp4;\n",
+ " _res_D_state(1, 8) = _tmp19;\n",
+ " _res_D_state(2, 8) = _tmp22;\n",
+ " _res_D_state(0, 9) = _tmp7;\n",
+ " _res_D_state(1, 9) = _tmp16;\n",
+ " _res_D_state(2, 9) = _tmp24;\n",
+ " _res_D_state(3, 16) = _tmp11;\n",
+ " _res_D_state(4, 16) = _tmp12;\n",
+ " _res_D_state(5, 16) = _tmp20;\n",
+ " _res_D_state(3, 17) = _tmp4;\n",
+ " _res_D_state(4, 17) = _tmp19;\n",
+ " _res_D_state(5, 17) = _tmp22;\n",
+ " _res_D_state(3, 18) = _tmp7;\n",
+ " _res_D_state(4, 18) = _tmp16;\n",
+ " _res_D_state(5, 18) = _tmp24;\n",
+ " _res_D_state(6, 19) = _tmp11;\n",
+ " _res_D_state(7, 19) = _tmp12;\n",
+ " _res_D_state(8, 19) = _tmp20;\n",
+ " _res_D_state(6, 20) = _tmp4;\n",
+ " _res_D_state(7, 20) = _tmp19;\n",
+ " _res_D_state(8, 20) = _tmp22;\n",
+ " _res_D_state(6, 21) = _tmp7;\n",
+ " _res_D_state(7, 21) = _tmp16;\n",
+ " _res_D_state(8, 21) = _tmp24;\n",
+ " _res_D_state(9, 22) = _tmp11;\n",
+ " _res_D_state(10, 22) = _tmp12;\n",
+ " _res_D_state(11, 22) = _tmp20;\n",
+ " _res_D_state(9, 23) = _tmp4;\n",
+ " _res_D_state(10, 23) = _tmp19;\n",
+ " _res_D_state(11, 23) = _tmp22;\n",
+ " _res_D_state(9, 24) = _tmp7;\n",
+ " _res_D_state(10, 24) = _tmp16;\n",
+ " _res_D_state(11, 24) = _tmp24;\n",
+ " _res_D_state(12, 25) = _tmp11;\n",
+ " _res_D_state(13, 25) = _tmp12;\n",
+ " _res_D_state(14, 25) = _tmp20;\n",
+ " _res_D_state(12, 26) = _tmp4;\n",
+ " _res_D_state(13, 26) = _tmp19;\n",
+ " _res_D_state(14, 26) = _tmp22;\n",
+ " _res_D_state(12, 27) = _tmp7;\n",
+ " _res_D_state(13, 27) = _tmp16;\n",
+ " _res_D_state(14, 27) = _tmp24;\n",
+ " }\n",
+ "\n",
+ " return _res;\n",
+ "} // NOLINT(readability/fn_size)\n",
+ "\n",
+ "// NOLINTNEXTLINE(readability/fn_size)\n",
+ "} // namespace sym\n",
+ "
// -----------------------------------------------------------------------------\n",
+ "// This file was autogenerated by symforce from template:\n",
+ "// function/FUNCTION.h.jinja\n",
+ "// Do NOT modify by hand.\n",
+ "// -----------------------------------------------------------------------------\n",
+ "\n",
+ "#pragma once\n",
+ "\n",
+ "#include <Eigen/Dense>\n",
+ "\n",
+ "namespace sym {\n",
+ "\n",
+ "/**\n",
+ " * This function was autogenerated from a symbolic function. Do not modify by hand.\n",
+ " *\n",
+ " * Symbolic function: compute_mean\n",
+ " *\n",
+ " * Args:\n",
+ " * state: Matrix28_1\n",
+ " * u: Matrix61\n",
+ " * dT: Scalar\n",
+ " * epsilon: Scalar\n",
+ " *\n",
+ " * Outputs:\n",
+ " * res: Matrix28_1\n",
+ " * res_D_state: (28x28) jacobian of res (28) wrt arg state (28)\n",
+ " */\n",
+ "template <typename Scalar>\n",
+ "Eigen::Matrix<Scalar, 28, 1> ComputeMeanWithJacobian0(\n",
+ " const Eigen::Matrix<Scalar, 28, 1>& state, const Eigen::Matrix<Scalar, 6, 1>& u,\n",
+ " const Scalar dT, const Scalar epsilon,\n",
+ " Eigen::Matrix<Scalar, 28, 28>* const res_D_state = nullptr) {\n",
+ " // Total ops: 150\n",
+ "\n",
+ " // Unused inputs\n",
+ " (void)epsilon;\n",
+ "\n",
+ " // Input arrays\n",
+ "\n",
+ " // Intermediate terms (49)\n",
+ " const Scalar _tmp0 = dT * (-state(12, 0) + u(2, 0));\n",
+ " const Scalar _tmp1 = dT * (-state(10, 0) + u(0, 0));\n",
+ " const Scalar _tmp2 = dT * (-state(11, 0) + u(1, 0));\n",
+ " const Scalar _tmp3 = -state(14, 0) + u(4, 0);\n",
+ " const Scalar _tmp4 = 2 * state(1, 0);\n",
+ " const Scalar _tmp5 = _tmp4 * state(0, 0);\n",
+ " const Scalar _tmp6 = 2 * state(2, 0);\n",
+ " const Scalar _tmp7 = _tmp6 * state(3, 0);\n",
+ " const Scalar _tmp8 = _tmp5 - _tmp7;\n",
+ " const Scalar _tmp9 = -state(15, 0) + u(5, 0);\n",
+ " const Scalar _tmp10 = _tmp6 * state(0, 0);\n",
+ " const Scalar _tmp11 = _tmp4 * state(3, 0);\n",
+ " const Scalar _tmp12 = _tmp10 + _tmp11;\n",
+ " const Scalar _tmp13 = -state(13, 0) + u(3, 0);\n",
+ " const Scalar _tmp14 = 2 * std::pow(state(1, 0), Scalar(2));\n",
+ " const Scalar _tmp15 = 2 * std::pow(state(2, 0), Scalar(2)) - 1;\n",
+ " const Scalar _tmp16 = _tmp14 + _tmp15;\n",
+ " const Scalar _tmp17 = _tmp5 + _tmp7;\n",
+ " const Scalar _tmp18 = 2 * state(3, 0);\n",
+ " const Scalar _tmp19 = _tmp18 * state(0, 0);\n",
+ " const Scalar _tmp20 = _tmp6 * state(1, 0);\n",
+ " const Scalar _tmp21 = _tmp19 - _tmp20;\n",
+ " const Scalar _tmp22 = 2 * std::pow(state(0, 0), Scalar(2));\n",
+ " const Scalar _tmp23 = _tmp15 + _tmp22;\n",
+ " const Scalar _tmp24 = _tmp10 - _tmp11;\n",
+ " const Scalar _tmp25 = _tmp19 + _tmp20;\n",
+ " const Scalar _tmp26 = _tmp14 + _tmp22 - 1;\n",
+ " const Scalar _tmp27 = -_tmp0;\n",
+ " const Scalar _tmp28 = -_tmp1;\n",
+ " const Scalar _tmp29 = _tmp3 * _tmp4;\n",
+ " const Scalar _tmp30 = _tmp6 * _tmp9;\n",
+ " const Scalar _tmp31 = 4 * state(0, 0);\n",
+ " const Scalar _tmp32 = -_tmp13 * _tmp4;\n",
+ " const Scalar _tmp33 = _tmp18 * _tmp9;\n",
+ " const Scalar _tmp34 = _tmp18 * _tmp3;\n",
+ " const Scalar _tmp35 = -_tmp2;\n",
+ " const Scalar _tmp36 = 2 * state(0, 0);\n",
+ " const Scalar _tmp37 = _tmp3 * _tmp36;\n",
+ " const Scalar _tmp38 = 4 * state(1, 0);\n",
+ " const Scalar _tmp39 = _tmp13 * _tmp36;\n",
+ " const Scalar _tmp40 = -_tmp3 * _tmp6;\n",
+ " const Scalar _tmp41 = _tmp13 * _tmp18;\n",
+ " const Scalar _tmp42 = _tmp36 * _tmp9;\n",
+ " const Scalar _tmp43 = 4 * state(2, 0);\n",
+ " const Scalar _tmp44 = _tmp4 * _tmp9;\n",
+ " const Scalar _tmp45 = -dT * state(3, 0);\n",
+ " const Scalar _tmp46 = dT * state(2, 0);\n",
+ " const Scalar _tmp47 = dT * state(1, 0);\n",
+ " const Scalar _tmp48 = dT * state(0, 0);\n",
+ "\n",
+ " // Output terms (2)\n",
+ " Eigen::Matrix<Scalar, 28, 1> _res;\n",
+ "\n",
+ " _res(0, 0) =\n",
+ " _tmp0 * state(1, 0) + _tmp1 * state(3, 0) - _tmp2 * state(2, 0) + Scalar(1.0) * state(0, 0);\n",
+ " _res(1, 0) =\n",
+ " -_tmp0 * state(0, 0) + _tmp1 * state(2, 0) + _tmp2 * state(3, 0) + Scalar(1.0) * state(1, 0);\n",
+ " _res(2, 0) =\n",
+ " _tmp0 * state(3, 0) - _tmp1 * state(1, 0) + _tmp2 * state(0, 0) + Scalar(1.0) * state(2, 0);\n",
+ " _res(3, 0) =\n",
+ " -_tmp0 * state(2, 0) - _tmp1 * state(0, 0) - _tmp2 * state(1, 0) + Scalar(1.0) * state(3, 0);\n",
+ " _res(4, 0) = dT * state(7, 0) + state(4, 0);\n",
+ " _res(5, 0) = dT * state(8, 0) + state(5, 0);\n",
+ " _res(6, 0) = dT * state(9, 0) + state(6, 0);\n",
+ " _res(7, 0) = _tmp12 * _tmp9 - _tmp13 * _tmp16 + _tmp3 * _tmp8 + state(7, 0);\n",
+ " _res(8, 0) = _tmp13 * _tmp17 - _tmp21 * _tmp9 - _tmp23 * _tmp3 + state(8, 0);\n",
+ " _res(9, 0) =\n",
+ " _tmp13 * _tmp24 + _tmp25 * _tmp3 - _tmp26 * _tmp9 + state(9, 0) + Scalar(9.8000000000000007);\n",
+ " _res(10, 0) = state(10, 0);\n",
+ " _res(11, 0) = state(11, 0);\n",
+ " _res(12, 0) = state(12, 0);\n",
+ " _res(13, 0) = state(13, 0);\n",
+ " _res(14, 0) = state(14, 0);\n",
+ " _res(15, 0) = state(15, 0);\n",
+ " _res(16, 0) = state(16, 0);\n",
+ " _res(17, 0) = state(17, 0);\n",
+ " _res(18, 0) = state(18, 0);\n",
+ " _res(19, 0) = state(19, 0);\n",
+ " _res(20, 0) = state(20, 0);\n",
+ " _res(21, 0) = state(21, 0);\n",
+ " _res(22, 0) = state(22, 0);\n",
+ " _res(23, 0) = state(23, 0);\n",
+ " _res(24, 0) = state(24, 0);\n",
+ " _res(25, 0) = state(25, 0);\n",
+ " _res(26, 0) = state(26, 0);\n",
+ " _res(27, 0) = state(27, 0);\n",
+ "\n",
+ " if (res_D_state != nullptr) {\n",
+ " Eigen::Matrix<Scalar, 28, 28>& _res_D_state = (*res_D_state);\n",
+ "\n",
+ " _res_D_state.setZero();\n",
+ "\n",
+ " _res_D_state(0, 0) = Scalar(1.0);\n",
+ " _res_D_state(1, 0) = _tmp27;\n",
+ " _res_D_state(2, 0) = _tmp2;\n",
+ " _res_D_state(3, 0) = _tmp28;\n",
+ " _res_D_state(7, 0) = _tmp29 + _tmp30;\n",
+ " _res_D_state(8, 0) = -_tmp3 * _tmp31 - _tmp32 - _tmp33;\n",
+ " _res_D_state(9, 0) = _tmp13 * _tmp6 - _tmp31 * _tmp9 + _tmp34;\n",
+ " _res_D_state(0, 1) = _tmp0;\n",
+ " _res_D_state(1, 1) = Scalar(1.0);\n",
+ " _res_D_state(2, 1) = _tmp28;\n",
+ " _res_D_state(3, 1) = _tmp35;\n",
+ " _res_D_state(7, 1) = -_tmp13 * _tmp38 + _tmp33 + _tmp37;\n",
+ " _res_D_state(8, 1) = _tmp30 + _tmp39;\n",
+ " _res_D_state(9, 1) = -_tmp38 * _tmp9 - _tmp40 - _tmp41;\n",
+ " _res_D_state(0, 2) = _tmp35;\n",
+ " _res_D_state(1, 2) = _tmp1;\n",
+ " _res_D_state(2, 2) = Scalar(1.0);\n",
+ " _res_D_state(3, 2) = _tmp27;\n",
+ " _res_D_state(7, 2) = -_tmp13 * _tmp43 - _tmp34 + _tmp42;\n",
+ " _res_D_state(8, 2) = -_tmp3 * _tmp43 + _tmp41 + _tmp44;\n",
+ " _res_D_state(9, 2) = _tmp29 + _tmp39;\n",
+ " _res_D_state(0, 3) = _tmp1;\n",
+ " _res_D_state(1, 3) = _tmp2;\n",
+ " _res_D_state(2, 3) = _tmp0;\n",
+ " _res_D_state(3, 3) = Scalar(1.0);\n",
+ " _res_D_state(7, 3) = _tmp40 + _tmp44;\n",
+ " _res_D_state(8, 3) = 2 * _tmp13 * state(2, 0) - _tmp42;\n",
+ " _res_D_state(9, 3) = _tmp32 + _tmp37;\n",
+ " _res_D_state(4, 4) = 1;\n",
+ " _res_D_state(5, 5) = 1;\n",
+ " _res_D_state(6, 6) = 1;\n",
+ " _res_D_state(4, 7) = dT;\n",
+ " _res_D_state(7, 7) = 1;\n",
+ " _res_D_state(5, 8) = dT;\n",
+ " _res_D_state(8, 8) = 1;\n",
+ " _res_D_state(6, 9) = dT;\n",
+ " _res_D_state(9, 9) = 1;\n",
+ " _res_D_state(0, 10) = _tmp45;\n",
+ " _res_D_state(1, 10) = -_tmp46;\n",
+ " _res_D_state(2, 10) = _tmp47;\n",
+ " _res_D_state(3, 10) = _tmp48;\n",
+ " _res_D_state(10, 10) = 1;\n",
+ " _res_D_state(0, 11) = _tmp46;\n",
+ " _res_D_state(1, 11) = _tmp45;\n",
+ " _res_D_state(2, 11) = -_tmp48;\n",
+ " _res_D_state(3, 11) = _tmp47;\n",
+ " _res_D_state(11, 11) = 1;\n",
+ " _res_D_state(0, 12) = -_tmp47;\n",
+ " _res_D_state(1, 12) = _tmp48;\n",
+ " _res_D_state(2, 12) = _tmp45;\n",
+ " _res_D_state(3, 12) = _tmp46;\n",
+ " _res_D_state(12, 12) = 1;\n",
+ " _res_D_state(7, 13) = _tmp16;\n",
+ " _res_D_state(8, 13) = -_tmp17;\n",
+ " _res_D_state(9, 13) = -_tmp24;\n",
+ " _res_D_state(13, 13) = 1;\n",
+ " _res_D_state(7, 14) = -_tmp8;\n",
+ " _res_D_state(8, 14) = _tmp23;\n",
+ " _res_D_state(9, 14) = -_tmp25;\n",
+ " _res_D_state(14, 14) = 1;\n",
+ " _res_D_state(7, 15) = -_tmp12;\n",
+ " _res_D_state(8, 15) = _tmp21;\n",
+ " _res_D_state(9, 15) = _tmp26;\n",
+ " _res_D_state(15, 15) = 1;\n",
+ " _res_D_state(16, 16) = 1;\n",
+ " _res_D_state(17, 17) = 1;\n",
+ " _res_D_state(18, 18) = 1;\n",
+ " _res_D_state(19, 19) = 1;\n",
+ " _res_D_state(20, 20) = 1;\n",
+ " _res_D_state(21, 21) = 1;\n",
+ " _res_D_state(22, 22) = 1;\n",
+ " _res_D_state(23, 23) = 1;\n",
+ " _res_D_state(24, 24) = 1;\n",
+ " _res_D_state(25, 25) = 1;\n",
+ " _res_D_state(26, 26) = 1;\n",
+ " _res_D_state(27, 27) = 1;\n",
+ " }\n",
+ "\n",
+ " return _res;\n",
+ "} // NOLINT(readability/fn_size)\n",
+ "\n",
+ "// NOLINTNEXTLINE(readability/fn_size)\n",
+ "} // namespace sym\n",
+ "