Autobahn + Gamepad.js

#1

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/

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

theres some conflict with those functions apparently. Im 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

0 Likes

#2

Hi Bruno,

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

···

Am 07.11.2014 17:01, schrieb Bruno Brusantin:

--
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.

0 Likes

#3

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

···

Em sexta-feira, 7 de novembro de 2014 14h01min40s UTC-2, Bruno Brusantin escreveu:

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/

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

theres some conflict with those functions apparently. Im 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

0 Likes

#4

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

···

Am Dienstag, 11. November 2014 01:55:59 UTC+1 schrieb Bruno Brusantin:

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

Em sexta-feira, 7 de novembro de 2014 14h01min40s UTC-2, Bruno Brusantin escreveu:

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/

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

theres some conflict with those functions apparently. Im 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

0 Likes

#5

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

···

Am 11.11.2014 01:55, schrieb Bruno Brusantin:

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

Em sexta-feira, 7 de novembro de 2014 14h01min40s UTC-2, Bruno Brusantin > escreveu:

    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.

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

    thanks in advance

--
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>.
For more options, visit https://groups.google.com/d/optout.

0 Likes

#6

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.

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

thanks a lot Tobias and Alexander

0 Likes

#7

Hello again,

im having dificulties with the code again. So i better just say what im 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:

http://vimeo.com/13217587

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 ? :slight_smile:

  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.

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

any help will be greatly apreciated.

Thanks again

0 Likes

#8

Hi Tobias,

a while ago you helped me by making this demo:

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

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:

https://github.com/oberstet/scratchbox/blob/master/js/gamepad/web/gamepad.js


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

···

2014-11-11 13:53 GMT-02:00 Tobias Oberstein tobias.o...@gmail.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

Am 11.11.2014 01:55, schrieb Bruno Brusantin:

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

Em sexta-feira, 7 de novembro de 2014 14h01min40s UTC-2, Bruno Brusantin

escreveu:

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/](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.



can anyone please show me some code that will make it work ?  any

ideas area also welcome.



thanks in advance

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+unsubscribe@googlegroups.com

mailto:autobahnws+unsub...@googlegroups.com.

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

mailto:autobahnws@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>.

For more options, visit https://groups.google.com/d/optout.

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.

For more options, visit https://groups.google.com/d/optout.

Bruno Brusantin
(19) 998-996-678

0 Likes