Programming the Fire Fighter
        in RCX-Code

for more information about the technical reference to the RCX-Programming see: www.legomindstorms.com

Here the source-code for the Fire Fighter:
 
 
define#
variable 1: AverageTemperature
variable 2: LightValue
variable 3: TemperatureValue

SelectPrgm(slot_5)

BeginOfTask(Main)
   Float(Motor_B)                           {Propeller-motor must float}
   SetRwd(Motor_B)                      {Propeller must turn to the right direction}
   SetFwd(Motor_A+Motor_C)     {Direction of movement}
   SetPower(Motor_A+Motor_C,Con,1)  {Move slowly}
   On(Motor_A+Motor_C)              {Go}
 
   SetSensorType(Sensor_2,Light_Type)
   SetSensorType(Sensor_3,Temp_Type)
   SetSensorMode(Sensor_2,Percent_Mode,0) {0..100; 0: light is left; 1: light is right}
   SetSensorMode(Sensor_3,Raw_Mode,0)  {1023..0; 1023 is cold; 0 is hot}
 
   StartTask(Task_1)                     {react on diff light}
   StartTask(Task_2)                     {Tatitata}

   {................determine the average temperature.....................}

   SetVar(AverageTemperature,Con,0)
 
   Loop(Con,40)                            {40 tests}
      SetVar(TemperatureValue,SenVal,Sensor_3)
      SumVar(AverageTemperature,Var,TemperatureValue)
                         {Sum of the  temperature values}
      Wait(Con,5)   {wait 5 cs}
   EndLoop()

   DivVar(AverageTemperature,Con,40)   {Average}
   SubVar(AverageTemperature,Con,5)    {fluctuation}

   {..................................................................................................}

   StartTask(Task_3)                {react if hot source found}
EndOfTask()

{******************************************************************}

BeginOfTask(Task_1)                   {react on light}
Loop(Con,Forever)
   SetVar(LightValue,SenVal,Sensor_2)
    If(Var,LightValue,LT,Con,48)  {Light is left}
       SetFwd(Motor_A) {go to the left}
       On(Motor_A)
       Off(Motor_C)
    else()
        If(Var,LightValue,GT,Con,52)  {Light is right}
            SetFwd(Motor_C) {go to the right}
            On(Motor_C)
            Off(Motor_A)
         else()        {Light is in the midth}
            SetFwd(Motor_A+Motor_C)
            On(Motor_A+Motor_C)
          endif()
    endif()

Wait(Con,1)
EndLoop()
EndOfTask()

{******************************************************************}

BeginOfTask(Task_2)    {Tatitata}
Loop(Con,Forever)
   PlayTone(147,100) {D 1/4}
   PlayTone(196,100)  {G 1/4}
   PlayTone(147,100)  {D 1/4}
   PlayTone(196,100)   {G 1/4}
   Wait(Con,800)  {Pause 1/2 + 1/4 + Melodie}
EndLoop()
EndOfTask()

{******************************************************************}

BeginOfTask(Task_3)   {react on temperature}
Loop(Con,Forever)
  SetVar(TemperatureValue,SenVal,Sensor_3)
  If(Var,TemperatureValue,LT,Var,AverageTemperature)
      StopTask(Task_1)  {stop}
      StopTask(Task_2)   {no Tatitata}
      Off(Motor_A+Motor_C)
     PlaySystemSound(Sweep_fast_sound)  {jhuppie}
     
     On(Motor_B)   {Propeller}
     Wait(Con,500)  {5 sec}
     Float(Motor_B)  {stop propeller}
     Wait(Con,3)

     SetRwd(Motor_A+Motor_C)   {walk back}
     On(Motor_A+Motor_C)
     Wait(Con,300)    {3 sec}
     
      SetFwd(Motor_A+Motor_C)  {direction}
     StartTask(Task_1)   {search light again}
     StartTask(Task_2)   {Tatitata}
   Endif()
Wait(Con,3)
EndLoop()
EndOfTask()

{::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::}



 
 


Page précédente