Version 2

From GeoMod

Jump to: navigation, search

from Numeric import*
from visual import *
from random import uniform

class Wrangler:
    def __init__(self,pos,scale=1):
        self.pos = pos		#REQUIRED
    	self.scale = scale	#REQUIRED
    	self.name = "prototype" #REQUIRED

        self.body = frame (pos= pos)
        self.chassis = box(frame=self.body, length = 7*scale, height = 0.5*scale, width=3*scale, pos=(0.5*scale,-0.5*scale,0*scale),color=(.23,.23,.23))
        
        self.wheel_RR = ring(frame=self.body, radius=1*scale, axis=(0,0,1*scale),thickness=0.5*scale,color=(1,.98,.11),pos=(-1.8*scale,-0.9*scale,-2.5*scale))
        self.wheel_RL = ring(frame=self.body, radius=1*scale, axis=(0,0,1*scale),thickness=0.5*scale,color=(1,.98,.11),pos=(-1.8*scale,-0.9*scale,2.5*scale))
        self.wheel_FR = ring(frame=self.body, radius=1*scale, axis=(0,0,1*scale),thickness=0.5*scale,color=(1,.98,.11),pos=(2.5*scale,-0.9*scale,-2.5*scale))
        self.wheel_FL = ring(frame=self.body, radius=1*scale, axis=(0,0,1*scale),thickness=0.5*scale,color=(1,.98,.11),pos=(2.5*scale,-0.9*scale,2.5*scale))
        
        self.axel_1= cylinder(frame=self.body,  pos=(-1.8*scale,-.9*scale,-2.95*scale),axis=(0,0,5.9*scale),radius=0.3*scale,color=(.23,.23,.23))
        self.axel_2= cylinder(frame=self.body,  pos=(2.5*scale,-.9*scale,-2.95*scale),axis=(0,0,5.9*scale),radius=0.3*scale,color=(.23,.23,.23))
        
        self.grill= box(frame=self.body,length = .2*scale, height = 0.7*scale, width=1.3*scale, pos=(4.1*scale,0.5*scale,0), color=(.23,.23,.23))
        self.grill1= ellipsoid (frame=self.body, length=.15*scale, height=0.7*scale, width=.2*scale, color=color.white,pos=(4.15*scale,0.5*scale,-.5*scale))
        self.grill2= ellipsoid (frame=self.body, length=.15*scale, height=0.7*scale, width=.2*scale, color=color.white,pos=(4.15*scale,0.5*scale,-.3*scale))
        self.grill3= ellipsoid (frame=self.body, length=.15*scale, height=0.7*scale, width=.2*scale, color=color.white,pos=(4.15*scale,0.5*scale,-.1*scale))
        self.grill4= ellipsoid (frame=self.body, length=.15*scale, height=0.7*scale, width=.2*scale, color=color.white,pos=(4.15*scale,0.5*scale,.1*scale))
        self.grill5= ellipsoid (frame=self.body, length=.15*scale, height=0.7*scale, width=.2*scale, color=color.white,pos=(4.15*scale,0.5*scale,.3*scale))
        self.grill6= ellipsoid (frame=self.body, length=.15*scale, height=0.7*scale, width=.2*scale, color=color.white,pos=(4.15*scale,0.5*scale,.5*scale))
        
        self.light_R= sphere(frame=self.body, radius=.25*scale, color=color.yellow ,pos=(4.0*scale,0.8*scale,-1*scale))
        self.light_L= sphere(frame=self.body, radius=.25*scale, color=color.yellow ,pos=(4.0*scale,0.8*scale,1*scale))
        self.caution_lightR= sphere(frame=self.body, radius=.2*scale, color=color.red ,pos=(4.0*scale,0.35*scale,-0.85*scale))
        self.caution_lightL= sphere(frame=self.body, radius=.2*scale, color=color.red ,pos=(4.0*scale,0.35*scale,0.85*scale))
        
        self.front= box(frame=self.body, length = .2*scale, height = 1.5*scale, width=2.5*scale, pos=(4.0*scale,.5*scale,0),color=color.black)        
        self.bumper=box(frame=self.body, length = .5*scale, height = .5*scale, width=3.5*scale, pos=(4.2*scale,-0.5*scale,0),color=(.5,0,.3))
        self.top_bumper= box(frame=self.body, length = .5*scale, height = .5*scale, width=1*scale, pos=(4.2*scale,-0.2*scale,0),color=(.5,0,.3))
        
        self.hood = box (frame=self.body, length=1.1*scale, height=.2*scale, width=2.5*scale, color=(.11,.62,.29),pos=(3.55*scale,1.25*scale,0))
        self.front_seat= box (frame=self.body, length=1.3*scale, height=1*scale, width=.2*scale, color=(.5,0,.3),pos=(.8*scale,.2*scale,-1.3*scale))
        self.front_seat2= box (frame=self.body, length=1.3*scale, height=1*scale, width=.2*scale, color=(.5,0,.3),pos=(.8*scale,.2*scale,1.3*scale))
        self.front_seat3= box (frame=self.body, length=1.3*scale, height=.2*scale, width=2.6*scale, color=(.5,0,.3),pos=(.8*scale,.6*scale,0))
        self.front_seat_back = box (frame=self.body, length=.2*scale, height=2.8*scale, width=2.8*scale, color=(.23,.23,.23),pos=(.2*scale,.8*scale,0))
        self.windsheild= box(frame=self.body, length=.3*scale, height=2*scale, width=.3*scale, color=(.11,.62,.29),pos=(2.4*scale,2.1*scale,-1.4*scale),axis=(1,.7*scale,0))
        self.windsheild2= box(frame=self.body, length=.3*scale, height=2*scale, width=.3*scale, color=(.11,.62,.29),pos=(2.4*scale,2.1*scale,1.4*scale),axis=(1,.7*scale,0))
        self.windsheild3= cylinder(frame=self.body,  pos=(1.8*scale,2.9*scale,-1.55*scale),axis=(0,0,3.1*scale),radius=0.2*scale,color=(.11,.62,.29))

        self.sidepanel_R= box(frame=self.body, length=2*scale, height=1.6*scale, width=.4*scale, color=(.11,.62,.29),pos=(3.1*scale,.55*scale,-1.3*scale))
        self.sidepanel_L= box(frame=self.body, length=2*scale, height=1.6*scale, width=.4*scale, color=(.11,.62,.29),pos=(3.1*scale,.55*scale,1.3*scale))

        self.rollbar= cylinder(frame=self.body,  pos=(-1*scale,2.9*scale,-1.55*scale),axis=(0,0,3.1*scale),radius=0.2*scale,color=(.5,0,.3))
        self.rollbar2= cylinder(frame=self.body,  pos=(-1.1*scale,2.9*scale,-1.4*scale),axis=(3*scale,0,0),radius=0.2*scale,color=(.5,0,.3))
        self.rollbar3= cylinder(frame=self.body,  pos=(-1.1*scale,2.9*scale,1.4*scale),axis=(3*scale,0,0),radius=0.2*scale,color=(.5,0,.3))
        self.rollbar4= cylinder(frame=self.body,  pos=(-1.1*scale,2.9*scale,-1.4*scale),axis=(-1.2*scale,-1.7*scale,0),radius=0.2*scale,color=(.5,0,.3))
        self.rollbar5= cylinder(frame=self.body,  pos=(-1.1*scale,2.9*scale,-1.4*scale),axis=(0,-1.7*scale,0),radius=0.2*scale,color=(.5,0,.3))
        self.rollbar6= cylinder(frame=self.body,  pos=(-1.1*scale,2.9*scale,1.4*scale),axis=(-1.2*scale,-1.7*scale,0),radius=0.2*scale,color=(.5,0,.3))
        self.rollbar7= cylinder(frame=self.body,  pos=(-1.1*scale,2.9*scale,1.4*scale),axis=(0,-1.7*scale,0),radius=0.2*scale,color=(.5,0,.3))

        self.trunk = box (frame=self.body, length=3*scale, height=1.7*scale, width=3.1*scale, color=(.11,.62,.29),pos=(-1.4*scale,.5*scale,0))
        self.back_bumper=box(frame=self.body, length = .5*scale, height = .5*scale, width=3.5*scale, pos=(-3.0*scale,-0.4*scale,0),color=(.5,0,.3))
        
        
        
    def jump (self, howhigh):
        dt=0.01
        while (self.body.y <= howhigh):
            rate(50)
            self.body.y= self.body.y + howhigh * dt
        while (self.body.y > 0):
            rate(50)      
            self.body.y = self.body.y - howhigh *dt

    '''def move(self, new_pos):
        dt=0.07
        while (self.body.x <> new_pos.x):
            rate(50)
            self.body.x= self.bod
            y.x + dt * new_pos.x
            
        self.body.x = new_pos.x'''
    def move(self, new_pos):		#REQUIRED
    	self.pos = new_pos		#REQUIRED
        self.body.pos = new_pos         #REQUIRED

    def choose_direction (self, local_topo, target_x, target_y, target_dir, dx, max_slope): #REQUIRED
        '''local_topo is a 3x3 array of the area around the car
        target_dir is a vector with the direction of the target relative to the car
        eg: vector (1,0,0) is the x direction (east)
             vector (0,0,-1) is the -z direction (North)
             vec (1,0,-1) is 45 degrees east of due north
        Returns a vector indication which direction you want your car to go'''
        choice1= target_dir
        choice2= vector(uniform(0,1.0),uniform(0,1.0),0) #a random direction choice
        #print 'choice2',choice2
        choice3= vector(uniform(0,-1),uniform(0,-1),0)
        choice4= vector(uniform(0,1.0),uniform(0,-1),0)
        choice5=vector(uniform(0,-1.0), uniform(0,1.0),0)
        choice6= vector(uniform(-1.0,1.0), uniform(-1.0,1.0),0)
        x=0
        
        final_choice= vector(0,0,0)
        current_dir= choice1
        #print 'target dir', target_dir
        #print 'final_choice', final_choice
        #print 'current direction', current_dir
        
        while final_choice.x == 0:
            #print 'current direction2', current_dir
            
            if (current_dir.x < 0.5) and (target_dir.x > -0.5):
                X = 0
                j = 1
            if (current_dir.y < 0.5) and (target_dir.z > -0.5):
                Y= 0
                i= 1
            if (current_dir.x <= -0.5):
                X = -1
                j= 0
            if (current_dir.y <= -0.5):
                Y = -1
                i = 0
            if (current_dir.x >= 0.5):
                X = 1
                j= 2
            if (current_dir.y >= 0.5):
                Y = 1
                i = 2
            print 'X=',X, 'Z=',Y, 'i=',i, 'j=',j
            slope = ((local_topo[i,j]-local_topo[1,1])/100)
            #print 'slope of current direction', slope

            if (((local_topo[i,j]-local_topo[1,1])/dx) < max_slope) and (((local_topo[i,j]-local_topo[1,1])/dx) > -max_slope):
                final_choice = current_dir
            elif (x == 1):
                current_dir= choice2
                final_choice.x= 0
            elif (x==2):
                final_choice.x= 0
                current_dir=choice3
            elif (x==3):
                final_choice.x= 0
                current_dir=choice4
            elif (x==4):
                final_choice.x= 0
                current_dir=choice5
            elif (x > 4):
                final_choice.x= 0
                current_dir=choice6
                
            #print 'final_choice', final_choice
            #print 'current_dir', current_dir
            #print 'loop counter=',x
            #final_choice=target_dir

        #u=1
        previous_dir = final_choice
        direction_choice = vector(X,Y,0)
        #direction_choice = final_choice
        #direction_choice= final_choice

        return direction_choice 

Personal tools