We first started by writing our code for the VEX. Since we had used functions in previous labs, the first step was to create our functions in the code. This would allow us to write specific code for movements in a simpler manner than having to write out the entire section. Here is the first parts of our code and you can see the functions we used.
You can see that the functions we created were functions to move straight, turn right, turn left and move back. They were all listed before the main task so we could refer to them when writing our commands for the VEX.
For the first part of the main task of the code, we had the VEX travel down the left hand hallway towards room #2. For each room we had two parts: the VEX would turn and "look" into the room, then either enter the room after finding the light source or move on to the next room. If there was no light source, the VEX would turn and continue searching. Once the VEX picked up on the light source in a room, the code for extinguishing the flame took over.
You can see that for each room the VEX comes across, it either sees the light source and enters the room or moves on to the next room. Since our light source was a cluster of infrared LED's, the light was able to bounce off the walls and be seen by the flame sensor on the VEX. The VEX didn't even need to enter the room to find the light source, just facing the opening was good enough to register an increase in the flame sensor value.
Once our code had been tested, adjusted and retested many times, it was time to perform the challenge. We only wrote one code for all 3 challenges since that one code would search the entire maze and find the light source no matter which room the light source was in. Here is our VEX robot in action finding and extinguishing the light sources like a boss!
Lab 17 finished!
No comments:
Post a Comment