Skip to content

Commit

Permalink
Updates README.md to include RobotInterface
Browse files Browse the repository at this point in the history
  • Loading branch information
ethanmusser committed Aug 3, 2022
1 parent 3956561 commit 4b9c6b3
Showing 1 changed file with 48 additions and 11 deletions.
59 changes: 48 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,36 @@ for better realtime performance
the easy creation of new controllers
5. The `MjbotsRobotInterface` which provides a convenient interface for communicating with any number
of moteus motor controllers
6. The `RobotInterface` which provides and interface for updating robot state and joint torques.

Note: This library only supports torque commands. If you wish to use
position control, you either must close the loop yourself or modify the
library to allow for the position loop to Run on the moteus.

#Important
# Important
In order to keep the message size down, kp and kd on the motors must be set to 0

# Usage

## MjbotsControlLoop:
To use the `MjbotsControlLoop` create a class which inherits the `MjbotsControlLoop`
and implements `CalcTorques` to set the torques in the robot object.
To use the Mjbots control loop, create a class which inherits the
`MjbotsControlLoop` object and implements `CalcTorques` to set the torques in
the robot object as follows.

class Controller : public MjbotsControlLoop{
using MjbotsControlLoop::MjbotsControlLoop;
void CalcTorques() override{
std::vector<float> torques = control_effort;
robot_->SetTorques(torques);
}
};
```cpp
class SimpleRobotControlLoop : public kodlab::mjbots::MjbotsControlLoop
using MjbotsControlLoop::MjbotsControlLoop;
void CalcTorques() override{
std::vector<float> torques = control_effort;
robot_->SetTorques(torques);
}
};
```
A simple example using the `MjbotsControlLoop` is provided in
`examples/spint_joints_example.cpp`. The `MjbotsControlLoop` is optionally templated with an LCM
log type, an LCM input type, and a `RobotInterface`-derived class. These are
described below.
## Accessing robot state
To access the robot state use `robot_->GetJointPositions()` or `robot_->GetJointVelocities()`
Expand All @@ -52,7 +62,8 @@ Finally when creating the instance of the class set the `log_channel_name` optio
options.log_channel_name = "example";
Controller control_loop(options)
To log data, on your laptop Start the bot lcm tunnel with `bot-lcm-tunnel <IP>` and Start logging using `lcm-logger`
To log data, on your laptop Start the bot lcm tunnel with `bot-lcm-tunnel <IP>` and Start logging using `lcm-logger`.
Refer again to `examples/spint_joints_example.cpp` for an example implementation.

This comment has been minimized.

Copy link
@jdcaporale

jdcaporale Aug 3, 2022

Contributor

typo spin_joints_example...

## Input LCM Communication
In order to set gains during run time or to communicate between your laptop and the robot, first define the LCM data
Expand All @@ -67,6 +78,32 @@ Next, implement the `ProcessInput` function to do things with the data in `lcm_s
gains_ = lcm_sub_.data_.gains;
}
## Robot Interface
The `RobotInterface` object is intended to be inherited by a user-defined robot
class. The derived class should implement an override of
`RobotInterface::Update()`. Note that this new `Update()` function must
increment the cycle count. A simple implementation follows.
```cpp
class MyRobot : virtual public kodlab::RobotInterface
{
using kodlab::RobotInterface::RobotInterface;
public:
int mode = 0; // Member variables encode whatever added state we need
// Set up robot update function for state and torques
void Update() override
{
cycle_count_++;
std::vector<float> torques(num_joints_, 0);
SetTorques(torques);
}
};
```

Refer to `include/examples/simple_robot.h` for a sample robot class and
`examples/robot_example.cpp` for a usage example.

## Soft Start
To configure the soft Start, set the `options.max_torque` and `options.soft_start_duration`. Where the
max torque is the maximum torque per motor and the soft Start duration is how long the torque ramp should last
Expand Down

0 comments on commit 4b9c6b3

Please sign in to comment.