⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 drinkrobots.tz

📁 本代码用基于steve语言的breve软件编写的
💻 TZ
📖 第 1 页 / 共 3 页
字号:
            distance2 = |(self get-location)-(-50,2,-50)|.
            #robot can seek recycleBin automaticly
            if(distance2<mini-distance2):{
              objectdirection = ((-50,2,-50) - (self get-location)).
              current-velocity = (self get-velocity).
              angle-of-turn = self find-angle from current-velocity to objectdirection.
              self turn-by angle angle-of-turn / 10.
              return 1.    
            }
            
          } 
          return 0.
    #Define a method: a behavior for collectors to deposit bottle when it arrives recycleBin
    + to deposit bottle owndrinkBottleShape(object):
         #get a list of all drink bottles
         owndrinkBottleList = all drinkBottles.
         #get the state of ownbottle state
         ownbottlestate = self get-ownbottle-state.
         mini-distance4 = 250.
         #work out the distance between a collector with an empty bottle and recycleBin
         distance5 =|(self get-location)- (-50,2,-50)|.
         #if a robot has an empty bottle                         
         if((controller get-empty-bottle-exsist)== 1):{
            #find a closest empty bottle which is closer to recycleBin
            for each owndrinkBottleShape in (owndrinkBottleList):{
                distance4 = |(self get-location) - (owndrinkBottleShape get-location)|.
                if(distance4 < mini-distance4):{
                   mini-distance4 = distance4.
                   collectorBotclosestbottle = owndrinkBottleShape.
			              }
            }#end foreach  
            #if the cloest empty bottle is picked up, the distance is less 5m and it has a empty bottle
            #Then deposit the bottle
            if(((collectorBotclosestbottle get-be-pickedup)==3)&&(distance5< 13)&&(ownbottlestate == 0)):{
                #random the location where the empty bottle is deposited in the recycle bin.
                length = random[length].
                width = random[width].
                self set-ownbottle-state value 1.
                collectorBotclosestbottle set-be-pickedup value 4.
                #deposit the empty bottle in the recyle bin
                collectorBotclosestbottle move-drinkBottle to-location (-50,4,-50)+(length,0,width).
                print "A collect rob deposits the empty in the recycle bin".
                return 1.}
        }
        #otherwise wander
          return 0.
    
    #define a method: a behavior for collectors to wander
    + to wander-randomly:
        if( time-since-turn >= random[1000]): {
            angle-of-turn = random[(2 * pi)] - pi.
            self turn-by angle angle-of-turn.
            time-since-turn = 0.
        }
        self point vertex (0,0,1) at (self get-velocity).
        time-since-turn = time-since-turn + 1 .
        return 1.

    ##define a method: this show a subsumption architecture 
    + to activateaction:
        activeateDeposit = (self deposit bottle owndrinkBottleShape).
        activeateseekRecycleBin =(self seek-recycleBin).
        activeateCollect = (self collect bottle bottleShape).
        activeateWander = (self wander-randomly).

           
        robotCommand = noCommand. 
	#the select behavior from hight priority to low priority
        if((robotCommand == noCommand) && (activeateDeposit == 1)):{
            robotCommand = depositbottlecommand.
        }
        if((robotCommand == noCommand) && (activeateseekRecycleBin == 1)):{
            robotCommand = seekRecycleBincommand.
        }
        if(robotCommand == noCommand) && (activeateCollect == 1 ): 
            robotCommand = collectbottlecommand. 
        if(robotCommand == noCommand):
            robotCommand = wanderrandomcommand.
        
        #This is Motor Schemas to execute the selected behavior
        if (robotCommand == depositbottlecommand): {self deposit bottle owndrinkBottleShape.}
        if (robotCommand == seekRecycleBincommand): {self seek-recycleBin.}
        if (robotCommand == collectbottlecommand): {self collect bottle bottleShape.}
        if (robotCommand == wanderrandomcommand): {self wander-randomly.}
    #keep executing activateaction
    + to iterate:
        super iterate.
        self activateaction.
		 

}
#Define a mobile class for drinkBottle
Mobile: drinkBottle (aka drinkBottles){
        #set variables
        + variables:
          drinkBottleShape(object).
          be-pickedup(int).
        # set the shape of drinkbottle and some variables
        + to init:
          #set the shape of bottle as column shape
          drinkBottleShape = (new Shape init-with-polygon-disk radius 1 sides 6 height 6 ).
          self set-shape to drinkBottleShape.
          be-pickedup =0.
        
        #set the state of bottle(picked up or not)
        + to set-be-pickedup value val(int):
           be-pickedup = val.
           
        #return the state of bottle   
        + to get-be-pickedup:
           return be-pickedup.
          
          
        # move bottle to a new location
        + to move-drinkBottle to-location location (vector):
          self move to location.
    
        + to iterate: 
}       

#Define a mobile class for touchSensor which can be used to attach with robots
Mobile : touchSensor (aka touchSensors) {
    # Declare variables
    + variables:
        touchSensorShape(object).
        
    # Set the shape and colour of the touchSensor.
    + to init:
        touchSensorShape = (new PolygonCone init-with radius 1 sides 8 height 5.5). 
        self set-shape to touchSensorShape.
        self set-color to (0.0, 0.0, 1.0).        
    
    # Move this sensor to the new location
    + to move-sensor to-location location (vector):
        self move to location.
        
    # Turn this sensor to a direction    
    + to turn-sensor to-direction velocity (vector):
        self point vertex (0,1,0) at velocity.
   
    + to iterate:        
       
}

#Define a mobile class for wheelEfector which can be used to attach robots        
Mobile : wheelEffector (aka wheelEffectors) {
     # Declare the shape variable and other variables
    + variables:
        wheelEffectorShape(object).
        new-velocity(vector).
        new-rotation(matrix).
        pi(float).
    
    # Set the shape and colour of the wheel effector.
    + to init: 
        wheelEffectorShape = (new PolygonDisk init-with radius 1 sides 12 height 5.5). 
        self set-shape to wheelEffectorShape.
        self set-color to (0.0, 1.0, 0.0).
        pi = 3.14159.        
    
    # Move this effector to the new location
    + to move-effector to-location location (vector):
        self move to location.        
    
    # "Turn this effector to a direction
    + to turn-effector to-direction velocity (vector):
 
        self point vertex (0,1,0) at velocity.
        self rotate around-axis (0,1,0) by pi/2 .
        new-rotation = (self get-rotation).
        new-velocity = new-rotation * velocity.
        self point vertex (0,1,0) at new-velocity.
        
    + to iterate:
}

#Define a stationary class for four fences(left, right, front and back)
Stationary: fourFences{
        #declare variables for fences
        + variables:
           frontFence(object).
           backFence(object).
           leftFence(object).
           rightFence(object).
        #set the size, color and location of fences
        + to init:
           #print "Creating four Fences".
           #set the drinkMachine as the cube shape
           frontFence = (new Cube init-with size(160,8,1)).
           self register with-shape (frontFence) at-location (0, 2, 80).
           self set-color to (6, 1, .4).
           
           backFence = (new Cube init-with size(160,8,1)).
           self register with-shape (backFence) at-location (0, 2, -80).
           self set-color to (6, 1, .4).
           
           leftFence = (new Cube init-with size(1,8,160)).
           self register with-shape (leftFence) at-location (-80, 2, 0).
           self set-color to (6, 1, .4).
           
           rightFence = (new Cube init-with size(1,8,160)).
           self register with-shape (rightFence) at-location (80, 2, 0).
           self set-color to (6, 1, .4).
         
        + to iterate:           
           
           
}
#Define a stationary class for recycleBin 
Stationary: recycleBin{
        #Define variable for recycleBin
        + variables:
           recycleBinShape(object).
        #Init the size, location, color of recyleBin  
        + to init:
           #print "Creating the recyle bin".
           #set the drinkMachine as the cube shape
           recycleBinShape = (new Cube init-with size(12,2,12)).
           self register with-shape (recycleBinShape) at-location (-50, 2, -50).
           self set-color to (.9, .9, .9).
        
        + to inerate:
}
#Define a stationary class for drinkMachine
Stationary: drinkMachine{
        #Define the shape variable for drinkMachine
        + variables:
           drinkMachineShape(object).
        
        #init the size, location, color of drinkMachine    
        + to init:
           #print "Creating the drinkMachine on the stage".
           #set the drinkMachine as the cube shape
           drinkMachineShape = (new Cube init-with size(8,6,8)).
           self register with-shape (drinkMachineShape) at-location (50,2,50).
           self set-color to (.1,1,.1).
           
        + to inerate:

}
#Define a stationary class for 10 thirstyProgrammers
Stationary: thirstyProgrammers{
        #Define the shape variable for thirstyProgrammers
        + variables:
           thirstyProgrammersShape(object).
        
        #Also,to init the shape, location, color of thirstyProgrammers   
        + to init:
          #print "Creating 10 thirstyProgrammers on the stage with random locations".
          #set the thirstyProgrammers as a sphere shape
          thirstyProgrammersShape = ( new Sphere init-with radius 3).
          #random the init location of the thirstyProgrammers
          self register with-shape (thirstyProgrammersShape) at-location (random[60],3,random[40])-(random[60],1.5,random[70]).
          self set-color to (4,.4,.2).
          self set-neighborhood-size to 20 .
          

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -