Autobahn + Gamepad.js

74 views
Skip to first unread message

Bruno Brusantin

unread,
Nov 7, 2014, 11:01:40 AM11/7/14
to autob...@googlegroups.com
Hello,

I`m using the broadcast example from the examples folder. All works well.
Except that i`m trying to integrate it with an xbox controller using gamepad.js.


i`m new to javascript and i`m having problems while trying to send the values generated by the controller`s axis and buttons over a broadcast message.

there`s some conflict with those functions apparently. I`m desperate since i cant find anything on the subject. 

can anyone please show me some code that will make it work ?  any ideas area also welcome.

thanks in advance

Tobias Oberstein

unread,
Nov 9, 2014, 6:47:42 AM11/9/14
to autob...@googlegroups.com
Hi Bruno,

Am 07.11.2014 17:01, schrieb Bruno Brusantin:
> Hello,
>
> I`m using the broadcast example from the examples folder. All works well.
> Except that i`m trying to integrate it with an xbox controller using
> gamepad.js.
>
> http://www.gamepadjs.com/
>
> i`m new to javascript and i`m having problems while trying to send the
> values generated by the controller`s axis and buttons over a broadcast
> message.
>
> there`s some conflict with those functions apparently. I`m desperate
> since i cant find anything on the subject.

Have a look at http://autobahn.ws/js/

AutobahnJS provides a real publish & subscribe mechnism over WebSocket.
This much better fits your use case than the broadcast example.

>
> can anyone please show me some code that will make it work ? any ideas
> area also welcome.
>
> thanks in advance

Using AutobahnJS, here is how you would publish gamepad data as an event:

var payload = [];

var pads = Gamepad.getStates();
for (var i = 0; i < pads.length; ++i) {
if (pads[i]) {
payload.push({x: pads[i].leftStickX, y: pads[i].leftStickY};
} else {
payload.push(null);
}
}

session.publish("com.example.mypad1", [payload]);

I guess wiring up a gamepad using gamepad.js and AutobahnJS is nearly
trivial. This sounds cool, so I just ordered a Xbox wireless pad +
wireless adapter. When that arrives, I'll hack something and let you know ..

Cheers,
/Tobias

>
> --
> You received this message because you are subscribed to the Google
> Groups "Autobahn" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to autobahnws+...@googlegroups.com
> <mailto:autobahnws+...@googlegroups.com>.
> To post to this group, send email to autob...@googlegroups.com
> <mailto:autob...@googlegroups.com>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/autobahnws/35f676d9-e7e9-4239-b792-8770c455a04f%40googlegroups.com
> <https://groups.google.com/d/msgid/autobahnws/35f676d9-e7e9-4239-b792-8770c455a04f%40googlegroups.com?utm_medium=email&utm_source=footer>.
> For more options, visit https://groups.google.com/d/optout.

Bruno Brusantin

unread,
Nov 10, 2014, 7:55:59 PM11/10/14
to autob...@googlegroups.com
Hi Tobias,

Thanks for the quick response. i was happy that you liked the idea enough to get yourself a controller :D. 

I cant wait to get it working as well...
i' quicky tried to install autobahnJS  but i couldn´t figure out yet whats the server and client code.. and if i have to use it with NodeJs or python. 
i'm a little confused. i'll keep trying during the week and let you know how its going.. 

and as soon as i get it to work i'll show what i'm up to.


Thanks

Alexander Gödde

unread,
Nov 11, 2014, 6:25:10 AM11/11/14
to autob...@googlegroups.com
Hi Bruno!

AutobahnJS is client only. 

If you want to do PubSub only, i.e. the browser publishes the gamepad events and other clients subscribe and receive these, then the other thing you need is a WAMP router. My suggestion would be to use Crossbar.io, and use one of the application templates that come with this, e.g. the 'votes:browser' which gives you working code for establishing the necessary connections as well as doing PubSub.

You only need a backend if you want to do more than PubSub. For this you have a choice - which includes Node.js and Python. (Crossbar.io also includes templates with backends on either of these).

Hope this helps, and let me know if you have more questions!

Regards,

Alex

Tobias Oberstein

unread,
Nov 11, 2014, 10:53:27 AM11/11/14
to autob...@googlegroups.com
Hi Bruno,

the Xbox controller has arrived and I have hacked a demo:

https://github.com/oberstet/scratchbox/tree/master/js/gamepad

The demo does _not_ use gamepad.js - this library is deprecated, no
longer works, unneeded.

The demo isn't "shiny" .. will just do the bare minimum for real-time
connecting gamepads via WAMP.

Let me know if that works for you and you can follow the code.

Cheers,
/Tobias
> --
> You received this message because you are subscribed to the Google
> Groups "Autobahn" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to autobahnws+...@googlegroups.com
> <mailto:autobahnws+...@googlegroups.com>.
> To post to this group, send email to autob...@googlegroups.com
> <mailto:autob...@googlegroups.com>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/autobahnws/b1495526-72b3-4a5c-a104-f3384ae6fa43%40googlegroups.com
> <https://groups.google.com/d/msgid/autobahnws/b1495526-72b3-4a5c-a104-f3384ae6fa43%40googlegroups.com?utm_medium=email&utm_source=footer>.

Bruno Brusantin

unread,
Nov 11, 2014, 1:23:23 PM11/11/14
to autob...@googlegroups.com
Hi again,

WOW!! you guys sure work fast. i`m very impressed. 
today i took some time to read more about autobahnJS and understood more about how WAMP works.
got a the basic pubsub example working with basicrouter.py.

I`ll try the code you posted now. It sure looks amazing, and i`m almost sure it`s also exactly what i was looking for (also hoping that others will benefit).

thanks a lot Tobias and Alexander

Bruno Brusantin

unread,
Nov 18, 2014, 9:52:22 AM11/18/14
to autob...@googlegroups.com
Hello again,

i`m having dificulties with the code again. So i better just say what i`m trying to do.
The idea is to make a RC car race game over wi-fi.  (Think Mario Kart or Rock `n Roll Racing with real cars.). I got the idea from this guy:

so i`m using:
a windows PC that will be the crossbar.io server
The same PC will be a client with a browser and a gamepad. (i`m thinking that it can go up to 10 clients if it works)
each client will send gamepad commands through the browser to a car hooked with a raspberry pi and a camera.

i`m thinking the setup would be:
the "server" is a javascript frontend so i can monitor the changes in the race in real time and broadcast the info like lap times, positions, and who shot who
the "car" will have a python backend (mostly receiving the gamepad and send a message to the server when it makes a lap)
and the "pilot" a javascript frontend (with a gamepad to send commands to his car and receive updates from server)

so i made a realm "race" then there will be topics like "pilot1 to 10" and "car1 to 10" and "server".

the questions are:
1. Is what i`m thinking correct ? :)
2. i`m unsure, wich is best to use, PubSub or RPC to run python commands on the Raspberry Pi ? (from what i read looks like RPC is better)
3. is there already a standard way to know wich clients are subscribed to wich topic ? i`m asking this because i must know what cars are online, what pilots are connected to wich cars. (it can be set to a default, but the server must know)
4. in the PubSub model i didnt find a way to broadcast the info. Do i have to send a message to each topic ?

my current problems are:
1. migrating the example code you provided for the gamepad from the monitor.js to python, since that`s the only thing the raspberry pi will be needing. 
i`m still messing with both, the votes example as suggested by Alexander, and the basic pubsub but its hard since the codes seem different on each one.

2. breaking down the array that the gamepad is sending. how is that formatted ?


any help will be greatly apreciated.

Thanks again 

Bruno Brusantin

unread,
Feb 4, 2015, 7:25:11 AM2/4/15
to autob...@googlegroups.com, tobias.o...@gmail.com
Hi Tobias,

a while ago you helped me by making this demo:


i've managed to make it work and send the values below via RPC using session.call(). 
but i`m having trouble identifying the buttons and axes with this code

on this file:

   ...
line 98 changeEvent.gamepads[j].buttons[i] = val;
   ...
line 115 changeEvent.gamepads[j].axes[i] = val;
   ...


i cant get the index values of the object to know wich button or axis is pressed
could you please help me out ?

i`m looking for something like
console.log(button_pressed, value);

Thanks


Bruno Brusantin
(19) 998-996-678

To post to this group, send email to autob...@googlegroups.com

--
You received this message because you are subscribed to a topic in the Google Groups "Autobahn" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/autobahnws/FKjZTH3UcLM/unsubscribe.
To unsubscribe from this group and all its topics, send an email to autobahnws+unsubscribe@googlegroups.com.
To post to this group, send email to autob...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/autobahnws/546230F1.3090701%40gmail.com.
Reply all
Reply to author
Forward
0 new messages