successfully created basic movements functions

This commit is contained in:
Adrien LASSERRE 2022-11-22 15:48:34 +01:00
parent 6ef095daf4
commit ec243c7975
2 changed files with 7 additions and 20 deletions

View File

@ -132,7 +132,7 @@ include_directories(
## Declare a C++ executable ## Declare a C++ executable
## With catkin_make all packages are built within a single CMake context ## With catkin_make all packages are built within a single CMake context
## The recommended prefix ensures that target names across packages don't collide ## 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 ## Rename C++ executable without prefix
## The above recommended prefix causes long target names, the following renames the ## 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}) # add_dependencies(${PROJECT_NAME}_node ${${PROJECT_NAME}_EXPORTED_TARGETS} ${catkin_EXPORTED_TARGETS})
## Specify libraries to link a library or executable target against ## Specify libraries to link a library or executable target against
# target_link_libraries(${PROJECT_NAME}_node target_link_libraries(commander ${catkin_LIBRARIES})
# ${catkin_LIBRARIES}
# )
############# #############
## Install ## ## Install ##

View File

@ -10,14 +10,11 @@ Context: This cpp file is part of the second lab of the Advanced_Robotics course
#include <ros/ros.h> #include <ros/ros.h>
#include <thread> //std::this_thread_sleep_for #include <geometry_msgs/Twist.h>
#include <chrono> //std::chrono::seconds
//max values for lin vel 0.22 and angular vel 2.84 //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 //intialisation of the values for the twist messages
twist.linear.x=0.0; 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 //initialisation of the values for the twist messages
twist.linear.x=0.0; twist.linear.x=0.0;
@ -43,11 +40,7 @@ void turn_random(geometry_msgs::Twist twist){
twist.angular.z=0.0; twist.angular.z=0.0;
//randomise the angle //randomise the angle
int random_angular_speed=rand() % 2;
twist.angular.z=random_angular_speed; 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; geometry_msgs::Twist twist;
walk(twist, 0.1); turn_random(twist, 1);
commanderPublisher.publish(twist);
loopRate.sleep(3);
turn_random(twist);
commanderPublisher.publish(twist);
loopRate.sleep(3);
commanderPublisher.publish(twist);
ros::spinOnce(); ros::spinOnce();
loopRate.sleep(); loopRate.sleep();
} }