32 #include <std_msgs/Int32.h> 36 #include <xpp_msgs/TerrainInfo.h> 60 solver_ = std::make_shared<ifopt::IpoptSolver>();
102 std::string bag_file =
"towr_trajectory.bag";
103 if (msg.optimize || msg.play_initialization) {
117 if (msg.replay_trajectory || msg.play_initialization || msg.optimize) {
118 int success = system((
"rosbag play --topics " 121 +
" -r " + std::to_string(msg.replay_speed)
122 +
" --quiet " + bag_file).c_str());
125 if (msg.plot_trajectory) {
126 int success = system((
"killall rqt_bag; rqt_bag " + bag_file +
"&").c_str());
141 for (
int ee_towr=0; ee_towr<n_ee; ++ee_towr) {
151 std::vector<TowrRosInterface::XppVec>
154 std::vector<XppVec> trajectories;
183 for (
int ee_towr=0; ee_towr<n_ee; ++ee_towr) {
192 trajectory.push_back(state);
199 xpp_msgs::RobotParameters
202 xpp_msgs::RobotParameters params_msg;
203 auto max_dev_xyz = model.
kinematic_model_->GetMaximumDeviationFromNominal();
204 params_msg.ee_max_dev = xpp::Convert::ToRos<geometry_msgs::Vector3>(max_dev_xyz);
207 int n_ee = nominal_B.size();
208 for (
int ee_towr=0; ee_towr<n_ee; ++ee_towr) {
209 Vector3d pos = nominal_B.at(ee_towr);
210 params_msg.nominal_ee_pos.push_back(xpp::Convert::ToRos<geometry_msgs::Point>(pos));
221 const xpp_msgs::RobotParameters& robot_params,
223 bool include_iterations)
234 if (include_iterations) {
236 int n_iterations = trajectories.size();
237 for (
int i=0; i<n_iterations; ++i)
242 m.data = n_iterations;
256 const std::string& topic)
const 258 for (
const auto state : traj) {
259 auto timestamp =
::ros::Time(state.t_global_ + 1e-6);
261 xpp_msgs::RobotStateCartesian msg;
263 bag.
write(topic, timestamp, msg);
265 xpp_msgs::TerrainInfo terrain_msg;
266 for (
auto ee : state.ee_motion_.ToImpl()) {
268 terrain_msg.surface_normals.push_back(xpp::Convert::ToRos<geometry_msgs::Vector3>(n));
DynamicModel::Ptr dynamic_model_
void SetOptVariables(int iter)
int GetIterationCount() const
static xpp_msgs::StateLin3d ToRos(const StateLin3d &xpp)
towr_ros::TowrCommand TowrCommandMsg
void AddCostSet(CostTerm::Ptr cost_set)
void publish(const boost::shared_ptr< M > &message) const
bool & at(EndeffectorID ee)
void open(std::string const &filename, uint32_t mode=bagmode::Read)
static const std::string robot_state_desired("/xpp/state_des")
const VectorXd at(Dx deriv) const
Subscriber subscribe(const std::string &topic, uint32_t queue_size, void(T::*fp)(M), T *obj, const TransportHints &transport_hints=TransportHints())
std::vector< xpp::RobotStateCartesian > XppVec
std::vector< PhaseDurations::Ptr > phase_durations_
::ros::Publisher initial_state_pub_
::ros::Subscriber user_command_sub_
static const std::string nlp_iterations_count("/towr/nlp_iterations_count")
double visualization_dt_
duration between two rviz visualization states.
EndeffectorsMotion ee_motion_
virtual Parameters GetTowrParameters(int n_ee, const TowrCommandMsg &msg) const =0
Formulates the actual TOWR problem to be solved.
static HeightMap::Ptr MakeTerrain(TerrainID type)
ifopt::IpoptSolver::Ptr solver_
NLP solver, could also use SNOPT.
virtual void SetTowrInitialState()=0
Sets the base state and end-effector position.
static const std::string nlp_iterations_name("/towr/nlp_iterations_name")
geometry_msgs::TransformStamped t
Vector3d GetAngularAccelerationInWorld(double t) const
NodeSpline::Ptr base_linear_
void UserCommandCallback(const TowrCommandMsg &msg)
void PublishInitialState()
static std::pair< xpp::EndeffectorID, std::string > ToXppEndeffector(int number_of_ee, int towr_ee_id)
std::vector< NodeSpline::Ptr > ee_force_
XppVec GetTrajectory() const
Eigen::Quaterniond GetQuaternionBaseToWorld(double t) const
Publisher advertise(const std::string &topic, uint32_t queue_size, bool latch=false)
NodeSpline::Ptr base_angular_
virtual BaseState GetGoalState(const TowrCommandMsg &msg) const
Vector3d GetAngularVelocityInWorld(double t) const
::ros::Publisher robot_parameters_pub_
SplineHolder solution
the solution splines linked to the opt-variables.
xpp_msgs::RobotParameters BuildRobotParametersMsg(const RobotModel &model) const
ifopt::Problem nlp_
the actual nonlinear program to be solved.
std::vector< XppVec > GetIntermediateSolutions()
void AddConstraintSet(ConstraintSet::Ptr constraint_set)
static const std::string user_command("/towr/user_command")
static xpp::StateLinXd ToXpp(const towr::State &towr)
void SaveOptimizationAsRosbag(const std::string &bag_name, const xpp_msgs::RobotParameters &robot_params, const TowrCommandMsg user_command_msg, bool include_iterations=false)
void SaveTrajectoryInRosbag(rosbag::Bag &, const std::vector< xpp::RobotStateCartesian > &traj, const std::string &topic) const
KinematicModel::Ptr kinematic_model_
void AddVariableSet(VariableSet::Ptr variable_set)
void write(std::string const &topic, ros::MessageEvent< T > const &event)
static const std::string terrain_info("/xpp/terrain_info")
std::vector< NodeSpline::Ptr > ee_motion_
NlpFormulation formulation_
the default formulation, can be adapted
static const std::string robot_parameters("/xpp/params")
Endeffectors< Vector3d > ee_forces_
EndeffectorsContact ee_contact_
static StateLin3d ToXpp(const xpp_msgs::StateLin3d &ros)
virtual void SetIpoptParameters(const TowrCommandMsg &msg)=0
Sets the parameters of the nonlinear programming solver IPOPT.