Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implemented a SetLocalPosition Service #259

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ros/src/fs_msgs
7 changes: 7 additions & 0 deletions ros/src/fsds_ros_bridge/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,13 @@ find_package(catkin REQUIRED COMPONENTS
fs_msgs
)

add_service_files(
FILES
SetLocalPosition.srv
)

generate_messages()

catkin_package(
INCLUDE_DIRS include
# LIBRARIES airsim_ros
Expand Down
4 changes: 4 additions & 0 deletions ros/src/fsds_ros_bridge/include/airsim_ros_wrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@ STRICT_MODE_OFF //todo what does this do?
#include "statistics.h"
#include "common/AirSimSettings.hpp"
#include "common/common_utils/FileSystem.hpp"
#include "common/VectorMath.hpp"
#include "ros/ros.h"
#include "sensors/imu/ImuBase.hpp"
#include "vehicles/car/api/CarRpcLibClient.hpp"
#include "yaml-cpp/yaml.h"
#include <fs_msgs/ControlCommand.h>
#include <fs_msgs/Reset.h>
#include <fsds_ros_bridge/SetLocalPosition.h>
#include <fs_msgs/GoSignal.h>
#include <fs_msgs/FinishedSignal.h>
#include <fs_msgs/Track.h>
Expand Down Expand Up @@ -137,6 +139,7 @@ class AirsimROSWrapper

/// ROS service callbacks
bool reset_srv_cb(fs_msgs::Reset::Request& request, fs_msgs::Reset::Response& response);
bool set_local_position_srv_cb(fsds_ros_bridge::SetLocalPosition::Request& request, fsds_ros_bridge::SetLocalPosition::Response& response);

// methods which parse setting json ang generate ros pubsubsrv
void create_ros_pubs_from_settings_json();
Expand All @@ -163,6 +166,7 @@ class AirsimROSWrapper

private:
ros::ServiceServer reset_srvr_;
ros::ServiceServer set_local_position_srvr;

std::string vehicle_name;
CarApiBase::Point2D car_start_pos; // In Unreal coordinates
Expand Down
10 changes: 10 additions & 0 deletions ros/src/fsds_ros_bridge/src/airsim_ros_wrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,7 @@ void AirsimROSWrapper::create_ros_pubs_from_settings_json()
}

reset_srvr_ = nh_.advertiseService("reset", &AirsimROSWrapper::reset_srv_cb, this);
set_local_position_srvr = nh_.advertiseService("set_local_position", &AirsimROSWrapper::set_local_position_srv_cb, this);

initialize_airsim();
}
Expand All @@ -281,6 +282,15 @@ bool AirsimROSWrapper::reset_srv_cb(fs_msgs::Reset::Request& request, fs_msgs::R
return true; //todo
}

bool AirsimROSWrapper::set_local_position_srv_cb(fsds_ros_bridge::SetLocalPosition::Request& request, fsds_ros_bridge::SetLocalPosition::Response& response)
{
auto quaternion = msr::airlib::VectorMathf::toQuaternion(0, 0, request.yaw * M_PI / 180);
msr::airlib::Vector3r vec3r {request.x, request.y, request.z};

airsim_client_.simSetVehiclePose(msr::airlib::Pose {vec3r, quaternion}, true, "FSCar");
return true;
}

tf2::Quaternion AirsimROSWrapper::get_tf2_quat(const msr::airlib::Quaternionr& airlib_quat) const
{
return tf2::Quaternion(airlib_quat.x(), airlib_quat.y(), airlib_quat.z(), airlib_quat.w());
Expand Down
9 changes: 4 additions & 5 deletions ros/src/fsds_ros_bridge/srv/SetLocalPosition.srv
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
#Request : expects position setpoint via x, y, z
#Request : expects yaw setpoint via yaw (send yaw_valid=true)
float64 x
float64 y
float64 z
float64 yaw
string vehicle_name
float32 x
float32 y
float32 z
float32 yaw # in degree
---
#Response : success=true - (if async=false && if setpoint reached before timeout = 30sec) || (if async=true)
bool success
Expand Down