Skip to content

Commit 5f17a29

Browse files
author
Miguel Cuartin
committed
merge
2 parents dbf26bc + 617a7b6 commit 5f17a29

File tree

30 files changed

+357
-1606
lines changed

30 files changed

+357
-1606
lines changed

README.md

Lines changed: 66 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,85 @@
11
# YouBot
2+
[![python](https://img.shields.io/badge/python-v3.7.X-green.svg)](https://www.python.org/)
3+
[![pip](https://img.shields.io/badge/pip-v10.0.X-yellow.svg)](https://pypi.org/project/pip/)
4+
[![virtualenv](https://img.shields.io/badge/virtualenv-v15.1.X-red.svg)](https://virtualenv.pypa.io/en/stable/)
25

3-
ROS packages for KUKA YouBot Robot
6+
ROS packages for the KUKA YouBot robot.
7+
8+
## Table of Contents
9+
10+
- [Requirements](#requirements)
11+
- [Installation](#installation)
12+
- [Quickstart](#quickstart)
13+
- [Contributing](#contributing)
14+
- [Further reading / Useful links](#further-reading--useful-links)
15+
16+
## Requirements
17+
18+
Before you begin, ensure you have met the following requirements:
19+
* You have a Linux machine with Ubuntu Xenial 16.0. LTS
20+
* You have installed [ROS Kinetic](http://wiki.ros.org/kinetic/Installation)
21+
* You have installed [catkin_tools](https://catkin-tools.readthedocs.io/en/latest/installing.html)
22+
* You have installed [Python 2.7](https://www.python.org/downloads/)
423

524
**Maintainer:** [Miguel Cuartin Ordaz](https://www.linkedin.com/in/macuartin/)
625

726
## Installation
827

9-
### Basic Requirements
28+
Go to your ROS working directory:
1029

11-
1. Install [ROS Kinetic](http://wiki.ros.org/kinetic/Installation/Ubuntu) (**Base Install** Recommended)
12-
13-
### Repository Installation
14-
15-
Go to your ROS working directory. e.g.
1630
```bash
1731
cd ~/catkin_ws/src
18-
```
32+
```
33+
1934
Clone the required repositories:
35+
2036
```bash
21-
git clone https://github.com/fsuarez6/lenny.git
37+
git clone https://github.com/macuartin/youbot.git
2238
```
23-
Install any missing dependencies using rosdep:
24-
```bash
25-
rosdep update
26-
rosdep install --from-paths . --ignore-src --rosdistro $ROS_DISTRO
27-
```
28-
Now compile your ROS workspace. e.g.
39+
40+
Compile your ROS workspace:
41+
2942
```bash
3043
cd ~/catkin_ws && catkin_make
31-
```
44+
```
45+
46+
## Quickstart
3247

33-
### Testing Installation
48+
Be sure to always source the appropriate ROS setup file, e.g:
3449

35-
Be sure to always source the appropriate ROS setup file:
3650
```bash
3751
source ~/catkin_ws/devel/setup.bash
38-
```
39-
You might want to add that line to your `~/.bashrc`
52+
```
53+
You might want to add the line above to your ~/.bashrc file.
54+
55+
Try the following command:
56+
57+
```bash
58+
roslaunch youbot_bringup main.launch
59+
```
60+
61+
## Contributing
62+
63+
To contribute, follow these steps:
64+
65+
1. Fork this repository.
66+
2. Create a branch: `git checkout -b <branch_name>`.
67+
3. Make your changes and commit them: `git commit -m '<commit_message>'`
68+
4. Push to the original branch: `git push origin <project_name>/<location>`
69+
5. Create the pull request.
70+
71+
Alternatively see the GitHub documentation on [creating a pull request](https://help.github.com/en/github/collaborating-with-issues-and-pull-requests/creating-a-pull-request).
72+
73+
## Further reading / Useful links
74+
75+
* Lorem ipsum dolor sit amet, consectetur adipiscing elit.
76+
* Lorem ipsum dolor sit amet, consectetur adipiscing elit.
77+
78+
## Contact
79+
80+
If you want to contact me you can reach me at [[email protected]](mailto:[email protected])
81+
82+
## License
83+
<!--- If you're not sure which open license to use see https://choosealicense.com/--->
84+
85+
This project uses the following license: [<license_name>](<link>).

youbot_bringup/launch/main.launch

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<launch>
2-
<node pkg="youbot_traj_planner" type="traj_planner_publisher.py" name="traj_planner_publisher">
2+
<node pkg="youbot_control" type="traj_planner_node.py" name="traj_planner_node">
33
<rosparam file="$(find youbot_bringup)/config/youbot_traj_planner.yaml" />
44
</node>
55
</launch>

youbot_control/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ find_package(catkin REQUIRED COMPONENTS
2020
## Uncomment this if the package has a setup.py. This macro ensures
2121
## modules and global scripts declared therein get installed
2222
## See http://ros.org/doc/api/catkin/html/user_guide/setup_dot_py.html
23-
# catkin_python_setup()
23+
catkin_python_setup()
2424

2525
################################################
2626
## Declare ROS messages, services and actions ##

youbot_control/package.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<!-- One maintainer tag required, multiple allowed, one person per tag -->
88
<!-- Example: -->
99
<!-- <maintainer email="[email protected]">Jane Doe</maintainer> -->
10-
<maintainer email="[email protected]">macuartin</maintainer>
10+
<maintainer email="[email protected]">Miguel Cuartin </maintainer>
1111

1212

1313
<!-- One license tag required, multiple allowed, one license per tag -->
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#!/usr/bin/env python
2+
import rospy
3+
from youbot_msgs.msg import Point
4+
from rospy.numpy_msg import numpy_msg
5+
from youbot_control.cartesian_traj_generator import cubic_splines_planner
6+
from youbot_control.trajectory import TrajectoryController
7+
from numpy import pi
8+
9+
10+
if __name__ == '__main__':
11+
12+
try:
13+
checkpoints = rospy.get_param('/traj_planner_node/checkpoints')
14+
checkpoints_timing = rospy.get_param('/traj_planner_node/checkpoints_timing')
15+
initial_velocity = rospy.get_param('/traj_planner_node/initial_velocity')
16+
final_velocity = rospy.get_param('/traj_planner_node/final_velocity')
17+
sampling_time = rospy.get_param('/traj_planner_node/sampling_time')
18+
19+
controller = TrajectoryController(checkpoints,
20+
checkpoints_timing,
21+
initial_velocity,
22+
final_velocity,
23+
sampling_time,
24+
'cubic_splines')
25+
26+
position = controller.get_position_trajectory()
27+
28+
rospy.init_node('traj_planner_node')
29+
pub = rospy.Publisher('traj_planner_topic', numpy_msg(Point), queue_size=10)
30+
rate = rospy.Rate(10)
31+
msg = Point()
32+
33+
for point in position:
34+
msg.x = point[0]
35+
msg.y = point[1]
36+
msg.z = point[2]
37+
38+
pub.publish(msg)
39+
rospy.loginfo(msg)
40+
rate.sleep()
41+
42+
if rospy.is_shutdown():
43+
break
44+
45+
except rospy.ROSException as err:
46+
rospy.logerr(err)
Lines changed: 205 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,205 @@
1+
#! /usr/bin/env python
2+
from __future__ import division
3+
import rospy
4+
import numpy as np
5+
6+
7+
class TrajectoryController(object):
8+
9+
def __init__(self, checkpoints, checkpoints_timing, initial_velocity,
10+
final_velocity, sampling_time, generator):
11+
12+
self.checkpoints = checkpoints
13+
self.checkpoints_timing = checkpoints_timing
14+
self.initial_velocity = initial_velocity
15+
self.final_velocity = final_velocity
16+
self.sampling_time = sampling_time
17+
self.generator = generator
18+
19+
def get_position_trajectory(self):
20+
if self.generator == 'cubic_splines':
21+
return self.cubic_splines_interpolator('position')
22+
23+
def get_velocity_trajectory(self):
24+
if self.generator == 'cubic_splines':
25+
return self.cubic_splines_interpolator('velocity')
26+
27+
def get_acceleration_trajectory(self):
28+
if self.generator == 'cubic_splines':
29+
return self.cubic_splines_interpolator('acceleration')
30+
31+
def get_orientation_trajectory(self):
32+
if self.generator == 'cubic_splines':
33+
return self.cubic_splines_interpolator('position')
34+
35+
def __get_a_matrix(self, n, h):
36+
37+
A = np.zeros(shape=(n, n))
38+
39+
A[0, 0] = 2 * h[0]
40+
41+
for i in range(0, n-1):
42+
A[i+1, i] = h[i]
43+
A[i, i+1] = h[i]
44+
45+
for i in range(1, n-1):
46+
A[i, i] = 2 * (h[i-1] + h[i])
47+
48+
A[n-1, n-1] = 2 * h[n-2]
49+
50+
return A
51+
52+
def __get_F_vector(self, n, h, component):
53+
54+
F = np.zeros(shape=(n, 1))
55+
56+
F[0] = (((3/h[0])*(self.checkpoints[1][component]-self.checkpoints[0][component]))
57+
- 3*self.initial_velocity[component])
58+
59+
for i in range(1, n-1):
60+
F[i] = (((3/h[i])
61+
* (self.checkpoints[i+1][component]-self.checkpoints[i][component]))
62+
- ((3/h[i-1])
63+
* (self.checkpoints[i][component]-self.checkpoints[i-1][component])))
64+
65+
F[n-1] = (3*self.final_velocity[component]
66+
- ((3/h[n-2])
67+
* (self.checkpoints[n-1][component]-self.checkpoints[n-2][component])))
68+
69+
return F
70+
71+
def __get_b_coefficient(self, A, F):
72+
return np.dot(np.linalg.inv(A), F)
73+
74+
def __get_a_coefficient(self, n, b, h, component):
75+
a = np.zeros(shape=(n, 1))
76+
for i in range(0, n-1):
77+
a[i] = (b[i+1] - b[i]) / (3*h[i])
78+
return a
79+
80+
def __get_c_coefficient(self, n, b, h, component):
81+
c = np.zeros(shape=(n, 1))
82+
for i in range(0, n-1):
83+
c[i] = (((1/h[i])*(self.checkpoints[i+1][component]
84+
- self.checkpoints[i][component]))
85+
- ((h[i]/3)*((2*b[i]) + b[i+1])))
86+
return c
87+
88+
def __get_d_coefficient(self, n, b, h, component):
89+
d = np.zeros(shape=(n, 1))
90+
for i in range(0, n-1):
91+
d[i] = self.checkpoints[i][component]
92+
return d
93+
94+
def cubic_splines_interpolator(self, component):
95+
96+
'''
97+
checkpoints: [[x0,y0,z0], [x1,y1,z1], ... , [xn,yn,zn]].
98+
99+
checkpoints_timing: [t0, t1, ... , tn ].
100+
101+
velocity_vector: [[Vx0, Vy0, Vz0], [Vxn, Vyn, Vzn]].
102+
103+
sampling_time: time in seconds.
104+
'''
105+
106+
# Components
107+
x = 0
108+
y = 1
109+
z = 2
110+
111+
# Tamano del sistema
112+
n = len(self.checkpoints_timing)
113+
114+
# Vector de diferencias de tiempo.
115+
h = []
116+
for i in range(0, n-1):
117+
h.append(self.checkpoints_timing[i+1] - self.checkpoints_timing[i])
118+
119+
# Matriz A
120+
A = self.__get_a_matrix(n, h)
121+
122+
# Vector F
123+
Fx = self.__get_F_vector(n, h, x)
124+
Fy = self.__get_F_vector(n, h, y)
125+
Fz = self.__get_F_vector(n, h, z)
126+
127+
# Calculo de Coeficientes
128+
bx = self.__get_b_coefficient(A, Fx)
129+
by = self.__get_b_coefficient(A, Fy)
130+
bz = self.__get_b_coefficient(A, Fz)
131+
132+
ax = self.__get_a_coefficient(n, bx, h, x)
133+
ay = self.__get_a_coefficient(n, by, h, y)
134+
az = self.__get_a_coefficient(n, bz, h, z)
135+
136+
cx = self.__get_c_coefficient(n, bx, h, x)
137+
cy = self.__get_c_coefficient(n, by, h, y)
138+
cz = self.__get_c_coefficient(n, bz, h, z)
139+
140+
dx = self.__get_d_coefficient(n, bx, h, x)
141+
dy = self.__get_d_coefficient(n, by, h, y)
142+
dz = self.__get_d_coefficient(n, bz, h, z)
143+
144+
# Calculo de Posicion, Velocidad y Aceleracion.
145+
# Tamano de los vectores
146+
tv = 0
147+
for i in range(0, n-1):
148+
tv = tv + len(np.arange(0, h[i] + self.sampling_time, self.sampling_time))
149+
150+
# Creacion de Vectores
151+
T = np.zeros(tv)
152+
ori = np.zeros((tv, 3))
153+
traj = np.zeros((tv, 3))
154+
155+
# Variable Auxiliar para acumular la cantidad de tiempos
156+
p = 0
157+
for i in range(0, n-1):
158+
# Tiempo a evaluar en los polinomios
159+
# (de 0 al delta de tiempo del tramo)
160+
Tk = np.arange(0, h[i] + self.sampling_time, self.sampling_time)
161+
# Momento en el cual esta presente el robot en cada posicion
162+
tc = (np.arange(self.checkpoints_timing[i],
163+
self.checkpoints_timing[i+1] + self.sampling_time,
164+
self.sampling_time))
165+
166+
k = len(Tk)
167+
for j in range(0, k):
168+
169+
if component == 'position':
170+
traj[j+p, x] = ((ax[i] * (Tk[j]**3))
171+
+ (bx[i] * (Tk[j]**2))
172+
+ (cx[i]*Tk[j])
173+
+ dx[i])
174+
175+
traj[j+p, y] = ((ay[i] * (Tk[j]**3))
176+
+ (by[i] * (Tk[j]**2))
177+
+ (cy[i]*Tk[j])
178+
+ dy[i])
179+
180+
traj[j+p, z] = ((az[i] * (Tk[j]**3))
181+
+ (bz[i] * (Tk[j]**2))
182+
+ (cz[i]*Tk[j])
183+
+ dz[i])
184+
elif component == 'velocity':
185+
traj[j+p, x] = (3 * ax[i] * (Tk[j]**2)) + (2 * bx[i] * (Tk[j])) + cx[i]
186+
traj[j+p, y] = (3 * ay[i] * (Tk[j]**2)) + (2 * by[i] * (Tk[j])) + cy[i]
187+
traj[j+p, z] = (3 * az[i] * (Tk[j]**2)) + (2 * bz[i] * (Tk[j])) + cz[i]
188+
elif component == 'acceleration':
189+
traj[j+p, x] = (6 * ax[i] * (Tk[j])) + (2 * bx[i])
190+
traj[j+p, y] = (6 * ay[i] * (Tk[j])) + (2 * by[i])
191+
traj[j+p, z] = (6 * az[i] * (Tk[j])) + (2 * bz[i])
192+
193+
# Roll[j+p] = (Tk[j]*(self.checkpoints[i+1][3] - self.checkpoints[i][3])
194+
# + self.checkpoints[i][3])
195+
196+
# Pitch[j+p] = (Tk[j]*(self.checkpoints[i+1][4] - self.checkpoints[i][4])
197+
# + self.checkpoints[i][4])
198+
199+
# Yaw[j+p] = (Tk[j]*(self.checkpoints[i+1][5] - self.checkpoints[i][5])
200+
# + self.checkpoints[i][5])
201+
202+
T[j+p] = tc[j]
203+
p = p + k
204+
205+
return traj

0 commit comments

Comments
 (0)