Python - Uso de python

   
Vista:

Uso de python

Publicado por Jose Angel Miranda Calero jocolo5@hotmail.com (1 intervención) el 23/10/2012 17:53:51
Hola, mi nombre es Jose, ahora me encuentro haciendo un proyecto de robótica (mediante Gazebo etc) y tengo que desarrollar una función que haga lo siguiente:

The function is called from GUI when the robot is in the corner near the pool, right near the green object and oriented towards this object.
Plan robot way to the room behind the lab (upper right room on fine.pgm map).
Then plan robot way to the lower left corner of the biggest room (on fine.pgm map), make sure the robot is oriented towards the pool.
Then drive reactively towards the green object. Stop near the object. Function Finished() should be executed on such an event.

el codigo que he implementado me da error, no me deja compilar, nose porque, la cosa esque nunca he programado en python y estoy muy perdido, si alguien pudiera ayudarme se lo agradeceria:

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
from playerc import *
 
import math
 
def IsDebug():
    return False
 
 
#get the distance by X and Y
def GetDistanceByCoords(x, y):
    return math.sqrt(x*x+y*y)
 
#convert angle to range (-PI;PI]
def NormalizeAngle(a):
    while a <= -math.pi:
        a += 2.0*math.pi
    while a > math.pi:
        a -= 2.0*math.pi
    return a
 
def Finished ():
    print "FINISHED!!!"
 
def Drive(self, c, p_write, blob, planner, abortEvent):
    print "Drive executed"
 
    IsLongRoomInTheBackVisited = False
    IsLowerLeftCornerOfBigRoomVisited = False
    IsNearTheObject = False
 
 
    ##To make planner go to the desired coordinates, issue the following commands:
   # planner.set_cmd_pose(gx, gy, ga)
    #planner.enable(1)
    ##gx, gy and ga are desired position and orientation
 
    ##you can check if the planner has reached a goal by checking  planner.path_done
    ##it is equal to 0, if the goal is not yet reached
    ##set it to 0 before issuing a new goal
    #planner.path_done =0    
 
    ##during the movement towards the goal, wavefront can lose the goal...
    ##you can identify this event by checking for planner.waypoint_count
    ##it should be either 0 when no goal is set, or >=2, when the goal is set
    ##if planner.waypoint_count==1, then wavefront lost its goals 
    ## and the set_cmd_pose command should be issued again.
 
    #robot should be somewhere near the pool when "GO" button is pressed.
 
    while not IsLongRoomInTheBackVisited and not abortEvent():
        c.read()
 
        #START: PUT YOUR CODE HERE
 
        #calculate the desired position on your map yourself
        #Center of the image is 0,0. 
        #X axis is oriented towards right, Y axis - towards top. 
        #0 degrees orientation is along X axis.
        planner.set_cmd_pose(14, -7, NormalizeAngle(155))
        planner.enable(1)
        #give a command to planner to go to the desired position, if planner reached this position,  
        #make IsLongRoomInTheBackVisited = True
        if (planner.path_done==1):
 
    print "Goal Found"
    IsLongRoomInTheBackVisited = True
    planner.path_done=0
 
    elif (planner.waypoint_count==0):
    planner.set_cmd_pose(14, -7, NormalizeAngle(155))
        planner.enable(1)
 
    elif (planner.waypoint_count==1):
    planner.set_cmd_pose(14, -7, NormalizeAngle(155))
        planner.enable(1)
 
    else:
    print "Going towards goal!!!"
 
        #planner's properties are similar to the ones documented here:
        #http://playerstage.sourceforge.net/doc/Player-2.1.0/player/structplayerc__planner__t.html#_details
 
        #END: PUT YOUR CODE HERE
    #while end
 
    while not IsLowerLeftCornerOfBigRoomVisited and not abortEvent():
        c.read()
 
        #START: PUT YOUR CODE HERE
 
        #calculate the desired position on your map yourself
        #Center of the image is 0,0. 
        #X axis is oriented towards right, Y axis - towards top. 
        #0 degrees orientation is along X axis.
        planner.set_cmd_pose(-14, -7, NormalizeAngle(45))
        planner.enable(1)
        #give a command to planner to go to the desired position, if planner reached this position,  
        #make IsLowerLeftCornerOfBigRoomVisited = True
        if planner.path_done:
    print "Goal Found!!!"
    IsLowerLeftCornerOfBigRoomVisited = True
    planner.path_done=0
 
    elif planner.waypoint_count==0:
    planner.set_cmd_pose(-14, -7, NormalizeAngle(45))
        planner.enable(1)
 
    elif planner.waypoint_count==1:
    planner.set_cmd_pose(-14, -7, NormalizeAngle(45))
        planner.enable(1)
 
    else:
    print "Going towards goal!!!"
        #planner's properties are similar to the ones documented here:
        #http://playerstage.sourceforge.net/doc/Player-2.1.0/player/structplayerc__planner__t.html#_details
 
        #END: PUT YOUR CODE HERE
   #while end
 
    #while not IsNearTheObject and not abortEvent():
        #c.read()
 
        #START: PUT YOUR CODE HERE
 
        #drive towards the green object using reactive steering, when done,  
        #make IsNearTheObject = True
 
        #END: PUT YOUR CODE HERE
    #while end
 
    Finished()
return
#Drive end
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder
Imágen de perfil de xve

Uso de python

Publicado por xve (1351 intervenciones) el 23/11/2012 08:15:03
Hola Jose, tienes problema de tabulación... Python, tienes que estar tabulado a la perfección!!!

Saludos
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar