 |
WiiLi.org a new revolution
|
| View previous topic :: View next topic |
| Author |
Message |
thelucster
Joined: 12 Jul 2008 Posts: 2
Digg It |
Posted: Sat Jul 12, 2008 1:45 pm Post subject: Balance Board Samples |
|
|
Here are a couple of samples applications I have created which interact with the balance board. The first just shows a graph the same way as the accelerometer does, and the second is very similar to the centre of gravity game in WiiFit.
These have both been created using WiiremoteJ 1.5, under OSX with BlueCove.
Graph
| Code: |
import java.util.ArrayList;
import java.awt.*;
import javax.swing.*;
import wiiremotej.*;
import wiiremotej.event.*;
public class BoardGraph extends BalanceBoardAdapter
{
private BalanceBoard remote;
private static double leftTop = 0;
private static double leftBottom = 0;
private static double rightTop = 0;
private static double rightBottom = 0;
private static double total = 0;
private static double lastLeftTop = 0;
private static double lastLeftBottom = 0;
private static double lastRightTop = 0;
private static double lastRightBottom = 0;
private static double lastTotal = 0;
private static JFrame graphFrame;
private static JPanel graph;
private static int[][] pixels;
private static int t = 0;
public static void main(String args[])
{
try
{
WiiRemoteJ.setConsoleLoggingAll();
graphFrame = new JFrame();
graphFrame.setTitle("Mass graph: Balance Board");
graphFrame.setSize(800, 600);
graphFrame.setResizable(false);
t = 801;
pixels = new int[800][600];
graph = new JPanel()
{
public void paintComponent(Graphics graphics)
{
if (t >= 800)
{
t = 0;
graphics.clearRect(0, 0, 800, 600);
graphics.fillRect(0, 0, 800, 600);
graphics.setColor(Color.WHITE);
graphics.drawLine(0, 550, 800, 550);
}
graphics.setColor(Color.RED);
graphics.drawLine(t, (int) lastLeftTop, t, (int) leftTop);
graphics.setColor(Color.GREEN);
graphics.drawLine(t, (int) lastLeftBottom, t, (int) leftBottom);
graphics.setColor(Color.MAGENTA);
graphics.drawLine(t, (int) lastRightTop, t, (int) rightTop);
graphics.setColor(Color.BLUE);
graphics.drawLine(t, (int) lastRightBottom, t, (int) rightBottom);
graphics.setColor(Color.PINK);
graphics.drawLine(t, (int) total, t, (int) lastTotal);
}
};
graphFrame.add(graph);
graphFrame.setVisible(true);
BalanceBoard remote = null;
try
{
remote = WiiRemoteJ.connectToBalanceBoard(args[0]);
}
catch(java.lang.ArrayIndexOutOfBoundsException e)
{
System.out.println("Please parse the Bluetooth address of your board as an argument");
System.out.println("boardgraph [address]\n");
System.exit(0);
}
remote.addBalanceBoardListener(new BoardGraph(remote));
}
catch(Exception e){e.printStackTrace();}
}
public BoardGraph(BalanceBoard remote)
{
this.remote = remote;
}
public void disconnected()
{
System.out.println("Remote disconnected... Please Wii again.");
System.exit(0);
}
public void massInputReceived(BBMassEvent evt)
{
double totalmass = evt.getTotalMass();
double mass00 = evt.getMass(0, 0);
double mass01 = evt.getMass(0, 1);
double mass10 = evt.getMass(1, 0);
double mass11 = evt.getMass(1, 1);
lastLeftTop = leftTop;
lastLeftBottom = leftBottom;
lastRightTop = rightTop;
lastRightBottom = rightBottom;
lastTotal = total;
leftTop = 550 - (mass01 / 100 * 550);
leftBottom = 550 - (mass11 / 100 * 550);
rightTop = 550 - (mass00 / 100 * 550);
rightBottom = 550 - (mass10 / 100 * 550);
total = 550 - (totalmass / 100 * 550);
t++;
graph.repaint();
}
}
|
Centre Of Gravity
| Code: |
import java.util.ArrayList;
import java.awt.*;
import javax.swing.*;
import wiiremotej.*;
import wiiremotej.event.*;
import java.lang.Math;
public class BoardCentre extends BalanceBoardAdapter
{
private BalanceBoard remote;
private static double horizontal = 400;
private static double vertical = 300;
private static JFrame graphFrame;
private static JPanel graph;
private static int[][] pixels;
private static double totalmass = 0;
private static boolean connected = false;
public static void main(String args[])
{
try
{
WiiRemoteJ.setConsoleLoggingAll();
graphFrame = new JFrame();
graphFrame.setTitle("Center of gravity graph: Balance Board");
graphFrame.setSize(800, 600);
graphFrame.setResizable(false);
pixels = new int[800][600];
graph = new JPanel()
{
public void paintComponent(Graphics graphics)
{
// draw axis
graphics.clearRect(0, 0, 800, 600);
graphics.fillRect(0, 0, 800, 600);
if (totalmass > 20)
{
graphics.setColor(Color.WHITE);
graphics.drawLine(0, 300, 800, 300);
graphics.drawLine(400, 0, 400, 600);
// draw centre of gravity
if (horizontal > 390 && horizontal < 410 && vertical > 290 && vertical < 310)
{
graphics.setColor(Color.BLUE);
} else {
graphics.setColor(Color.YELLOW);
}
graphics.fillOval(((int) horizontal) - 10, ((int) vertical - 10), 20, 20);
// draw mass
graphics.setColor(Color.RED);
graphics.drawString(Math.round(totalmass) + " kg", 10, 20);
} else {
graphics.setColor(Color.RED);
if (connected)
{
graphics.drawString("Please step onto the Balance Board", 300, 300);
}
else
{
graphics.drawString("Connecting...", 380, 300);
}
}
}
};
graphFrame.add(graph);
graphFrame.setVisible(true);
BalanceBoard remote = null;
try
{
remote = WiiRemoteJ.connectToBalanceBoard(args[0]);
}
catch(java.lang.ArrayIndexOutOfBoundsException e)
{
System.out.println("Please parse the Bluetooth address of your board as an argument");
System.out.println("boardcenter [address]\n");
System.exit(0);
}
remote.addBalanceBoardListener(new BoardCentre(remote));
}
catch(Exception e){e.printStackTrace();}
}
public BoardCentre(BalanceBoard remote)
{
connected = true;
this.remote = remote;
}
public void disconnected()
{
System.out.println("Remote disconnected... Please Wii again.");
System.exit(0);
}
public void massInputReceived(BBMassEvent evt)
{
totalmass = evt.getTotalMass();
double massRightTop = evt.getMass(0, 0);
double massLeftTop = evt.getMass(0, 1);
double massRightBottom = evt.getMass(1, 0);
double massLeftBottom = evt.getMass(1, 1);
// below 20kg the results aren't very accurate
if (totalmass > 20)
{
// deltas are +/- how much kg in each direction
double horizontalDelta = (massRightTop + massRightBottom) - (massLeftTop + massLeftBottom);
double verticalDelta = (massLeftBottom + massRightBottom) - (massLeftTop + massRightTop);
// we now need to make them relative to mass and work out position
horizontal = (horizontalDelta / totalmass * 400) + 400;
vertical = (verticalDelta / totalmass * 300) + 300;
} else {
horizontal = 400;
vertical = 300;
}
graph.repaint();
}
}
|
I also had to discover which pad is which, so if you can't be bothered to look through my code, here you go! Front refers to the side opposite the power button.
| Quote: | Front Right 00
Front Left 01
Back Right 10
Back Left 11 |
Enjoy! |
|
| Back to top |
|
 |
Cha0s Site Admin
Joined: 17 Jan 2007 Posts: 522
Digg It |
Posted: Sat Jul 12, 2008 8:40 pm Post subject: |
|
|
I've updated the docs to point to the location of the field constants (in the MassConstants class), so you don't have to guess.  _________________ Cha0s |
|
| Back to top |
|
 |
samba
Joined: 28 Oct 2008 Posts: 9
Digg It |
Posted: Tue Oct 28, 2008 5:31 am Post subject: |
|
|
thanks for the app, can someone help i get this error when i launch script with eclipse:
Caused by: com.intel.bluetooth.NotSupportedIOException: Not Supported on bluesoleil
is there a way i can go around this? thanx for your help, i really need this app, and would be ready to donate |
|
| Back to top |
|
 |
Zero
Joined: 27 Oct 2008 Posts: 6
Digg It |
Posted: Tue Oct 28, 2008 12:58 pm Post subject: RE: Balance Board Samples |
|
|
Hé! This is my first post on this forum. Recently I started a research for my study, which involves the programming of Wii devices. I am able to connect my Wiimote, but i have troubles with the Balance Board. Therefore I tried your sample, but to run it I need the Bluetooth address of the Board as an argument.
Where can I find this address. Is it printed on the board somewhere? I haven't been able to connect the balance board to my bluetooth directly, like the Wiimote, so I can't use that either.
Can anyone help me out please?
***UPDATE***
I have succeeded that my Bluetooth discovered the Balance Board by pressing the SYNC button instead of the POWER button, but it won't stay connected.
Then I tried running the graph example again with the argument "00:1f:c5:92:09:8b" as the device address, but I got the following exception:
-------------------------------------------------------------------------------------
BlueCove version 2.0.3 on widcomm
28-okt-2008 14:31:51 wiiremotej.BalanceBoard construct
INFO: btl2cap://00:1f:c5:92:09:8b
java.lang.IllegalArgumentException: channel 1f:c5:92:09:8b:11
at com.intel.bluetooth.MicroeditionConnector.openImpl(MicroeditionConnector.java:330)
at com.intel.bluetooth.MicroeditionConnector.open(MicroeditionConnector.java:510)
at javax.microedition.io.Connector.open(Connector.java:95)
at wiiremotej.BalanceBoard.construct(BalanceBoard.java:145)
at wiiremotej.BalanceBoard.<init>(BalanceBoard.java:109)
at wiiremotej.WiiRemoteJ.connectToBalanceBoard(WiiRemoteJ.java:209)
at net.niek.io.bb.graph.BoardGraph.main(BoardGraph.java:77)
-------------------------------------------------------------------------------------
I think that Device Address isn't the same as Bluetooth address. So I'm still nowhere. |
|
| Back to top |
|
 |
Cha0s Site Admin
Joined: 17 Jan 2007 Posts: 522
Digg It |
Posted: Wed Oct 29, 2008 7:51 pm Post subject: |
|
|
Zero: You should be able to connect the board the same way as the Wii Remote. You just call findBalanceBoard and push the red sync button on the balance board (pushing the front button does not work).
As for why it won't stay connected... what do you mean? How long does it stay connected before disconnecting?
As for passing the address, you shouldn't separate the characters at all. It should be exactly the address returned from the getBluetoothAddress() method. The call should look something like this: WiiRemoteJ.connectToBalanceBoard("001F32FD09B0");
Note, you still need to press the sync button on the balance board, but after pressing this, it should connect immediately.
----
samba: Try using the WIDCOMM stack. Bluesoleil is a bit spotty and only works with some configurations. If that doesn't work, let me know! _________________ Cha0s |
|
| Back to top |
|
 |
samba
Joined: 28 Oct 2008 Posts: 9
Digg It |
Posted: Thu Oct 30, 2008 1:22 pm Post subject: |
|
|
finally found a widcomm that would work on vista.
Balanceboard is connected to window but when i launch the app in eclipse with the address as an argument it can not find the board:
thanks for your responses +++
there is what is on the console
BlueCove version 2.0.3 on widcomm
30 oct. 2008 14:18:37 wiiremotej.BalanceBoard construct
INFO: btl2cap://001e35bf45e4
30 oct. 2008 14:20:38 wiiremotej.WiiRemoteJ connectToBalanceBoard
GRAVE: Error connecting to balance board.
java.io.IOException: BalanceBoard failed to connect!
at wiiremotej.BalanceBoard.construct(BalanceBoard.java:151)
at wiiremotej.BalanceBoard.<init>(BalanceBoard.java:109)
at wiiremotej.WiiRemoteJ.connectToBalanceBoard(WiiRemoteJ.java:209)
at BoardGraph.main(BoardGraph.java:77)
Caused by: javax.bluetooth.BluetoothConnectionException: Connection timeout
at com.intel.bluetooth.BluetoothStackWIDCOMM.l2OpenClientConnectionImpl(Native Method)
at com.intel.bluetooth.BluetoothStackWIDCOMM.l2OpenClientConnection(BluetoothStackWIDCOMM.java:876)
at com.intel.bluetooth.BluetoothL2CAPClientConnection.<init>(BluetoothL2CAPClientConnection.java:33)
at com.intel.bluetooth.MicroeditionConnector.openImpl(MicroeditionConnector.java:401)
at com.intel.bluetooth.MicroeditionConnector.open(MicroeditionConnector.java:510)
at javax.microedition.io.Connector.open(Connector.java:95)
at wiiremotej.BalanceBoard.construct(BalanceBoard.java:145)
... 3 more
java.io.IOException: BalanceBoard failed to connect!
at wiiremotej.BalanceBoard.construct(BalanceBoard.java:151)
at wiiremotej.BalanceBoard.<init>(BalanceBoard.java:109)
at wiiremotej.WiiRemoteJ.connectToBalanceBoard(WiiRemoteJ.java:209)
at BoardGraph.main(BoardGraph.java:77)
Caused by: javax.bluetooth.BluetoothConnectionException: Connection timeout
at com.intel.bluetooth.BluetoothStackWIDCOMM.l2OpenClientConnectionImpl(Native Method)
at com.intel.bluetooth.BluetoothStackWIDCOMM.l2OpenClientConnection(BluetoothStackWIDCOMM.java:876)
at com.intel.bluetooth.BluetoothL2CAPClientConnection.<init>(BluetoothL2CAPClientConnection.java:33)
at com.intel.bluetooth.MicroeditionConnector.openImpl(MicroeditionConnector.java:401)
at com.intel.bluetooth.MicroeditionConnector.open(MicroeditionConnector.java:510)
at javax.microedition.io.Connector.open(Connector.java:95)
at wiiremotej.BalanceBoard.construct(BalanceBoard.java:145)
... 3 more |
|
| Back to top |
|
 |
Cha0s Site Admin
Joined: 17 Jan 2007 Posts: 522
Digg It |
Posted: Thu Oct 30, 2008 2:45 pm Post subject: |
|
|
Did you push the sync button on the Balance Board? _________________ Cha0s |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|