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

Real and simulator #113

Open
wants to merge 36 commits into
base: add_gnssnav
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
e2d2f1d
Update README.md
HarukiOgawa1 Apr 29, 2024
ace424e
Update README.md
HarukiOgawa1 May 1, 2024
97290f5
🐛fix:パラメータなどの仕様の修正
Aug 20, 2024
3c52fb6
🐛fix:角速度計算アルゴリズムの修正
Aug 20, 2024
f308333
✨feat:配線図
Aug 21, 2024
c842f9d
🐛fix:ament_export_dependenciesなど推奨されているものを使用する
Aug 21, 2024
a6fd54f
Merge branch 'deploy'
Aug 27, 2024
976eb70
Merge branch 'deploy' into feature/chassis
Aug 27, 2024
3a435a7
Merge branch 'deploy' into feat/gnssnav_refactoring
Aug 27, 2024
f992983
🐛fix: gnss_navigation_old削除
kyo0221 Aug 27, 2024
2e7c990
Merge branch 'deploy' into feat/gnssnav_develop
kyo0221 Aug 27, 2024
a6856ae
🐛fix: rm zedx_image_publisher
kyo0221 Aug 27, 2024
82499e1
🐛fix:角度補正する場所の変更
Aug 29, 2024
174ec0b
Merge pull request #100 from open-rdc/feat/gnssnav_refactoring
kyo0221 Aug 29, 2024
091654b
✨feat:log levelのargmentを設定できるようにした
Aug 29, 2024
ff2d522
✨feat:vectornav/poseの再現
Aug 29, 2024
fd14f0b
Merge remote-tracking branch 'origin/main' into feat/gnssnav_develop
kyo0221 Sep 3, 2024
f89c8bd
Merge remote-tracking branch 'origin/feat/vectornav_sim' into feat/gn…
kyo0221 Sep 3, 2024
ee482c9
✨feat: ステアリング制御を変更
kyo0221 Sep 9, 2024
8f749e2
Merge branch 'feat/gnssnav_develop' of https://github.com/open-rdc/AI…
kyo0221 Sep 9, 2024
022fe78
Merge remote-tracking branch 'origin/feat/gnssnav_refactoring' into f…
Sep 9, 2024
ef29937
✨feat:速度計画機
Sep 9, 2024
9824372
✨feat:新しい駆動輪角速度計算
Sep 9, 2024
cc3b2bc
add simulation launch
yasuohayashibara Sep 10, 2024
b430570
fix:testrun
rdclab Sep 10, 2024
ed2b827
Merge branch 'feature/chassis' into feat/gnssnav_develop
rdclab Sep 10, 2024
53a33d3
revert main.cpp
yasuohayashibara Sep 10, 2024
118b030
fix:utm converter
rdclab Sep 10, 2024
574e48f
Merge branch 'feat/gnssnav_develop' of https://github.com/open-rdc/AI…
rdclab Sep 10, 2024
ddc5159
param
rdclab Sep 10, 2024
c0245d1
✨feat: csv追加
kyo0221 Sep 10, 2024
30452af
Merge branch 'feat/gnssnav_develop' of https://github.com/open-rdc/AI…
kyo0221 Sep 10, 2024
ec66194
rm cource
rdclab Sep 10, 2024
fbdbd50
✨feat: bagからcsvファイルを作成するスクリプト
kyo0221 Sep 10, 2024
5a1e593
merge feat/gnssnav_develop
yasuohayashibara Sep 10, 2024
a4aae9e
default parameters
yasuohayashibara Sep 10, 2024
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
18 changes: 9 additions & 9 deletions roboteq_driver/CMakeLists.txt → chassis_driver/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
cmake_minimum_required(VERSION 3.8)
project(roboteq_driver)
project(chassis_driver)

if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
add_compile_options(-Wall -Wextra -Wpedantic)
Expand All @@ -14,12 +14,12 @@ find_package(geometry_msgs REQUIRED)
find_package(socketcan_interface_msg REQUIRED)
find_package(utilities REQUIRED)

add_library(roboteq_driver_node src/roboteq_driver_node.cpp)
target_compile_features(roboteq_driver_node PUBLIC c_std_99 cxx_std_17) # Require C99 and C++17
target_include_directories(roboteq_driver_node PUBLIC
add_library(chassis_driver_node src/chassis_driver_node.cpp)
target_compile_features(chassis_driver_node PUBLIC c_std_99 cxx_std_17) # Require C99 and C++17
target_include_directories(chassis_driver_node PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>)
ament_target_dependencies(roboteq_driver_node
ament_target_dependencies(chassis_driver_node
rclcpp
std_msgs
geometry_msgs
Expand All @@ -29,7 +29,7 @@ ament_target_dependencies(roboteq_driver_node

# 実行可能ノード
add_executable(debug_printer
src/debug_printer
src/debug_printer.cpp
)
target_include_directories(debug_printer PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
Expand All @@ -43,14 +43,14 @@ ament_target_dependencies(debug_printer

# Causes the visibility macros to use dllexport rather than dllimport,
# which is appropriate when building the dll but not consuming it.
target_compile_definitions(roboteq_driver_node PRIVATE "ROBOTEQ_DRIVER_BUILDING_LIBRARY")
target_compile_definitions(chassis_driver_node PRIVATE "CHASSIS_DRIVER_BUILDING_LIBRARY")

install(
DIRECTORY include/
DESTINATION include
)
install(
TARGETS roboteq_driver_node
TARGETS chassis_driver_node
EXPORT export_${PROJECT_NAME}
ARCHIVE DESTINATION lib
LIBRARY DESTINATION lib
Expand All @@ -77,7 +77,7 @@ ament_export_include_directories(
include
)
ament_export_libraries(
roboteq_driver_node
chassis_driver_node
)
ament_export_targets(
export_${PROJECT_NAME}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,23 @@

#include <rclcpp/rclcpp.hpp>
#include <geometry_msgs/msg/twist.hpp>
#include <geometry_msgs/msg/twist_stamped.hpp>
#include <std_msgs/msg/empty.hpp>
#include <std_msgs/msg/float64.hpp>
#include "socketcan_interface_msg/msg/socketcan_if.hpp"
#include "utilities/velplanner.hpp"

#include "roboteq_driver/visibility_control.h"
#include "chassis_driver/visibility_control.h"

namespace roboteq_driver{
namespace chassis_driver{

class RoboteqDriver : public rclcpp::Node {
class ChassisDriver : public rclcpp::Node {
public:
ROBOTEQ_DRIVER_PUBLIC
explicit RoboteqDriver(const rclcpp::NodeOptions& options = rclcpp::NodeOptions());
CHASSIS_DRIVER_PUBLIC
explicit ChassisDriver(const rclcpp::NodeOptions& options = rclcpp::NodeOptions());

ROBOTEQ_DRIVER_PUBLIC
explicit RoboteqDriver(const std::string& name_space, const rclcpp::NodeOptions& options = rclcpp::NodeOptions());
CHASSIS_DRIVER_PUBLIC
explicit ChassisDriver(const std::string& name_space, const rclcpp::NodeOptions& options = rclcpp::NodeOptions());

private:
rclcpp::Subscription<geometry_msgs::msg::Twist>::SharedPtr _subscription_vel;
Expand All @@ -36,9 +38,17 @@ class RoboteqDriver : public rclcpp::Node {

rclcpp::Publisher<socketcan_interface_msg::msg::SocketcanIF>::SharedPtr publisher_can;
rclcpp::Publisher<std_msgs::msg::Float64>::SharedPtr publisher_steer;
rclcpp::Publisher<geometry_msgs::msg::TwistStamped>::SharedPtr publisher_ref_vel;

rclcpp::QoS _qos = rclcpp::QoS(10);


// 速度計画機
velplanner::VelPlanner linear_planner;
const velplanner::Limit linear_limit;
velplanner::VelPlanner angular_planner;
const velplanner::Limit angular_limit;

// 定数
const int interval_ms;
const double wheel_radius;
Expand All @@ -48,9 +58,6 @@ class RoboteqDriver : public rclcpp::Node {
const bool is_reverse_left;
const bool is_reverse_right;

// 制御
std::shared_ptr<geometry_msgs::msg::Twist> vel;

// 動作モード
enum class Mode{
cmd,
Expand All @@ -60,4 +67,4 @@ class RoboteqDriver : public rclcpp::Node {

};

} // namespace roboteq_driver
} // namespace chassis_driver
35 changes: 35 additions & 0 deletions chassis_driver/include/chassis_driver/visibility_control.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#ifndef CHASSIS_DRIVER__VISIBILITY_CONTROL_H_
#define CHASSIS_DRIVER__VISIBILITY_CONTROL_H_

// This logic was borrowed (then namespaced) from the examples on the gcc wiki:
// https://gcc.gnu.org/wiki/Visibility

#if defined _WIN32 || defined __CYGWIN__
#ifdef __GNUC__
#define CHASSIS_DRIVER_EXPORT __attribute__ ((dllexport))
#define CHASSIS_DRIVER_IMPORT __attribute__ ((dllimport))
#else
#define CHASSIS_DRIVER_EXPORT __declspec(dllexport)
#define CHASSIS_DRIVER_IMPORT __declspec(dllimport)
#endif
#ifdef CHASSIS_DRIVER_BUILDING_LIBRARY
#define CHASSIS_DRIVER_PUBLIC CHASSIS_DRIVER_EXPORT
#else
#define CHASSIS_DRIVER_PUBLIC CHASSIS_DRIVER_IMPORT
#endif
#define CHASSIS_DRIVER_PUBLIC_TYPE CHASSIS_DRIVER_PUBLIC
#define CHASSIS_DRIVER_LOCAL
#else
#define CHASSIS_DRIVER_EXPORT __attribute__ ((visibility("default")))
#define CHASSIS_DRIVER_IMPORT
#if __GNUC__ >= 4
#define CHASSIS_DRIVER_PUBLIC __attribute__ ((visibility("default")))
#define CHASSIS_DRIVER_LOCAL __attribute__ ((visibility("hidden")))
#else
#define CHASSIS_DRIVER_PUBLIC
#define CHASSIS_DRIVER_LOCAL
#endif
#define CHASSIS_DRIVER_PUBLIC_TYPE
#endif

#endif // CHASSIS_DRIVER__VISIBILITY_CONTROL_H_
2 changes: 1 addition & 1 deletion roboteq_driver/package.xml → chassis_driver/package.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0"?>
<?xml-model href="http://download.ros.org/schema/package_format3.xsd" schematypens="http://www.w3.org/2001/XMLSchema"?>
<package format="3">
<name>roboteq_driver</name>
<name>chassis_driver</name>
<version>0.0.0</version>
<description>TODO: Package description</description>
<maintainer email="[email protected]">kazuma</maintainer>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "roboteq_driver/roboteq_driver_node.hpp"
#include "chassis_driver/chassis_driver_node.hpp"

#include "utilities/data_utils.hpp"
#include "utilities/utils.hpp"
Expand All @@ -7,93 +7,125 @@

using namespace utils;

namespace roboteq_driver{
namespace chassis_driver{

RoboteqDriver::RoboteqDriver(const rclcpp::NodeOptions& options) : RoboteqDriver("", options) {}
ChassisDriver::ChassisDriver(const rclcpp::NodeOptions& options) : ChassisDriver("", options) {}

RoboteqDriver::RoboteqDriver(const std::string& name_space, const rclcpp::NodeOptions& options)
: rclcpp::Node("roboteq_driver_node", name_space, options),
ChassisDriver::ChassisDriver(const std::string& name_space, const rclcpp::NodeOptions& options)
: rclcpp::Node("chassis_driver_node", name_space, options),
interval_ms(get_parameter("interval_ms").as_int()),
wheel_radius(get_parameter("wheel_radius").as_double()),
tread(get_parameter("tread").as_double()),
wheelbase(get_parameter("wheelbase").as_double()),
rotate_ratio(1.0 / get_parameter("reduction_ratio").as_double()),
is_reverse_left(get_parameter("reverse_left_flag").as_bool()),
is_reverse_right(get_parameter("reverse_right_flag").as_bool())
is_reverse_right(get_parameter("reverse_right_flag").as_bool()),

linear_limit(DBL_MAX,
get_parameter("linear_max.vel").as_double(),
get_parameter("linear_max.acc").as_double()),

angular_limit(DBL_MAX,
get_parameter("angular_max.vel").as_double(),
get_parameter("angular_max.acc").as_double())
{
_subscription_vel = this->create_subscription<geometry_msgs::msg::Twist>(
"cmd_vel",
_qos,
std::bind(&RoboteqDriver::_subscriber_callback_vel, this, std::placeholders::_1)
std::bind(&ChassisDriver::_subscriber_callback_vel, this, std::placeholders::_1)
);
_subscription_stop = this->create_subscription<std_msgs::msg::Empty>(
"stop",
_qos,
std::bind(&RoboteqDriver::_subscriber_callback_stop, this, std::placeholders::_1)
std::bind(&ChassisDriver::_subscriber_callback_stop, this, std::placeholders::_1)
);
_subscription_restart = this->create_subscription<std_msgs::msg::Empty>(
"restart",
_qos,
std::bind(&RoboteqDriver::_subscriber_callback_restart, this, std::placeholders::_1)
std::bind(&ChassisDriver::_subscriber_callback_restart, this, std::placeholders::_1)
);
_subscription_rpm = this->create_subscription<socketcan_interface_msg::msg::SocketcanIF>(
"can_rx_711",
_qos,
std::bind(&RoboteqDriver::_subscriber_callback_rpm, this, std::placeholders::_1)
std::bind(&ChassisDriver::_subscriber_callback_rpm, this, std::placeholders::_1)
);
_subscription_emergency = this->create_subscription<socketcan_interface_msg::msg::SocketcanIF>(
"can_rx_712",
_qos,
std::bind(&RoboteqDriver::_subscriber_callback_emergency, this, std::placeholders::_1)
std::bind(&ChassisDriver::_subscriber_callback_emergency, this, std::placeholders::_1)
);
publisher_can = this->create_publisher<socketcan_interface_msg::msg::SocketcanIF>("can_tx", _qos);
publisher_steer = this->create_publisher<std_msgs::msg::Float64>("cybergear/pos", _qos);
publisher_ref_vel = this->create_publisher<geometry_msgs::msg::TwistStamped>("ref_vel", _qos);

_pub_timer = this->create_wall_timer(
std::chrono::milliseconds(interval_ms),
[this] { _publisher_callback(); }
);

linear_planner.limit(linear_limit);
angular_planner.limit(angular_limit);
}

void RoboteqDriver::_subscriber_callback_vel(const geometry_msgs::msg::Twist::SharedPtr msg){
void ChassisDriver::_subscriber_callback_vel(const geometry_msgs::msg::Twist::SharedPtr msg){
if(mode == Mode::stop) return;
mode = Mode::cmd;

vel = msg;
const double linear_vel = constrain(msg->linear.x, -linear_limit.vel, linear_limit.vel);
const double angular_vel = constrain(msg->angular.z, -angular_limit.vel, angular_limit.vel);
linear_planner.vel(linear_vel);
angular_planner.vel(angular_vel);
}

void RoboteqDriver::_publisher_callback(){
void ChassisDriver::_publisher_callback(){
linear_planner.cycle();
angular_planner.cycle();

if(mode == Mode::stop || mode == Mode::stay){
this->send_rpm(0.0, 0.0);
return;
}
if(vel == nullptr) return;
send_rpm(vel->linear.x, vel->angular.z);

const double linear_vel = linear_planner.vel();
const double angular_vel = angular_planner.vel();
send_rpm(linear_vel, angular_vel);

// デバッグ用にロボットの目標速度指令値を出版
auto msg_ref_vel = std::make_shared<geometry_msgs::msg::TwistStamped>();
msg_ref_vel->header.stamp = this->now();
msg_ref_vel->header.frame_id = "map";
msg_ref_vel->twist.linear.x = linear_vel;
msg_ref_vel->twist.angular.z = angular_vel;
publisher_ref_vel->publish(*msg_ref_vel);

// 従動輪角度の送信
auto msg_steer = std::make_shared<std_msgs::msg::Float64>();
if(vel->linear.x == 0.0){
if(linear_vel == 0.0){
msg_steer->data = 0.0;
}
else{
msg_steer->data = std::asin((wheelbase*vel->angular.z) / vel->linear.x);
msg_steer->data = std::asin((wheelbase*angular_vel) / linear_vel);
if(std::isnan(msg_steer->data)) msg_steer->data = 0.0;
}
publisher_steer->publish(*msg_steer);
}

void RoboteqDriver::_subscriber_callback_stop(const std_msgs::msg::Empty::SharedPtr msg){
void ChassisDriver::_subscriber_callback_stop(const std_msgs::msg::Empty::SharedPtr msg){
mode = Mode::stop;
RCLCPP_INFO(this->get_logger(), "停止");
}
void RoboteqDriver::_subscriber_callback_restart(const std_msgs::msg::Empty::SharedPtr msg){
void ChassisDriver::_subscriber_callback_restart(const std_msgs::msg::Empty::SharedPtr msg){
mode = Mode::stay;

velplanner::Physics_t physics_zero(0.0, 0.0, 0.0);
linear_planner.current(physics_zero);
angular_planner.current(physics_zero);
RCLCPP_INFO(this->get_logger(), "再稼働");
}

void RoboteqDriver::_subscriber_callback_rpm(const socketcan_interface_msg::msg::SocketcanIF::SharedPtr msg){
void ChassisDriver::_subscriber_callback_rpm(const socketcan_interface_msg::msg::SocketcanIF::SharedPtr msg){
}
void RoboteqDriver::_subscriber_callback_emergency(const socketcan_interface_msg::msg::SocketcanIF::SharedPtr msg){
void ChassisDriver::_subscriber_callback_emergency(const socketcan_interface_msg::msg::SocketcanIF::SharedPtr msg){
uint8_t _candata[8];
for(int i=0; i<msg->candlc; i++) _candata[i] = msg->candata[i];

Expand All @@ -103,10 +135,12 @@ void RoboteqDriver::_subscriber_callback_emergency(const socketcan_interface_msg
}
}

void RoboteqDriver::send_rpm(const double linear_vel, const double angular_vel){
void ChassisDriver::send_rpm(const double linear_vel, const double angular_vel){
// 駆動輪の目標角速度
const double left_vel = (1.0 / wheel_radius) * linear_vel + (tread / wheel_radius*2.0) * angular_vel;
const double right_vel = (1.0 / wheel_radius) * linear_vel - (tread / wheel_radius*2.0) * angular_vel;
// const double left_vel = (1.0 / wheel_radius) * linear_vel + (tread / wheel_radius*2.0) * angular_vel;
// const double right_vel = (1.0 / wheel_radius) * linear_vel - (tread / wheel_radius*2.0) * angular_vel;
const double left_vel = (-tread*angular_vel + 2.0*linear_vel) / (2.0*wheel_radius);
const double right_vel = (tread*angular_vel + 2.0*linear_vel) / (2.0*wheel_radius);

// rad/s -> rpm & 回転方向制御
const double left_rpm = (is_reverse_left ? -1 : 1) * (left_vel*30.0 / d_pi) * rotate_ratio;
Expand All @@ -127,4 +161,4 @@ void RoboteqDriver::send_rpm(const double linear_vel, const double angular_vel){
}


} // namespace roboteq_driver
} // namespace chassis_driver
Loading