Rovio API use examples

30 posts / 0 new
Last post
gbyron
gbyron's picture
Rovio API use examples

 

I have the Rovio and
have enjoyed driving it around the house, but after a few minutes of driving I
needed something far more interesting. The API seems like the doorway to an
interesting robot interface. Unfortunately I have found no example of using the
ROVIO API from a generalized programming language (e.g.  Python, Visual Basic or C). Does anybody in
the group have any experience with the Rovio API and can you list an example of
using the API from you scrip/program? I would greatly appreciate any examples
that you may offer. It is all new and these are the first steps on the road to
making this little $300 robot a significant robotic platform/ Thanks.

I look forward to
Roboreaml's  interface 

http://www.roborealm.com/

roschler
roschler's picture

Roborealm appears to be having a temporary problem:

"Fatal error: Call to undefined function: opendatabase() in /htdocs/RoboRealm/header.php on line 274"

What does it do and what features did they announce for Rovio support specifically?

-- roschler

milw
milw's picture

isn't RoboRealm the machine vision system?

gbyron
gbyron's picture

Robo Realm is a free vision system. If you download their product and look through the available options and documentation you will find interfaces and drivers for several video equipped platforms.
http://www.surveyor.com/SRV_info.html.
If they can get their hands on a Rovio they will write an interface.
http://www.roborealm.com/
Myro is another good possibility for an intelligent interface host on your PC. You may detect my bias toward Python, but I am interested in any scripts that may be available to illustrate Rovio's API usage.

Thanks

roschler
roschler's picture

Python's great! Ruby is too. I didn't realize until recently that there's significant effort in the Python community to use Python with robotics (Pyro). However, I wonder how large that community is compared to the usual suspects of of C/C++ and Java who seem to dominate robotics development; not to leave out the the Basic and assembler camps though.

-- roschler

Rudolph
Rudolph's picture

The published Rovio API is just a bunch of http calls, so interfacing with it is trivial.

My first ever python program was (is) an under-featured text-mode Rovio client. See RoboCommunity's Download section to get it.

milw
milw's picture

Here's a bit of PHP code, if you have a web server to test it with. You also need to have the pecl_http extension for PHP installed.

<?php
$response = http_get("http://10.0.1.200/rev.cgi?Cmd=nav&action=1", array("timeout"=>10,"httpauth"=>"username:password","httpauthtype"=>HTTP_AUTH_BASIC), $info);
if ($info[response_code] == 200)   
{
print($response);
$response_array = explode("|",$response, 7);
//list($head, $navResponses, $myX, $myY, $myTheta, $myRoom, $mySS) = split("|",$response,7);
echo("<br>Done.<br>");
print_r($response_array[1]);
echo("<br>");
print_r($response_array[2]);
echo("<br>");
print_r($response_array[3]);
echo("<br>");
print_r($response_array[5]);
echo("<br>");
list($val, $myX)=split("=",$response_array[1]);
print_r($myX);
} 
else
{
print_r($info);
}
?> 

 

Bibert
Bibert's picture

I use it within an Objective-C / Cocoa Touch project.

Any language that provides a way to send requests to an url will work, in other words pretty much any language... you could use either sockets, Java HttpConnection, Stream Connection, NSUrl... and so on

labrat
labrat's picture

This an an example of using the API in Java to set the neck/head of Rovio in the middle position:

 

import java.io.*;
import java.net.*;

public class Example {
   
    public static void main(String[] args) throws IOException {
        
        final String login = "labrat";
        final String password = "password";
        
        //Create an authenticator to provide username and password to Rovio
        Authenticator.setDefault(new Authenticator() {                                        
            protected PasswordAuthentication getPasswordAuthentication() {
                return new PasswordAuthentication (login, password.toCharArray());
                }
            });
        
        //Create the command being sent to Rovio
        URL url = new URL("http://192.168.1.200/rev.cgi?Cmd=nav&action=18&drive=13");

        //Open the connection to Rovio and send command
        URLConnection uc = url.openConnection();
        uc.setDoOutput(true);
        BufferedReader in = new BufferedReader(new InputStreamReader(uc.getInputStream()));
        
        //Read anything returned by Rovio and print it
        String line;
        while ((line = in.readLine()) != null) {
            System.out.println (line);
        }
        
        //Close connection
        in.close();
    }

 

branden_g
branden_g's picture

An example in ruby would be:
require 'net/http'

class RovioController
attr_accessor :status
@status = {}
def initialize( ip = '192.168.2.124', port = 80,username = 'admin', password = 'admin')
@ip = ip
@port = port
@username = username
@password = password
end

def send_command command
response = nil
Net::HTTP.start(@ip,@port) {|http|
req = Net::HTTP::Get.new(command)
req.basic_auth @username, @password
response = http.request(req)

}
return response.body

#robot = Net::HTTP.new(@ip,@port)
#head,body = robot.get(command)
#return body
end

def move direction
body = send_command
end

def set_camera_position position
body = send_command "/rev.cgi?Cmd=nav&action=18&drive=#{position.to_s}"
end

def update_status
body = send_command '/rev.cgi?Cmd=nav&action=1'

@status = {}
body.split('|')[1..-1].each { |res| value = res.split('='); @status[value[0]] = value[1] }
end

def is_charging?
update_status
if @status["charging"] == "80" then return true else return false end
end

end
------------------
an example (this one to charge my defective rovio that stops charging prematurely)
#!/usr/bin/env ruby
# tested on Ubuntu and on Windows with OneClick Installer

require 'rovio.rb' # the name of the above code
r = RovioController.new # using defaults, would include new values like this:
# r = RovioController.new('192.168.2.18',80,"myname","mypass")
reset_count = 0

while reset_count if !r.is_charging? then #if it isn't charging then redock
reset_count += 1
print Time.now.to_s + "(" + reset_count.to_s + ")\n" #prints every time it redocks
3.times {r.move 1} # three steps forward
6.times {r.move 2} # six steps back (to make sure it docks)
sleep 105.0 #pause 2 minutes before checking again (rovio takes time to start charging again)
end
sleep 15.0 #check every 15 seconds
end

amodedoma
amodedoma's picture

Wow, thanks guys! now I can play around with the api just by typing out the proper URL. Not quite as elegant as a terminal connection but I'll take it. I'm starting my nav and control program in powerbasic - will let you know how it comes out and of course share it with you.

amodedoma
amodedoma's picture

Oh and since it was mentioned and I think it worthy of your attention here is a proper link to roborealm's rovio specific page ->
http://www.roborealm.com/help/WowWee_Rovio.php

Paranosh
Paranosh's picture

basic class example C#: (.net 3.5)

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Rovio
{
partial class IECredencialesRovio
{
bool _usaaut;
public bool UsaAutentificacion
{
get { return _usaaut; }
set { _usaaut = value; }
}

public string IPRovio
{
get;
set;
}
public string PassRovio
{
get;
set;
}
public string UserRovio
{
get;
set;
}
public string PuertoRovio
{
get;
set;
}
private string _Rurl;
public string IE_Rurl
{
get
{
if (UsaAutentificacion == true)
{
_Rurl = "http://" + UserRovio + ":" + PassRovio + "@" + IPRovio + ":" + PuertoRovio;
}
if (UsaAutentificacion == false)
{
_Rurl = "http://" + IPRovio + ":" + PuertoRovio;
}
Consola.WriteLine("Conectando: " + _Rurl + "\r\n");
return _Rurl;
}

}

}
}

seeya.

Paranosh
Paranosh's picture

text to speech class implemented: C# (thanks to mt)
http://www.robocommunity.com/forum/thread/15055/Can-rovio-somehow-do-Tex...

using System;
using System.IO;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Speech;
using System.Speech.Synthesis;
using System.Speech.AudioFormat;
using System.Net;
using System.Net.Sockets;

namespace Rovio
{
partial class t2speech : IECredencialesRovio
{
String _Log;
public String Log
{

get { return _Log; }
set { _Log = value; }
}

public static byte[] StringToByteArray(string inputString)
{
System.Text.ASCIIEncoding encoding = new System.Text.ASCIIEncoding();
return encoding.GetBytes(inputString);
}
private string _rovioIPAddress;
private int _rovioAudioPort;
private byte[] szSend;
private Socket _rovioAudioSocket;
public void Say(bool debug, string text)
{
_rovioIPAddress = IPRovio;
_rovioAudioPort = int.Parse(PuertoRovio);
_rovioAudioSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
System.Net.IPEndPoint remoteEndPoint = new System.Net.IPEndPoint(System.Net.IPAddress.Parse(_rovioIPAddress), _rovioAudioPort);
_rovioAudioSocket.Connect(remoteEndPoint);
if (debug == true)
{
Log = (DateTime.Now.ToString() + " : Audio socket connected\r\n");
}

// Prepare the audio port for sending audio from the PC back to the Rovio
string temp = "POST /GetAudio.cgi HTTP/1.1\r\n" + "User-Agent: AudioAgent\r\n" + "Host: " + _rovioIPAddress + "\r\n" + "Content-Length: 2147483647\r\n" + "Cache-Control: no-cache\r\n" + "\r\n";
szSend = StringToByteArray(temp);
//REVIEW: skipping Credentials
if (_rovioAudioSocket.Send(szSend) == -1)
{
if (debug == true)
{
Log += (DateTime.Now.ToString() + " : Error sending initial packet\r\n");
}
}
Stream stream = new MemoryStream();
SpeechSynthesizer speaker = new SpeechSynthesizer();
byte[] format = new byte[0];
speaker.SetOutputToAudioStream(stream, new SpeechAudioFormatInfo(8000, AudioBitsPerSample.Sixteen, AudioChannel.Mono));
speaker.Volume = 100;
speaker.Rate = -2;
speaker.Speak(text);
stream.Seek(0, SeekOrigin.Begin);
byte[] output = new byte[stream.Length];
stream.Read(output, 0, (int)stream.Length);
_rovioAudioSocket.Send(output);
_rovioAudioSocket.Close();
if (debug == true)
{
Log += (DateTime.Now.ToString() + " : Audio socket closed\r\n");
}

}
}

}

seeya.

Jafni
Jafni's picture

Hello.. I want to ask you how to get file path name hBitmap using VC++?? Actually I want to build the robot for my project. I'm using VC++ to make it detect 4 pattern and it will stop for a second when it detect any one of that pattern. I had make a code until it can display in GUI but I don't know how to make it detect an image and it will display a character like

Jafni
Jafni's picture

Hello.. I want to ask you how to get file path name hBitmap using VC++?? Actually I want to build the robot for my project. I'm using VC++ to make it detect 4 pattern and it will stop for a second when it detect any one of that pattern. I had make a code until it can display in GUI but I don't know how to make it detect an image and it will display a character like "Triangle" and this robot will stop for a second. Can you help me? I also include my code...

void CSample_API_AppDlg::OnGetImage()
{
SetTimer(ID_CLOCK_TIMER,100,NULL);
}
void CSample_API_AppDlg::OnTimer(UINT nIDEvent)
{
// TODO: Add your message handler code here and/or call default

switch(nIDEvent)
{
case ID_CLOCK_TIMER:

int width, height;
unsigned char *image = (unsigned char *)malloc(320*240*3);

RR_API rr;

// open up RoboRealm if it is not already running. Note you may need to change
// the path on this.
rr.open("c:\\www\RoboRealm\\bin\\RoboRealm.exe", 6060);

if (!rr.connect("localhost"))
{
printf("RoboRealm does not appear to be running.\nPlease run RoboRealm and try again.");
exit(0);
}

if (hBitmap) DeleteObject(hBitmap);

hBitmap = rr.getBitmap("processed", image, &width, &height, 320*240*3);

imageCtl.SetBitmap(hBitmap);

rr.disconnect();

free(image);
break;
}
CDialog::OnTimer(nIDEvent);
}

Your kindness are really appreciated...

wirbly
wirbly's picture

Can the Rovio be told to move in a specific direction until told to stop? I'm programming on a device with a *very* slow net connection, and the standard method of repeatedly issuing the "move" command fast enough to keep the rovio moving simply isn't an option. (right now holding down the move button makes it nudge spastically, if that makes any sense.)

kakeakeai
kakeakeai's picture

Using the Cmd.cgi you can call rev.cgi multiple times in a single request enabling you to make many movements with only 1 request. As for manipulating it to move until told to stop I would look into hacking the path functions since it is the only features that enables the rovio to move until you stop it. For instance create a path to a location a few feet in front of where you are currently. I just got my rovio last night and will post any new ideas I come across.

wirbly
wirbly's picture

kakeakeai said:

Using the Cmd.cgi you can call rev.cgi multiple times in a single request enabling you to make many movements with only 1 request. As for manipulating it to move until told to stop I would look into hacking the path functions since it is the only features that enables the rovio to move until you stop it. For instance create a path to a location a few feet in front of where you are currently. I just got my rovio last night and will post any new ideas I come across.

Thanks for that info, kakeakeai. I didn't know about either one of those options. They will definitely help!

polis
polis's picture

Hi, guys, you're programs is very interesting. Unfortunately don't know how dowload at rovio? I would greatly appreciate help me. It is all new and these are the first steps on robot's programming
Sorry my broken english

thanks you

Buzz_Litebeer
Buzz_Litebeer's picture

Hello,

I am programming a piece of software for my rovio, before I upgrade the rovio to the latest firmware the audio example above worked for me. (IE opening the socket and sending the data).

After the firmware update it no longer works, and it looks like it is because the socket needs to have credentials.

I looked on the net how to do this but so far all attempts have failed, do you have an example of how this might be done?

Here is the code i use to get the audio socket (sans my attempt at adding an auth request at the end, this used to work on older rovio firmware).

[CODE]
public System.Net.Sockets.Socket GetRovioAudioSocket()
{

System.Net.Sockets.Socket AudioSocket = new System.Net.Sockets.Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);

int port = int.Parse(mPort);
string ipaddress = mAddress;
System.Net.IPEndPoint IPEndPoint = new IPEndPoint(System.Net.IPAddress.Parse(ipaddress), port);

AudioSocket.Connect(IPEndPoint);

string POSTCommand =

Buzz_Litebeer
Buzz_Litebeer's picture

If anyone is interested here is updated code that does not ignore the authorization step. Note, this is my internal method for grabbing the audio socket.

[CODE]
public System.Net.Sockets.Socket GetRovioAudioSocket()
{

System.Net.Sockets.Socket AudioSocket = new System.Net.Sockets.Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);

int port = int.Parse(mPort);
string ipaddress = mAddress;
System.Net.IPEndPoint IPEndPoint = new IPEndPoint(System.Net.IPAddress.Parse(ipaddress), port);

AudioSocket.Connect(IPEndPoint);

string POSTCommand = "POST /GetAudio.cgi HTTP/1.1" + Environment.NewLine + "User-Agent: AudioAgent" + Environment.NewLine + "Host: " + ipaddress + Environment.NewLine + "Content-Length: 2147483647" + Environment.NewLine + "Cache-Control: no-cache" + Environment.NewLine + "Authorization: Basic " + Convert.ToBase64String(ASCIIEncoding.ASCII.GetBytes(username + ":" + password)) + Environment.NewLine + Environment.NewLine;

byte[] szSend;
szSend = StrToByteArray(POSTCommand);

if (AudioSocket.Send(szSend) == -1)
{
throw new Exception("Failed to Connect to Audio Socket");
}

return AudioSocket;
}
[/CODE]

polis
polis's picture

Hello, sorry my bad english
I did like programing rovio in Dev C++,
Unfortunately I have found no example of using the ROVIO API for access .cgi comands control movement. I appreciate help me

Regards

cowboyctx
cowboyctx's picture
xlordt
xlordt's picture

Hey guys, I am aware of this thread being old, but I am looking to stream rovio video on my own website.. I read the api doc and I see they have this sample code in html.
yet nothing happens. Does anyone knows what I am missing? else mind driving me in the right direction please. I am thinking that there might be something wrong with the .cab, as I dont get an activex installed on IE.

Thanks

cowboyctx
cowboyctx's picture

This works for me.  Replace the X's with your Rovio IP and port.  Also turn off PASSWORD on your Rovio.  Also the ACTIVEX you need to install.http://www.robocommunity.com/download/19453/Rovio-WebSee-ActiveX-for-man...

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"        "http:////www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http:////www.w3.org/1999/xhtml" xml:lang="en" lang="en"><head>    <title>Code</title>    <meta http-equiv="content-type" content="text/html; charset=utf-8" />    <meta name="author" content="Josh Savage">    <meta name="copyright" content="WowWee Group Ltd.">     <script type="text/javascript" src="http://XXX.XXX.X.XXX:XXXX/lib/rovio_mobile.js"></script>
 <script type="text/javascript" src="http://XXX.XXX.X.XXX:XXXX/rev.cgi?Cmd=nav&action=6&JsObj=pathsObj"></script>

 <link rel="stylesheet" href="http://XXX.XXX.X.XXX:XXXX/css/mobile.css" type="text/css" media="screen" /></head><body>        <img id="cmd_frame" src="" style="display: none;" />        <table class="movement_btns" style="width: 320px;">            <tr>                <td>                    <div id="camera_container" style="height: 240px;">                        <script>                            document.write ('<img id="oCamCtl" src="http://XXX.XXX.X.XXX:XXXX/Jpeg/CamImg' + Math.floor (10000 * Math.random ()) + '.jpg" width="320px" height="240px" />');                            if(navigator.platform != 'WinCE'){                                setInterval("$('oCamCtl').src='http://XXX.XXX.X.XXX:XXXX/Jpeg/CamImg' + Math.floor (10000 * Math.random ()) + '.jpg';", 500);                            }                        </script>                    </div>                </td>                       </body></html>

xlordt
xlordt's picture

Nice thank you cowboyctx, I will give this a try.

cowboyctx
cowboyctx's picture

Did it work?

xlordt
xlordt's picture

cowboyctx said: Did it work?

yap, I get the image.. thanks again

Elf
Elf's picture

Hello,

I'm looking for a command to authenticate with user id and password in cgi commands mode in oder to integrate rovio's commands into EZ-Builder application. Anyone has an idea ? I tried so far the usuals (user:password@ip and ip/xx.cgi?user&password...) without success.

Thank you very much for your help,
Elfege