Society of Robots - Robot Forum
Software => Software => Topic started by: lanamor on April 15, 2009, 07:00:38 AM
-
So I’ve been doing some research regarding some sort of web interface for a robot. I’ve found several sites showing off projects that claim this, but nothing with usable directions or nothing that use open source software. I have this vision for a remotely controlled rover bot with camera. It would be controllable via the internet.
I actually have a web server running PHP and I was able to access it via Internet Explorer and got the server to send serial commands to my arduino project board. The problem is that there is a 10 second delay from when I submit the command to when it is executed. I’m only accessing my web server from my LAN so network latency isn’t the problem. I assume the process with which my web server communicates with the serial port is the problem.
I’m not really asking for help debugging my current setup. What I’m wondering is if anyone else has tried this or seen it done that could give some suggestions on how they did it.
-
i did this a very similar way to you but with Python instead of PHP.
robot <> wireless serial link <> server's serial port <> Python CGI code <> webserver <> internet
my latency was between 1 and 2 seconds from a terminal out on the internet when the server was on my home LAN.
your results should be similar. 10 seconds is definitely too long.
i was running Apache webserver on Linux with Python CGI. i forget the name of the Python module i was using for serial comms....
try running ping tests on your server to see what the network latency is.
if you are connecting to the server through multiple routers traceroute might give you better information than ping.
presuming your network is not causing the delay,
how quickly can you load plain HTML pages?
if you run a simple "hello world" PHP CGI script do you get the same delay?
is there any time difference using a web browser on the server and on a remote machine?
if you are not seeing the delay with the tests mentioned above then i would agree that the speed the PHP CGI communicates with the serial port that is the problem.
if it is slow communications between PHP and the serial port you have a few options:
i'm sure there is more than one method for PHP to control a serial port.
if you are using Linux you can just write to the serial port as if it was a file. i have no idea how you would do that on windows.
the other option i can think of is you can allow PHP to run executable files. this is a bit of a security hole but safe with the right precautions.
make an executable program that controls your bot and allow PHP to run that. (can't remember the PHP command to run an executable i'm afraid.)
dunk.
-
how quickly can you load plain HTML pages?
Super fast even with CSS formatting.
if you run a simple "hello world" PHP CGI script do you get the same delay?
No
is there any time difference using a web browser on the server and on a remote machine?
No
my latency was between 1 and 2 seconds from a terminal out on the internet when the server was on my home LAN.
Yea, 2-3 seconds is about the most you can compensate for when driving this remotely.
It has to be the PHP module I’m using. It loads a .dll as a PHP module that does all the actual work. I’m running Apache on top of Vista so because I was using my travel laptop. My end idea will have some old hacked up laptop so Linux would probably work best. I’m an IT admin but my LAN is all Microsoft, so I have only a little play time with any distro of Linux. I did figure that I’d have to use Linux though.
I guess I’ll just have to find an old laptop on Ebay first, then load it up with Linux and Apache before I continue testing this project. The problem with that is that all the “robot” tools and software I’m using are all for Windows! I’ll have to find Linux replacements for everything…
v/r
SSgt Matthew S. Cassidy
2 CS/SCOO, Network Operations
Barksdale AFB, Louisiana
DSN: 781-3249 Comm: (318)456-3249
-
If you are comfortable in the Microsoft world, why not do it with asp.net? You just need a box running XP Pro with IIS, .net framework 2.0 and VWD 2008 Express. I could dig up some sample code of a web page writing to a comm port if you are interested.
-
for comparison have you considered trying Python instead of PHP?
it can do everything PHP can and of all the scripting languages i've had to use it is the easiest to learn.
if you are competent in PHP i would estimate you would have the basics of Python down in an afternoon.
dunk.
-
If you are comfortable in the Microsoft world, why not do it with asp.net? You just need a box running XP Pro with IIS, .net framework 2.0 and VWD 2008 Express. I could dig up some sample code of a web page writing to a comm port if you are interested.
I found the System.IO.Ports name space for .NET but I've had very little experience with programming using the .NET framework. I took a web programming class back in college that covered the basics of ASP.NET but that's it. I'm going to look into ASP.NET with C# to see if I can poke my way through this. If anyone has a simple example I'd love to see it, but don't go spending hours looking it up.
-
Looks like I found my solution after about 2 hours of refreshing my ASP.NET skills and reading the MSDN whitepages.
Here is a simple C# ASP.NET snip that turns the LED of my arduino on and off. The Arduino is programmed to turn the LED on if '1' is received via serial and off when '0' is received via serial. There is almost no latency when I access this from host to host on my internal LAN.
using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO.Ports;
public partial class test : System.Web.UI.Page
{
SerialPort sp = new SerialPort();
protected void Page_Load(object sender, EventArgs e)
{
sp.PortName = "COM4";
sp.BaudRate = 9600;
sp.DataBits = 8;
sp.Parity = Parity.None;
sp.StopBits = StopBits.One;
}
protected void btnOn_Click(object sender, EventArgs e)
{
try
{
sp.Open();
sp.WriteLine("0");
sp.Close();
}
catch (System.Exception ex)
{
txtError.Text = ex.Message;
}
}
protected void btnOff_Click(object sender, EventArgs e)
{
try
{
sp.Open();
sp.WriteLine("1");
sp.Close();
}
catch (System.Exception ex)
{
txtError.Text = ex.Message;
}
}
}
-
Congratulations. That looks very much like the sample I would have provided, except mine was in vb instead of c#.