first test - walking and turning for a few seconds

This commit is contained in:
Adrien LASSERRE 2022-11-22 15:09:53 +01:00
parent a4d7cc020e
commit 6ef095daf4
1 changed files with 51 additions and 2 deletions

View File

@ -10,6 +10,46 @@ 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 <chrono> //std::chrono::seconds
//max values for lin vel 0.22 and angular vel 2.84
void walk(geometry_msgs::Twist twist, speed_input){
//intialisation of the values for the twist messages
twist.linear.x=0.0;
twist.linear.y=0.0;
twist.linear.z=0.0;
twist.angular.x=0.0;
twist.angular.y=0.0;
twist.angular.z=0.0;
//use of the speed input
twist.linear.x=speed_input;
}
void turn_random(geometry_msgs::Twist twist){
//initialisation of the values for the twist messages
twist.linear.x=0.0;
twist.linear.y=0.0;
twist.linear.z=0.0;
twist.angular.x=0.0;
twist.angular.y=0.0;
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;
}
int main(int argc, char** argv) int main(int argc, char** argv)
{ {
@ -20,10 +60,19 @@ int main(int argc, char** argv)
ros::Rate loopRate(10); ros::Rate loopRate(10);
while(ros::ok()){ while(ros::ok()){
commanderPublisher.publish();
geometry_msgs::Twist twist;
walk(twist, 0.1);
commanderPublisher.publish(twist);
loopRate.sleep(3);
turn_random(twist);
commanderPublisher.publish(twist);
loopRate.sleep(3);
ros::spinOnce(); ros::spinOnce();
loopRate.sleep(); loopRate.sleep();
} }
return 0; return 0;
} }