Skip to content

Commit

Permalink
#8 New ROS2 Structure for Control
Browse files Browse the repository at this point in the history
  • Loading branch information
dongdongO committed Apr 11, 2024
1 parent 7ace37d commit 149a2a9
Show file tree
Hide file tree
Showing 12 changed files with 71 additions and 15 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ build
.vscode
.DStore
log
install

5 changes: 0 additions & 5 deletions control/.gitignore

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
cmake_minimum_required(VERSION 3.5)
project(control)
project(pure_pursuit)

# Default to C99
if(NOT CMAKE_C_STANDARD)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#pragma once

#include "msg_structs.h"
#include "utils/msg_structs.h"

#include "controller/pure_pursuit.hpp"

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#pragma once

#include "msg_structs.h"
#include "utils/msg_structs.h"

#include <array>
#include <cmath>
Expand All @@ -12,6 +12,9 @@ class PurePursuit {
public:
PurePursuit(double WB, double Kdd, double Ldc);

PurePursuit();
~PurePursuit();

void purepursuit_control(std::vector<Path> refPoses, double target_v, double x, double y, double yaw, double v);

double getThrottle();
Expand Down
File renamed without changes.
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>control</name>
<name>pure_pursuit</name>
<version>0.0.0</version>
<description>TODO: Package description</description>
<maintainer email="tjehdghks4356@gmail.com">dongdongo</maintainer>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "control.h"
#include "control.hpp"

Control::Control() : rclcpp::Node("vehicle_control"), controller(15, 0.5, 10.0) {
// this->controller = PurePursuit(2.7, 0.5, 4.0);
Control::Control() : rclcpp::Node("vehicle_control") {
this->controller = PurePursuit(2.7, 0.5, 4.0);

// Subscribe
path_subscription_ = this->create_subscription<nav_msgs::msg::Path>(
Expand All @@ -28,7 +28,7 @@ void Control::path_callback(const nav_msgs::msg::Path::SharedPtr path_msg) {
for (size_t i = 0; i < path_msg->poses.size(); ++i) {
refPose.x = path_msg->poses[i].pose.position.x;
refPose.y = path_msg->poses[i].pose.position.y;
// refPose.yaw = this->quat_to_yaw(path_msg->poses[i].pose.orientation);
refPose.yaw = this->quat_to_yaw(path_msg->poses[i].pose.orientation);
this->refPoses.push_back(refPose);
}
this->pathValid = true;
Expand Down Expand Up @@ -74,7 +74,7 @@ void Control::publisher_timer_callback() {

void Control::publish_drive(float speed, float steer) {
auto drive_msg = std::make_unique<geometry_msgs::msg::Twist>();
drive_msg->linear.x = speed;
drive_msg->linear.x = speed * 0.8;
drive_msg->angular.z = steer;
std::cout << "Publish Throttle : " << speed << " Publish Steering : " << steer << std::endl;
this->drive_publisher_->publish(std::move(drive_msg));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ PurePursuit::PurePursuit(double WB, double Kdd, double Ldc) {
this->target_node = 0;
}

PurePursuit::PurePursuit() {}

PurePursuit::~PurePursuit() {}

void PurePursuit::purepursuit_control(std::vector<Path> refPoses, double target_v, double x, double y, double yaw, double v) {
this->target_speed = target_v;
this->refPoses = refPoses;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "control.h"
#include "control.hpp"

int main(int argc, char * argv[])
{
Expand Down
35 changes: 35 additions & 0 deletions control_ws/src/stanley/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
cmake_minimum_required(VERSION 3.5)
project(stanley)

# Default to C99
if(NOT CMAKE_C_STANDARD)
set(CMAKE_C_STANDARD 99)
endif()

# Default to C++14
if(NOT CMAKE_CXX_STANDARD)
set(CMAKE_CXX_STANDARD 14)
endif()

if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
add_compile_options(-Wall -Wextra -Wpedantic)
endif()

# find dependencies
find_package(ament_cmake REQUIRED)
# uncomment the following section in order to fill in
# further dependencies manually.
# find_package(<dependency> REQUIRED)

if(BUILD_TESTING)
find_package(ament_lint_auto REQUIRED)
# the following line skips the linter which checks for copyrights
# uncomment the line when a copyright and license is not present in all source files
#set(ament_cmake_copyright_FOUND TRUE)
# the following line skips cpplint (only works in a git repo)
# uncomment the line when this package is not in a git repo
#set(ament_cmake_cpplint_FOUND TRUE)
ament_lint_auto_find_test_dependencies()
endif()

ament_package()
18 changes: 18 additions & 0 deletions control_ws/src/stanley/package.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?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>stanley</name>
<version>0.0.0</version>
<description>TODO: Package description</description>
<maintainer email="tjehdghks4356@gmail.com">dongdongo</maintainer>
<license>TODO: License declaration</license>

<buildtool_depend>ament_cmake</buildtool_depend>

<test_depend>ament_lint_auto</test_depend>
<test_depend>ament_lint_common</test_depend>

<export>
<build_type>ament_cmake</build_type>
</export>
</package>

0 comments on commit 149a2a9

Please sign in to comment.