From 2af772c0953b53ea532746dfdd6ce78d3da06b35 Mon Sep 17 00:00:00 2001 From: "lucas.marais" Date: Tue, 2 Apr 2024 13:59:09 +0200 Subject: [PATCH] cleaning in prog --- catkin_ws/src/poppy_ros | 1 - joystick_ros/src/parser.cpp | 46 -------------------- joystick_ros/src/position_ctrl.cpp | 70 ------------------------------ 3 files changed, 117 deletions(-) delete mode 160000 catkin_ws/src/poppy_ros delete mode 100644 joystick_ros/src/parser.cpp delete mode 100644 joystick_ros/src/position_ctrl.cpp diff --git a/catkin_ws/src/poppy_ros b/catkin_ws/src/poppy_ros deleted file mode 160000 index 97d4093..0000000 --- a/catkin_ws/src/poppy_ros +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 97d4093656a3ec9cfe8645457e00e55ccbdd8469 diff --git a/joystick_ros/src/parser.cpp b/joystick_ros/src/parser.cpp deleted file mode 100644 index a072ffc..0000000 --- a/joystick_ros/src/parser.cpp +++ /dev/null @@ -1,46 +0,0 @@ -#include -#include -#include -#include - -// Declare global variables to store Axis values -float axis0_value = 0.0; -float axis1_value = 0.0; - -void serial_data_callback(const std_msgs::String::ConstPtr& msg) { - // Parse received string message - std::string data_str = msg->data; - if (data_str.find("Axis0") != std::string::npos) { - // Extract value for Axis0 - axis0_value = std::stof(data_str.substr(data_str.find(":") + 1)); - } else if (data_str.find("Axis1") != std::string::npos) { - // Extract value for Axis1 - axis1_value = std::stof(data_str.substr(data_str.find(":") + 1)); - } - - // If both Axis0 and Axis1 values are available, publish them together - if (axis0_value != 0.0 && axis1_value != 0.0) { - std_msgs::Float32MultiArray float_array_msg; - float_array_msg.data.push_back(axis0_value); - float_array_msg.data.push_back(axis1_value); - axis_values_pub.publish(float_array_msg); - } -} - -int main(int argc, char** argv) { - // Initialize ROS node - ros::init(argc, argv, "serial_data_parser"); - ros::NodeHandle nh; - - // Subscribe to serial data topic - ros::Subscriber sub = nh.subscribe("serial_data", 10, serial_data_callback); - - // Initialize publisher for Axis values - ros::Publisher axis_values_pub = nh.advertise("axis_values", 10); - - // Spin ROS node - ros::spin(); - - return 0; -} - diff --git a/joystick_ros/src/position_ctrl.cpp b/joystick_ros/src/position_ctrl.cpp deleted file mode 100644 index bac53f8..0000000 --- a/joystick_ros/src/position_ctrl.cpp +++ /dev/null @@ -1,70 +0,0 @@ -#include -#include -#include - -// Constants -const float DEAD_ZONE = 5.0; // Dead zone in percentage (0 to 100) -const float MAX_SPEED = 1.0; // Maximum speed of the plate - -// Global variables -float y_position = 0.0; // Initial y position -float prev_time = 0.0; // Previous time -float direction = 0.0; // Direction of movement - -void joystick_axis_callback(const std_msgs::Float32MultiArray::ConstPtr& msg) { - // Extract joystick x and y positions - float x_joystick = msg->data[0]; - float y_joystick = msg->data[1]; - - // Determine direction based on joystick position - if (std::abs(x_joystick) < DEAD_ZONE) { - direction = 0.0; // Joystick in dead zone, no movement - } else { - direction = (x_joystick > 0) ? 1.0 : -1.0; // Joystick outside dead zone, set direction accordingly - } - - // Calculate speed based on joystick position - float speed = MAX_SPEED * std::abs(x_joystick) / 100.0; - - // Calculate time elapsed since last callback - float current_time = ros::Time::now().toSec(); - float time_elapsed = current_time - prev_time; - - // Calculate change in y position - y_position = y_position + time_elapsed * speed * direction; - - // Store current time for next iteration - prev_time = current_time; - - // Publish robot position in a point format - geometry_msgs::Point position_cmd; - position_cmd.x = 65.0; // Fixed x-coordinate - position_cmd.y = y_position; - position_cmd.z = 0.0; // Assuming z-coordinate is not used - - // Publish position command - ros::NodeHandle nh; - ros::Publisher position_cmd_pub = nh.advertise("/position_cmd", 10); - position_cmd_pub.publish(position_cmd); -} - -int main(int argc, char** argv) { - // Initialize ROS node - ros::init(argc, argv, "joystick_to_robot_converter"); - ros::NodeHandle nh; - - // Subscribe to joystick axis values topic - ros::Subscriber joystick_sub = nh.subscribe("joystick_axis_values", 10, joystick_axis_callback); - - // Initialize y position - y_position = 0.0; - - // Initialize previous time - prev_time = ros::Time::now().toSec(); - - // Spin ROS node - ros::spin(); - - return 0; -} -