From ec243c79759ecc340d8a5d4557285897b29c7dc3 Mon Sep 17 00:00:00 2001 From: "adrien.lasserre" Date: Tue, 22 Nov 2022 15:48:34 +0100 Subject: [PATCH] successfully created basic movements functions --- CMakeLists.txt | 6 ++---- src/project_file.cpp | 21 +++++---------------- 2 files changed, 7 insertions(+), 20 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 5a30ba2..bf34b64 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -132,7 +132,7 @@ include_directories( ## Declare a C++ executable ## With catkin_make all packages are built within a single CMake context ## The recommended prefix ensures that target names across packages don't collide -# add_executable(${PROJECT_NAME}_node src/test_node.cpp) +add_executable(commander src/project_file.cpp) ## Rename C++ executable without prefix ## The above recommended prefix causes long target names, the following renames the @@ -145,9 +145,7 @@ include_directories( # add_dependencies(${PROJECT_NAME}_node ${${PROJECT_NAME}_EXPORTED_TARGETS} ${catkin_EXPORTED_TARGETS}) ## Specify libraries to link a library or executable target against -# target_link_libraries(${PROJECT_NAME}_node -# ${catkin_LIBRARIES} -# ) +target_link_libraries(commander ${catkin_LIBRARIES}) ############# ## Install ## diff --git a/src/project_file.cpp b/src/project_file.cpp index bd1967c..44fbead 100644 --- a/src/project_file.cpp +++ b/src/project_file.cpp @@ -10,14 +10,11 @@ Context: This cpp file is part of the second lab of the Advanced_Robotics course #include -#include //std::this_thread_sleep_for -#include //std::chrono::seconds - - +#include //max values for lin vel 0.22 and angular vel 2.84 -void walk(geometry_msgs::Twist twist, speed_input){ +void walk(geometry_msgs::Twist& twist, float speed_input){ //intialisation of the values for the twist messages twist.linear.x=0.0; @@ -32,7 +29,7 @@ void walk(geometry_msgs::Twist twist, speed_input){ } -void turn_random(geometry_msgs::Twist twist){ +void turn_random(geometry_msgs::Twist& twist, float random_angular_speed){ //initialisation of the values for the twist messages twist.linear.x=0.0; @@ -43,11 +40,7 @@ void turn_random(geometry_msgs::Twist twist){ twist.angular.z=0.0; //randomise the angle - int random_angular_speed=rand() % 2; twist.angular.z=random_angular_speed; - std::this_thread_sleep_for (std::chrono::seconds(2)); - twist.angular.z=0.0; - } @@ -63,13 +56,9 @@ int main(int argc, char** argv) geometry_msgs::Twist twist; - walk(twist, 0.1); - commanderPublisher.publish(twist); - loopRate.sleep(3); - turn_random(twist); - commanderPublisher.publish(twist); - loopRate.sleep(3); + turn_random(twist, 1); + commanderPublisher.publish(twist); ros::spinOnce(); loopRate.sleep(); }