Skip to content

Commit e08d872

Browse files
committed
FollowMe code, linear motion and perfect circular motion
1 parent 7412de5 commit e08d872

File tree

8 files changed

+678
-0
lines changed

8 files changed

+678
-0
lines changed

move_in_circle/CMakeLists.txt

Lines changed: 232 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,232 @@
1+
cmake_minimum_required(VERSION 2.8.3)
2+
project(move_in_circle)
3+
4+
## Compile as C++11, supported in ROS Kinetic and newer
5+
# add_compile_options(-std=c++11)
6+
7+
## Find catkin macros and libraries
8+
## if COMPONENTS list like find_package(catkin REQUIRED COMPONENTS xyz)
9+
## is used, also find other catkin packages
10+
find_package(catkin REQUIRED COMPONENTS
11+
roscpp
12+
rospy
13+
std_msgs
14+
message_generation
15+
cv_bridge
16+
sensor_msgs
17+
image_transport
18+
)
19+
20+
## System dependencies are found with CMake's conventions
21+
# find_package(Boost REQUIRED COMPONENTS system)
22+
find_package(OpenCV REQUIRED)
23+
24+
25+
## Uncomment this if the package has a setup.py. This macro ensures
26+
## modules and global scripts declared therein get installed
27+
## See http://ros.org/doc/api/catkin/html/user_guide/setup_dot_py.html
28+
# catkin_python_setup()
29+
30+
################################################
31+
## Declare ROS messages, services and actions ##
32+
################################################
33+
34+
## To declare and build messages, services or actions from within this
35+
## package, follow these steps:
36+
## * Let MSG_DEP_SET be the set of packages whose message types you use in
37+
## your messages/services/actions (e.g. std_msgs, actionlib_msgs, ...).
38+
## * In the file package.xml:
39+
## * add a build_depend tag for "message_generation"
40+
## * add a build_depend and a exec_depend tag for each package in MSG_DEP_SET
41+
## * If MSG_DEP_SET isn't empty the following dependency has been pulled in
42+
## but can be declared for certainty nonetheless:
43+
## * add a exec_depend tag for "message_runtime"
44+
## * In this file (CMakeLists.txt):
45+
## * add "message_generation" and every package in MSG_DEP_SET to
46+
## find_package(catkin REQUIRED COMPONENTS ...)
47+
## * add "message_runtime" and every package in MSG_DEP_SET to
48+
## catkin_package(CATKIN_DEPENDS ...)
49+
## * uncomment the add_*_files sections below as needed
50+
## and list every .msg/.srv/.action file to be processed
51+
## * uncomment the generate_messages entry below
52+
## * add every package in MSG_DEP_SET to generate_messages(DEPENDENCIES ...)
53+
54+
## Generate messages in the 'msg' folder
55+
# add_message_files(
56+
# FILES
57+
# Message1.msg
58+
# Message2.msg
59+
# )
60+
61+
## Generate services in the 'srv' folder
62+
# add_service_files(
63+
# FILES
64+
# Service1.srv
65+
# Service2.srv
66+
# )
67+
68+
## Generate actions in the 'action' folder
69+
# add_action_files(
70+
# FILES
71+
# Action1.action
72+
# Action2.action
73+
# )
74+
75+
## Generate added messages and services with any dependencies listed here
76+
# generate_messages(
77+
# DEPENDENCIES
78+
# std_msgs
79+
# )
80+
81+
################################################
82+
## Declare ROS dynamic reconfigure parameters ##
83+
################################################
84+
85+
## To declare and build dynamic reconfigure parameters within this
86+
## package, follow these steps:
87+
## * In the file package.xml:
88+
## * add a build_depend and a exec_depend tag for "dynamic_reconfigure"
89+
## * In this file (CMakeLists.txt):
90+
## * add "dynamic_reconfigure" to
91+
## find_package(catkin REQUIRED COMPONENTS ...)
92+
## * uncomment the "generate_dynamic_reconfigure_options" section below
93+
## and list every .cfg file to be processed
94+
95+
## Generate dynamic reconfigure parameters in the 'cfg' folder
96+
# generate_dynamic_reconfigure_options(
97+
# cfg/DynReconf1.cfg
98+
# cfg/DynReconf2.cfg
99+
# )
100+
101+
###################################
102+
## catkin specific configuration ##
103+
###################################
104+
## The catkin_package macro generates cmake config files for your package
105+
## Declare things to be passed to dependent projects
106+
## INCLUDE_DIRS: uncomment this if your package contains header files
107+
## LIBRARIES: libraries you create in this project that dependent projects also need
108+
## CATKIN_DEPENDS: catkin_packages dependent projects also need
109+
## DEPENDS: system dependencies of this project that dependent projects also need
110+
catkin_package(
111+
# INCLUDE_DIRS include
112+
# LIBRARIES move_in_circle
113+
CATKIN_DEPENDS roscpp rospy std_msgs message_runtime cv_bridge sensor_msgs
114+
# DEPENDS system_lib
115+
)
116+
117+
###########
118+
## Build ##
119+
###########
120+
121+
## Specify additional locations of header files
122+
## Your package locations should be listed before other locations
123+
include_directories(
124+
# include
125+
${OpenCV_INCLUDE_DIRS}
126+
${catkin_INCLUDE_DIRS}
127+
}
128+
)
129+
130+
## Declare a C++ library
131+
# add_library(${PROJECT_NAME}
132+
# src/${PROJECT_NAME}/move_in_circle.cpp
133+
# )
134+
135+
## Add cmake target dependencies of the library
136+
## as an example, code may need to be generated before libraries
137+
## either from message generation or dynamic reconfigure
138+
# add_dependencies(${PROJECT_NAME} ${${PROJECT_NAME}_EXPORTED_TARGETS} ${catkin_EXPORTED_TARGETS})
139+
140+
## Declare a C++ executable
141+
## With catkin_make all packages are built within a single CMake context
142+
## The recommended prefix ensures that target names across packages don't collide
143+
# add_executable(${PROJECT_NAME}_node src/move_in_circle_node.cpp)
144+
145+
## Rename C++ executable without prefix
146+
## The above recommended prefix causes long target names, the following renames the
147+
## target back to the shorter version for ease of user use
148+
## e.g. "rosrun someones_pkg node" instead of "rosrun someones_pkg someones_pkg_node"
149+
# set_target_properties(${PROJECT_NAME}_node PROPERTIES OUTPUT_NAME node PREFIX "")
150+
151+
## Add cmake target dependencies of the executable
152+
## same as for the library above
153+
# add_dependencies(${PROJECT_NAME}_node ${${PROJECT_NAME}_EXPORTED_TARGETS} ${catkin_EXPORTED_TARGETS})
154+
155+
## Specify libraries to link a library or executable target against
156+
# target_link_libraries(${PROJECT_NAME}_node
157+
# ${catkin_LIBRARIES}
158+
# )
159+
160+
#############
161+
## Install ##
162+
#############
163+
164+
# all install targets should use catkin DESTINATION variables
165+
# See http://ros.org/doc/api/catkin/html/adv_user_guide/variables.html
166+
167+
## Mark executable scripts (Python etc.) for installation
168+
## in contrast to setup.py, you can choose the destination
169+
# install(PROGRAMS
170+
# scripts/my_python_script
171+
# DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION}
172+
# )
173+
174+
## Mark executables and/or libraries for installation
175+
# install(TARGETS ${PROJECT_NAME} ${PROJECT_NAME}_node
176+
# ARCHIVE DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
177+
# LIBRARY DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
178+
# RUNTIME DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION}
179+
# )
180+
181+
## Mark cpp header files for installation
182+
# install(DIRECTORY include/${PROJECT_NAME}/
183+
# DESTINATION ${CATKIN_PACKAGE_INCLUDE_DESTINATION}
184+
# FILES_MATCHING PATTERN "*.h"
185+
# PATTERN ".svn" EXCLUDE
186+
# )
187+
188+
## Mark other files for installation (e.g. launch and bag files, etc.)
189+
# install(FILES
190+
# # myfile1
191+
# # myfile2
192+
# DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION}
193+
# )
194+
195+
#############
196+
## Testing ##
197+
#############
198+
199+
## Add gtest based cpp test target and link libraries
200+
# catkin_add_gtest(${PROJECT_NAME}-test test/test_move_in_circle.cpp)
201+
# if(TARGET ${PROJECT_NAME}-test)
202+
# target_link_libraries(${PROJECT_NAME}-test ${PROJECT_NAME})
203+
# endif()
204+
205+
## Add folders to be run by python nosetests
206+
# catkin_add_nosetests(test)
207+
208+
add_executable(line src/line.cpp)
209+
target_link_libraries(line ${catkin_LIBRARIES})
210+
add_dependencies(line ${catkin_EXPORTED_TARGETS})
211+
212+
add_executable(circle src/circle.cpp)
213+
target_link_libraries(circle ${catkin_LIBRARIES})
214+
add_dependencies(circle ${catkin_EXPORTED_TARGETS})
215+
216+
217+
add_executable(around src/around.cpp)
218+
target_link_libraries(around ${catkin_LIBRARIES})
219+
add_dependencies(around ${catkin_EXPORTED_TARGETS})
220+
221+
222+
add_executable(yaw_mot src/yaw_mot.cpp)
223+
target_link_libraries(yaw_mot ${catkin_LIBRARIES})
224+
add_dependencies(yaw_mot ${catkin_EXPORTED_TARGETS})
225+
226+
add_executable(camViewMat src/camViewMat.cpp)
227+
target_link_libraries(camViewMat ${catkin_LIBRARIES} ${OpenCV_LIBRARIES})
228+
add_dependencies(camViewMat ${catkin_EXPORTED_TARGETS})
229+
230+
add_executable(vel_pub src/vel_pub.cpp)
231+
target_link_libraries(vel_pub ${catkin_LIBRARIES})
232+
add_dependencies(vel_pub ${catkin_EXPORTED_TARGETS})

move_in_circle/package.xml

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
<?xml version="1.0"?>
2+
<package format="2">
3+
<name>move_in_circle</name>
4+
<version>0.0.0</version>
5+
<description>The move_in_circle package</description>
6+
7+
<!-- One maintainer tag required, multiple allowed, one person per tag -->
8+
<!-- Example: -->
9+
<!-- <maintainer email="[email protected]">Jane Doe</maintainer> -->
10+
<maintainer email="[email protected]">carry</maintainer>
11+
12+
13+
<!-- One license tag required, multiple allowed, one license per tag -->
14+
<!-- Commonly used license strings: -->
15+
<!-- BSD, MIT, Boost Software License, GPLv2, GPLv3, LGPLv2.1, LGPLv3 -->
16+
<license>TODO</license>
17+
18+
19+
<!-- Url tags are optional, but multiple are allowed, one per tag -->
20+
<!-- Optional attribute type can be: website, bugtracker, or repository -->
21+
<!-- Example: -->
22+
<!-- <url type="website">http://wiki.ros.org/move_in_circle</url> -->
23+
24+
25+
<!-- Author tags are optional, multiple are allowed, one per tag -->
26+
<!-- Authors do not have to be maintainers, but could be -->
27+
<!-- Example: -->
28+
<!-- <author email="[email protected]">Jane Doe</author> -->
29+
30+
31+
<!-- The *depend tags are used to specify dependencies -->
32+
<!-- Dependencies can be catkin packages or system dependencies -->
33+
<!-- Examples: -->
34+
<!-- Use depend as a shortcut for packages that are both build and exec dependencies -->
35+
<!-- <depend>roscpp</depend> -->
36+
<!-- Note that this is equivalent to the following: -->
37+
<!-- <build_depend>roscpp</build_depend> -->
38+
<!-- <exec_depend>roscpp</exec_depend> -->
39+
<!-- Use build_depend for packages you need at compile time: -->
40+
<!-- <build_depend>message_generation</build_depend> -->
41+
<!-- Use build_export_depend for packages you need in order to build against this package: -->
42+
<!-- <build_export_depend>message_generation</build_export_depend> -->
43+
<!-- Use buildtool_depend for build tool packages: -->
44+
<!-- <buildtool_depend>catkin</buildtool_depend> -->
45+
<!-- Use exec_depend for packages you need at runtime: -->
46+
<exec_depend>message_runtime</exec_depend>
47+
<!-- Use test_depend for packages you need only for testing: -->
48+
<!-- <test_depend>gtest</test_depend> -->
49+
<!-- Use doc_depend for packages you need only for building documentation: -->
50+
<!-- <doc_depend>doxygen</doc_depend> -->
51+
<buildtool_depend>catkin</buildtool_depend>
52+
<build_depend>roscpp</build_depend>
53+
<build_depend>rospy</build_depend>
54+
<build_depend>std_msgs</build_depend>
55+
<build_depend>cv_bridge</build_depend>
56+
<build_depend>sensor_msgs</build_depend>
57+
<build_depend>image_transport</build_depend>
58+
<build_export_depend>roscpp</build_export_depend>
59+
<build_export_depend>rospy</build_export_depend>
60+
<build_export_depend>std_msgs</build_export_depend>
61+
<exec_depend>roscpp</exec_depend>
62+
<exec_depend>rospy</exec_depend>
63+
<exec_depend>std_msgs</exec_depend>
64+
<exec_depend>cv_bridge</exec_depend>
65+
<exec_depend>sensor_msgs</exec_depend>
66+
<exec_depend>image_transport</exec_depend>
67+
68+
69+
<!-- The export tag contains other, unspecified, tags -->
70+
<export>
71+
<!-- Other tools can request additional information be placed here -->
72+
73+
</export>
74+
</package>

move_in_circle/src/around.cpp

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#include "ros/ros.h"
2+
#include "std_msgs/Empty.h"
3+
#include "geometry_msgs/Twist.h"
4+
#include "nav_msgs/Odometry.h"
5+
#include <stdio.h>
6+
#include <cmath>
7+
#include <iostream>
8+
using namespace std;
9+
10+
11+
float r=0.5;
12+
float theta=0;
13+
float v= 0.01;
14+
int k=60;
15+
int main(int argc, char **argv)
16+
{
17+
ros::init(argc, argv, "around");
18+
ros::NodeHandle n;
19+
ros::Publisher pub;
20+
pub = n.advertise<geometry_msgs::Twist>("/bebop/cmd_vel", 100);
21+
ros::Rate loop_rate(10);
22+
geometry_msgs::Twist vel;
23+
vel.linear.z=0;
24+
vel.angular.z=0;
25+
while (ros::ok())
26+
{
27+
float a=v*cos(theta);
28+
float b=v*sin(theta);
29+
vel.linear.x=-a;
30+
vel.linear.y=-b;
31+
theta+=(v*0.1/r);
32+
//cout << a,b << endl;
33+
//cout << theta<< endl;
34+
pub.publish(vel);
35+
ros::spinOnce();
36+
loop_rate.sleep();
37+
}
38+
return 0;
39+
}

0 commit comments

Comments
 (0)