-
Notifications
You must be signed in to change notification settings - Fork 0
/
07anexos.tex
741 lines (662 loc) · 17.3 KB
/
07anexos.tex
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
\secnumberlesssection{ANEXOS}
\begin{comment}
\textbf{PREPARACIÓN DEL AMBIENTE DE LA MEMORIA}
\begin{verbatim}
sudo sh -c 'echo "deb http://packages.ros.org/ros/ubuntu
$(lsb_release -sc) main" > /etc/apt/sources.list.d/ros-latest.list'
\end{verbatim}
\begin{verbatim}
sudo apt install curl # if you haven't already installed curl
curl -s https://raw.githubusercontent.com/ros/rosdistro/master/ros.asc
| sudo apt-key add -
\end{verbatim}
\begin{verbatim}
sudo apt update
\end{verbatim}
\begin{verbatim}
sudo apt install ros-noetic-desktop-full
\end{verbatim}
\begin{verbatim}
echo "source /opt/ros/noetic/setup.bash" >> ~/.bashrc
source ~/.bashrc
\end{verbatim}
\begin{verbatim}
sudo apt install python3-rosdep python3-rosinstall
python3-rosinstall-generator python3-wstool build-essential
\end{verbatim}
\begin{verbatim}
sudo apt install python3-rosdep
\end{verbatim}
\begin{verbatim}
sudo rosdep init
rosdep update
\end{verbatim}
\newpage
\textbf{SECCIÓN DE CÓDIGOS DEL TIPO LAUNCH FILE}
\textbf{ros\_serial.launch}
\begin{verbatim}
<launch>
<node
pkg="rosserial_python"
name="arduino_node"
type="serial_node.py">
<param
name="port"
value="/dev/ttyACM0"
/>
<param
name="baud"
value="115200"
/>
</node>
</launch>
\end{verbatim}
\textbf{ld19.launch}
\begin{verbatim}
<launch>
<node
name="LD19"
pkg="ldlidar_stl_ros"
type="ldlidar_stl_ros_node">
<param
name="product_name"
value="LDLiDAR_LD19"/>
<param
name="topic_name"
value="scan"/>
<param
name="port_name"
value ="/dev/ttyUSB0"/>
<param
name="frame_id"
value="base_laser"/>
<param
name="laser_scan_dir"
type="bool"
value="true"/>
<param
name="enable_angle_crop_func"
type="bool"
value="false"/>
<param
name="angle_crop_min"
type="double"
value="135.0"/>
<param
name="angle_crop_max"
type="double"
value="225.0"/>
</node>
<node
name="base_to_laser"
pkg="tf"
type="static_transform_publisher"
args="0.0 0.0 0.18 4.71 0.0 0.0 base_link base_laser 50"/>
</launch>
\end{verbatim}
\textbf{gazebo.launch}
\begin{verbatim}
<launch>
<arg
name="extra_gazebo_args"
default="--verbose"/>
<arg
name="world_file"
default="$(
find robocop_description)/
worlds/
simulation_world_00/
simulation_world_00.world"/>
<param
name="robot_description"
command="$(find xacro)/xacro
$(find robocop_description)/urdf/robocop.xacro"/>
<node
name="spawn_urdf"
pkg="gazebo_ros"
type="spawn_model"
args="-param robot_description -urdf -model robocop"/>
<include
file="$(find gazebo_ros)/launch/empty_world.launch">
<arg
name="world_name"
value="$(arg world_file)"/>
<arg
name="paused"
value="false"/>
<arg
name="use_sim_time"
value="true"/>
<arg
name="gui"
value="true"/>
<arg
name="headless"
value="false"/>
<arg
name="debug"
value="false"/>
<arg
name="extra_gazebo_args"
value="$(arg extra_gazebo_args)"/>
</include>
</launch>
\end{verbatim}
\textbf{camera.launch}
\begin{verbatim}
<launch>
<node
name="usb_cam"
pkg="usb_cam"
type="usb_cam_node">
<param
name="video_device"
value="/dev/video2" />
<param
name="image_width"
value="640"/>
<param
name="image_height"
value="480"/>
<param
name="pyxel_format"
value="yuvj420p"/>
<param
name="image_format"
value="rgb8"/>
<param
name="camera_frame_id"
value="usb_cam"/>
<param
name="io_method"
value="mmap"/>
</node>
<node
name="image_view"
pkg="image_view"
type="image_view"
respawn="false">
<remap
from="image"
to="usb_cam/image_raw"/>
<param
name="autosize"
value="true"/>
</node>
</launch>
\end{verbatim}
\textbf{robocop\_map.launch}
\begin{verbatim}
<launch>
<include
file="$(find robocop_description)/launch/ld19.launch"/>
<include
file="$(find robocop_description)/launch/mapping/display_map.launch"/>
<include
file="$(find robocop_description)/launch/mapping/ps4.launch"/>
<include
file="$(find robocop_description)/launch/mapping/hector_mapping.launch"/>
</launch>
\end{verbatim}
\textbf{ps4.launch}
\begin{verbatim}
<launch>
<group ns="j1">
<node
name="ds4_joystick"
pkg="joy"
type="joy_node">
<param
name="dev"
value="/dev/input/js1" />
</node>
</group>
<node
pkg="robocop_description"
name="ps4Controller"
type="ps4Controller.py"/>
<node
pkg="rosserial_python"
name="arduino_node"
type="serial_node.py">
<param
name="port"
value="/dev/ttyACM0" />
<param
name="baud"
value="115200" />
</node>
</launch>
\end{verbatim}
\textbf{hector\_mapping.launch}
\begin{verbatim}
<launch>
<node
pkg="hector_mapping"
type="hector_mapping"
name="hector_mapping">
<param
name="base_frame"
value="base_link" />
<param
name="odom_frame"
value="base_link" />
</node>
</launch>
\end{verbatim}
\textbf{display\_map.launch}
\begin{verbatim}
<launch>
<arg
name="model"
default="$(find robocop_description)/urdf/robocop.xacro"/>
<arg
name="multi_robot_name"
default=""/>
<param
name="robot_description"
command="$(find xacro)/xacro $(arg model)"/>
<node
pkg="rviz"
type="rviz" name="rviz"
required="true"
args="-d $(find robocop_description)/launch/robocop.rviz"/>
<node
pkg="robot_state_publisher"
type="robot_state_publisher"
name="robot_state_publisher">
<param
name="publish_frequency"
type="double"
value="50.0"/>
<param
name="tf_prefix"
value="$(arg multi_robot_name)"/>
</node>
<node
name="joint_state_publisher"
pkg="joint_state_publisher"
type="joint_state_publisher"/>
</launch>
\end{verbatim}
\textbf{robocop\_auto.launch}
\begin{verbatim}
<launch>
<include
file="$(find robocop_description)/launch/ld19.launch"/>
<include
file="$(find robocop_description)/launch/auto/display_auto.launch"/>
<include
file="$(find robocop_description)/launch/ros_serial.launch"/>
</launch>
\end{verbatim}
\textbf{display\_auto.launch}
\begin{verbatim}
<launch>
<arg
name="model"
default="$(find robocop_description)/urdf/robocop.xacro"/>
<arg
name="multi_robot_name"
default=""/>
<param
name="robot_description"
command="$(find xacro)/xacro $(arg model)"/>
<node
pkg="rviz" type="rviz"
name="rviz" required="true"
args="-d $(find robocop_description)/launch/robocop.rviz"/>
<node
pkg="robot_state_publisher"
type="robot_state_publisher"
name="robot_state_publisher">
<param
name="publish_frequency"
type="double"
value="50.0" />
<param
name="tf_prefix"
value="$(arg multi_robot_name)"/>
</node>
<node
name="joint_state_publisher"
pkg="joint_state_publisher"
type="joint_state_publisher"/>
<node
name="map_server"
pkg="map_server"
type="map_server"
args="$(
find robocop_description)/
worlds/
real_world_00/
real_world_00.yaml" />
<include
file="$(
find robocop_description)/
launch/
auto/
amcl_robocop.launch"/>
<node
pkg="move_base"
type="move_base"
respawn="false"
name="move_base"
output="screen">
<param
name="base_local_planner"
value="dwa_local_planner/DWAPlannerROS" />
<rosparam
file="$(
find robocop_description)/
codes/
navigation_stack/
costmap_common_params.yaml"
command="load"
ns="global_costmap" />
<rosparam
file="$(
find robocop_description)/
codes/
navigation_stack/
costmap_common_params.yaml"
command="load"
ns="local_costmap" />
<rosparam
file="$(
find robocop_description)/
codes/
navigation_stack/
local_costmap_params.yaml"
command="load" />
<rosparam
file="$(
find robocop_description)/
codes/
navigation_stack/
global_costmap_params.yaml"
command="load" />
<rosparam
file="$(
find robocop_description)/
codes/
navigation_stack/
move_base_params.yaml"
command="load" />
<rosparam file="$(
find robocop_description)/
codes/
navigation_stack/
dwa_local_planner_params.yaml"
command="load" />
</node>
</launch>
\end{verbatim}
\textbf{amcl\_robocop.launch}
\begin{verbatim}
<launch>
<node
pkg="amcl"
type="amcl"
name="amcl">
<param
name="min_particles"
value="500"/>
<param
name="max_particles"
value="3000"/>
<param
name="kld_err"
value="0.02"/>
<param
name="update_min_d"
value="0.20"/>
<param
name="update_min_a"
value="0.20"/>
<param
name="resample_interval"
value="1"/>
<param
name="transform_tolerance"
value="0.5"/>
<param
name="recovery_alpha_slow"
value="0.00"/>
<param
name="recovery_alpha_fast"
value="0.00"/>
<param
name="gui_publish_rate"
value="50.0"/>
<param
name="laser_max_range"
value="8"/>
<param
name="laser_min_range"
value="0.3"/>
<param
name="laser_max_beams"
value="180"/>
<param
name="laser_z_hit"
value="0.5"/>
<param
name="laser_z_short"
value="0.05"/>
<param
name="laser_z_max"
value="0.05"/>
<param
name="laser_z_rand"
value="0.5"/>
<param
name="laser_sigma_hit"
value="0.2"/>
<param
name="laser_lambda_short"
value="0.1"/>
<param
name="laser_likelihood_max_dist"
value="2.0"/>
<param
name="laser_model_type"
value="likelihood_field"/>
<param
name="odom_model_type"
value="diff"/>
<param
name="odom_alpha1"
value="0.1"/>
<param
name="odom_alpha2"
value="0.1"/>
<param
name="odom_alpha3"
value="0.1"/>
<param
name="odom_alpha4"
value="0.1"/>
<param
name="odom_frame_id"
value="odom"/>
<param
name="base_frame_id"
value="base_link"/>
</node>
</launch>
\end{verbatim}
\newpage
\textbf{SECCIÓN DE CÓDIGOS PARA EL CONTROL}
\textbf{ps4Controller.py}
\begin{verbatim}
#!/usr/bin/env python
from sensor_msgs.msg import Joy
import sys, rospy
from geometry_msgs.msg import Twist
def chatter_callback(mensaje):
joystick_izquierdo = (
round(mensaje.axes[0],
3),
round(mensaje.axes[1], 3)
)
joystick_derecho = (
round(mensaje.axes[2],
3),
round(mensaje.axes[5], 3)
)
botones = (
mensaje.buttons[1],
mensaje.buttons[2],
mensaje.buttons[3],
mensaje.buttons[0])
# Publish data to cmd_vel topic
publisherMotores = rospy.Publisher('/cmd_vel', Twist, queue_size=10)
twist = Twist()
twist.linear.x = joystick_izquierdo[1]
twist.angular.z = joystick_derecho[0]
publisherMotores.publish(twist)
def nodoPS4():
nombreNodo = "nodo_ps4"
idUnico = True
rospy.init_node(nombreNodo, anonymous = idUnico)
nombreTopico = "/j1/joy"
tipoTopico = Joy
rospy.Subscriber(nombreTopico, tipoTopico, chatter_callback)
rospy.spin()
if __name__ == "__main__":
global arduino
nodoPS4()
\end{verbatim}
\newpage
\textbf{SECCIÓN DE CÓDIGOS PARA LA CÁMARA}
\textbf{camera.py}
\begin{verbatim}
#!/usr/bin/env python
import cv2
import numpy as np
import time
# Create a VideoCapture object
cap = cv2.VideoCapture(2)
# Check if camera opened successfully
if (cap.isOpened()== False):
print("Error opening video stream or file")
# Read until video is completed
while(cap.isOpened()):
# Capture frame-by-frame
ret, frame = cap.read()
if ret == True:
# Change the display size
frame = cv2.resize(frame, (320, 640))
# Display the resulting frame
cv2.imshow('Frame',frame)
# Press Q on keyboard to exit
if cv2.waitKey(25) & 0xFF == ord('q'):
break
# Break the loop
else:
break
# When everything done, release the video capture object
cap.release()
\end{verbatim}
\newpage
\textbf{SECCIÓN DE CÓDIGOS PARA LOS MOTORES}
\textbf{controller\_motor.ino}
\begin{verbatim}
// Se importan las librerías
#include <ros.h>
#include <AFMotor.h>
// Se importan los mensajes
#include <geometry_msgs/Twist.h>
// Variables globales de ROS
ros::NodeHandle nHandler;
// Se instancian las variables
float linearVelocity;
float angularVelocity;
float turnRightVel;
float turnLeftVel;
int forwardRight, forwardLeft, turnRight, turnLeft;
AF_DCMotor Motor1(3);
AF_DCMotor Motor2(4);
const byte encoder_rightA = 18;
const byte encoder_rightB = 19;
const byte encoder_leftA = 20;
const byte encoder_leftB = 21;
static long counter_right = 0;
static long counter_left = 0;
static long counter_right_old = 0;
static long counter_left_old = 0;
volatile bool fired_right, fired_left;
volatile bool up_right, up_left;
double x = 0;
double y = 0;
double theta = 0;
double rightVelocity = 0.0;
double leftVelocity = 0.0;
int long currentTime = 0;
int long previousTime = 0;
float map_float(
float x,
float in_min,
float in_max,
float out_min,
float out_max) {
return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
}
void callback(const geometry_msgs::Twist& vel){
linearVelocity = vel.linear.x;
angularVelocity = vel.angular.z;
int right_velocity = 150;
int left_velocity = 150;
if (linearVelocity>0.1){
Motor1.run(FORWARD);
Motor2.run(FORWARD);
Motor1.setSpeed(right_velocity);
Motor2.setSpeed(left_velocity);
}
if (linearVelocity<-0.1){
Motor1.run(BACKWARD);
Motor2.run(BACKWARD);
Motor1.setSpeed(right_velocity);
Motor2.setSpeed(left_velocity);
}
if (angularVelocity>0.1){
Motor1.run(FORWARD);
Motor2.run(BACKWARD);
Motor1.setSpeed(right_velocity);
Motor2.setSpeed(left_velocity);
}
if (angularVelocity<-0.1){
Motor1.run(BACKWARD);
Motor2.run(FORWARD);
Motor1.setSpeed(right_velocity);
Motor2.setSpeed(left_velocity);
}
if (abs(angularVelocity)<0.1 and abs(linearVelocity)<0.1){
Motor1.setSpeed(0);
Motor2.setSpeed(0);
}
}
// Creación de los nodos de ROS
ros::Subscriber<geometry_msgs::Twist> nodo_vel("cmd_vel", callback);
// Variables para la odometría
double odom_x = 1.0;
double odom_y = 0.0;
double odom_thet = 1.57;
void setup(){
// Se ajustan los nodos
nHandler.getHardware()->setBaud(115200);
nHandler.initNode();
nHandler.subscribe(nodo_vel);
// Se ajustan los motores
Motor1.setSpeed(0);
Motor2.setSpeed(0);
Motor1.run(RELEASE);
Motor2.run(RELEASE);
Serial.begin(115200);
}
void loop(){
nHandler.spinOnce();
}
\end{verbatim}
\end{comment}