goal_pose_publisher.cc
Go to the documentation of this file.
00001 /******************************************************************************
00002 Copyright (c) 2018, Alexander W. Winkler. All rights reserved.
00003 
00004 Redistribution and use in source and binary forms, with or without
00005 modification, are permitted provided that the following conditions are met:
00006 
00007 * Redistributions of source code must retain the above copyright notice, this
00008   list of conditions and the following disclaimer.
00009 
00010 * Redistributions in binary form must reproduce the above copyright notice,
00011   this list of conditions and the following disclaimer in the documentation
00012   and/or other materials provided with the distribution.
00013 
00014 * Neither the name of the copyright holder nor the names of its
00015   contributors may be used to endorse or promote products derived from
00016   this software without specific prior written permission.
00017 
00018 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00019 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00020 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00021 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
00022 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00023 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
00024 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00025 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
00026 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00027 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00028 ******************************************************************************/
00029 
00030 #include <ros/ros.h>
00031 #include <geometry_msgs/PoseStamped.h>
00032 
00033 #include <towr/terrain/height_map.h>
00034 #include <xpp_states/convert.h>
00035 
00036 #include <towr_ros/TowrCommand.h>  // listen to goal state
00037 #include <towr_ros/topic_names.h>
00038 
00039 
00040 namespace towr {
00041 
00042 static ros::Publisher rviz_pub;
00043 
00044 void UserCommandCallback(const towr_ros::TowrCommand& msg_in)
00045 {
00046   // get which terrain
00047   auto terrain_id = static_cast<HeightMap::TerrainID>(msg_in.terrain);
00048   auto terrain_ = HeightMap::MakeTerrain(terrain_id);
00049 
00050   geometry_msgs::PoseStamped goal_msg;
00051   goal_msg.header.frame_id = "world";
00052 
00053   // visualize goal z state on terrain.
00054   double x = msg_in.goal_lin.pos.x;
00055   double y = msg_in.goal_lin.pos.y;
00056   goal_msg.pose.position.x = x;
00057   goal_msg.pose.position.y = y;
00058   goal_msg.pose.position.z = terrain_->GetHeight(x, y);
00059 
00060   // orientation according to message
00061   Eigen::Quaterniond q = xpp::GetQuaternionFromEulerZYX(msg_in.goal_ang.pos.z,
00062                                                         msg_in.goal_ang.pos.y,
00063                                                         msg_in.goal_ang.pos.x);
00064   goal_msg.pose.orientation = xpp::Convert::ToRos(q);
00065   rviz_pub.publish(goal_msg);
00066 }
00067 
00068 } // namespace towr
00069 
00070 int main(int argc, char *argv[])
00071 {
00072   ros::init(argc, argv, "goal_pose_publisher");
00073 
00074   ros::NodeHandle n;
00075 
00076   ros::Subscriber goal_sub;
00077   goal_sub       = n.subscribe(towr_msgs::user_command, 1, towr::UserCommandCallback);
00078   towr::rviz_pub = n.advertise<geometry_msgs::PoseStamped>("xpp/goal", 1);
00079 
00080   ros::spin();
00081 
00082   return 1;
00083 }


towr_ros
Author(s): Alexander W. Winkler
autogenerated on Mon Apr 15 2019 02:42:39