Some images. First of all, the current state of the GUI.
Chrome:
Chrome (Android):
Safari (IOS):
And the robot itself. Currently missing the valve and associated water tubing...
The track, nothing more than a 2X4 with a nail in each end, propped up on books:
The robot and phone plugs can be seen from behind. Currently, I am having it "check on" each plant (designated by the blue strips of tape) at 10 minute intervals. I was running 1 minute intervals earlier today and haven't had a problem with this version of the program...here's to hoping.
To do:
1. Get tubing and water container together.
2. Figure out how to get position data from the robot to the web-page (I spent hours this morning getting bluetooth messages from phone to NXT worked out, now I have to figure out how to do it in reverse)
3. Get some soil and actually test this thing!!!
Monday, July 27, 2015
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.
Wow, that got long. Pictures/screenshots/code to follow.
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.
- 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.
- 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:
- 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.
- 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.
- 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.
Sunday, July 19, 2015
Garden Robot Update 9
Some aesthetic updates. Putting things in a table makes it look a bit better...I guess. Currently I have implemented control for left and right (rotating motor A in each direction when clicked and stop when released). The ambient light label refreshes when clicked.
I got the app running on an older Android phone today (running Android 2.2). I initially had some difficulty with NanoHTTPD throwing a null pointer exception, but fixed that by updating to the latest version of NanoHTTPD.
On the hardware side, the 350 milliamp converter I hacked into the NXT seems to be working fine for the single-motor rotation, but I picked up a 2.2 amp converter that needs to be placed on. I want to put in some kind of protection, like the fuse and diode in this example.
To do:
1. Fix the moisture level command so that it reports the proper values.
2. Find a way to scale the ambient light command from 0 to 100%.
3. Start on the actual design of the robot...
4. Get the 2.2A converter together.
5. Figure out how (if?) the NXT should push data to the server. For example, I think it should display its current position and valve setting.
6. Put in new controls for open valve and close valve.
Friday, July 17, 2015
Garden Robot Update 8
Quick update. After WAY too long struggling how to get text info (like sensor readings) from the NXT to the webpage without refreshing, I looked into using Ajax in jquery and it turned out to be an EXTREMELY simple "get" command. No need for Canvas text, no need to mess with the HTML (all of which, unfortunately, I tried.) Basically, this in javascript:
(the key is the second argument to the $.get request, as "function(data)" will process whatever data you are getting back)
And in the .java file:
Of course, later, the "999" and "111" will be replaced with return values from the NXT as I discussed earlier.
To do:
1. Continue to lay out the GUI. (It looks so ugly now, I wonder how to make it look any better...?)
2. Actually make it work with the NXT. Put in the direct commands to control motors and get input values.
3. Start to figure out some form of security...I really doubt I know enough to actually encrypt any data but I want at least a form of password-protection. Like, really annoying password-protection.
4. Start to design the actual thing...I certainly want some sort of CAD file, but I don't (currently) have SolidWorks, so I should probably look into MLCAD or something. Or LDD, which I have used extensively in the past.
5. Figure out where I can actually run this thing. I need to talk to some people.
$("#refresh").mousedown(function() { $.get('lightrefresh', function(data) { document.getElementById("lightlabel").innerHTML = ("Ambient Light: " + data); }); $.get('moisturerefresh', function(data) { document.getElementById("moisturelabel").innerHTML = ("Moisture Level: " + data); }); });
(the key is the second argument to the $.get request, as "function(data)" will process whatever data you are getting back)
And in the .java file:
else if(uri.equals("lightrefresh")) { Log.w("HelloServer", "lightrefresh"); res = new Response(Response.Status.OK, MIME_PLAINTEXT, "999");} else if(uri.equals("moisturerefresh")) { Log.w("HelloServer", "moisturerefresh"); res = new Response(Response.Status.OK, MIME_PLAINTEXT, "111");}
Of course, later, the "999" and "111" will be replaced with return values from the NXT as I discussed earlier.
To do:
1. Continue to lay out the GUI. (It looks so ugly now, I wonder how to make it look any better...?)
2. Actually make it work with the NXT. Put in the direct commands to control motors and get input values.
3. Start to figure out some form of security...I really doubt I know enough to actually encrypt any data but I want at least a form of password-protection. Like, really annoying password-protection.
4. Start to design the actual thing...I certainly want some sort of CAD file, but I don't (currently) have SolidWorks, so I should probably look into MLCAD or something. Or LDD, which I have used extensively in the past.
5. Figure out where I can actually run this thing. I need to talk to some people.
Wednesday, July 8, 2015
Garden Robot Update 7
Decent breakthrough today.
Basically, I finally got the Nxtbotguard streaming solution to work with my current implementation without modifying the Nanohttpd java file. That's the middle canvas element in the image. Still not entirely sure how it works, as I have borrowed a fair amount of code.
Also using the Nxtbotguard solution I have implemented the bottom two arrow buttons (as images) which respond as expected when clicked (using Jquery, which seems awesome and I really need to learn more about) Nothing works with the NXT...yet.
The biggest issue is updating text however. I want to update the ambient light value from the NXT through dynamic text, and I am a bit of a standstill how to do that...currently trying to use Canvas, like the streaming image solution, but it doesn't work. Yet.
Still a lot to do, but might actually see a bit of progress at last...
Basically, I finally got the Nxtbotguard streaming solution to work with my current implementation without modifying the Nanohttpd java file. That's the middle canvas element in the image. Still not entirely sure how it works, as I have borrowed a fair amount of code.
Also using the Nxtbotguard solution I have implemented the bottom two arrow buttons (as images) which respond as expected when clicked (using Jquery, which seems awesome and I really need to learn more about) Nothing works with the NXT...yet.
The biggest issue is updating text however. I want to update the ambient light value from the NXT through dynamic text, and I am a bit of a standstill how to do that...currently trying to use Canvas, like the streaming image solution, but it doesn't work. Yet.
Still a lot to do, but might actually see a bit of progress at last...
Subscribe to:
Posts (Atom)