Sunday, July 26, 2015

Garden Robot Update 10

It's been a full week since the last update.  Quite a few things have changed, but not a ton.  I have continued to make changes to the GUI and have implemented a rudimentary security system.  "Rudimentary" is right...it is, for now, just a prompt box that redirects the window to another page of my choosing (mwuhaha) if you don't put in the right password.

However, the most progress has been on the robot itself.  I have finally constructed revision 1.  For now, it is comprised of 3 motors (move left/right, raise/lower attachment, open/close valve).  It also has 3 sensors (ambient light, moisture, touch sensor to reset position, and light sensor to detect marks on the track and determine position).  I am currently using a 2X4 as a track, with 3 strips of electrical tape to mark out the positions of the plants.

I have also finally gotten around to coding the position control of the robot.  This one was a little bit more tricky...I wanted a system where something (either a user request or a preprogrammed routine) could ask the robot to move to any position, regardless of where it starts.  For now, I have two parts to handle these two different requests.  (1) If the bluetooth mailbox returns a value of 0, the program switches towards a preprogrammed routine.  (2) If the bluetooth mailbox returns a value that is not 0, the user is requesting a change in position.

  1. After initial reset, the main task starts another task that runs simultaneously for the rest of the program.  This sub-task simply waits one second, then increments three variables - timer1, timer2 and timer3.  The main task checks to see if any of these variables has exceeded a certain threshold - if so, it calculates the amount needed to move to position 1, 2 or 3 from where it currently is, and passes the MoveRobot subroutine this calculated value as an argument.
  2. The main task sets the desired position to the value read out of the bluetooth mailbox.  This value is the user's requested position.  As before, it calculates the amount needed to move to this position and calls the MoveRobot subroutine.  
Significantly, since these two branches are on either side of an if/else statement, they cannot execute at the same time and thus cannot interfere with each other.

The MoveRobot subroutine uses the downwards-facing light sensor to check for the electrical tape markings on the track.  Depending on if the argument is negative or positive, it moves backwards or forwards, incrementing a counter variable as it detects a piece of tape. Once the argument matches the counter, it breaks out of the loop.

Couple things:
  1. The direct control I currently have programmed will mess up the position of the robot, which might cause it to become confused (it thinks it is in position 1 when it is actually in position 2, etc.)  To fix this I should probably get rid of direct commands and add a third branch in addition to the above two.  This way, the robot could reset itself after the user finishes controlling it.
  2. I still haven't found a way to get the robot to "push" vital information to the server without a user-initiated GET request.  For example, whenever the robot changes position (ex. from 1 to 3) it should cause this data to update on the web page.  Same for valve state and attachment position.
  3. Figure out port forwarding - for now the server is only accessible to devices connected to the same network.  However I don't really yet plan on using this outside of the same network...for now.

Wow, that got long.  Pictures/screenshots/code to follow.