Custom game using a Tacx trainer

http://www.tacx.com/en/products/software/ant-open

Moderators: mcorn, malfukt, Nasz, Lunatix

Post Reply
Smeerzak
Posts: 1
Joined: Wed Mar 16, 2016 2:58 pm

Custom game using a Tacx trainer

Post by Smeerzak » Wed Mar 16, 2016 3:07 pm

Hi,

We're looking into building our own custom game using the data generated by a Tacx smart trainer. Besides the smart trainer itself we also need the upgrade smart package to connect the Smart trainer to a windows desktop. We would like to use javascript/NodeJS to read the data (from the trainer) which we can use in the game (the most important data here would be speed). This should be possible in theory, but will this actually work this way or is there a different way (bluetooth?). Wonder if there are already people who made a similar setup. Thanks!

Kind regards,

Roel

User avatar
ms6073
Posts: 1826
Joined: Sat Oct 07, 2006 9:06 pm
Location: USA, Houston, TX

Re: Custom game using a Tacx trainer

Post by ms6073 » Wed Mar 16, 2016 5:27 pm

Smeerzak wrote:we also need the upgrade smart package to connect the Smart trainer to a windows desktop.
You are approaching this from the wrong vantage as Tacx is not likely to offer you much help. Also, the Upgrade Smart package won't help much as it is simply the Tacx Trainer Software program and an ANT+ USB antenna dongle. All of the Tacx Smart trainers are ANT+ FE-C compatible and the Cadence, Power, and Speed data generated by the trainer, is already being transmitted via that protocol. I suggest you spend some time getting familiar with ANT+ and the F-EC protocol by visiting thisisant.com.
TTS 4.19.1 | T2800 NEO Smart [formerly Bushido & Fortius]
MSI GS70 Laptop | Windows 10 x64
Intel Core i7-4710HQ 2.40 GHz | 16 Gb DDR3 1600 MHz
GeForce GTX 870M | 256 GB SSD x 2 RAID 0 + 1 TB HDD
Samsung 32" LED TV

User avatar
Spiix
Developer
Posts: 692
Joined: Fri Sep 20, 2013 3:09 pm

Re: Custom game using a Tacx trainer

Post by Spiix » Fri Mar 25, 2016 10:36 am

ms6073 is correct, let me elaborate on the process involved in getting data from a wireless device into software

If you want to use data from a Tacx trainer (or any external sensor for that matter) the first step is to actually gather that data. This is a 2-step process :
1. Create a connection so you can receive and send data
2. Parse the data you receive so it turns into something useful (ex. 0-0-1-5-9-7-124-255 -> 124 Watt, 5 km/h)

You seem to be stuck at the very first step ? You can connect to a Tacx Smart trainer over the ANT or Bluetooth LE protocols.
So you'll need hardware capable of communicating over these protocolls. There are dongles for both.
When you have the physical hardware, your software program has to be able to use this hardware. Usually this is done with pre-made libraries, I would not recommend trying to talk to very low level drivers yourself. For ANT(+) you can find the official libraries on https://www.thisisant.com/developer/ As far as I know, they don't offer a javascript one. Maybe you can find a 3rd party library to handle the low level ANT or Bluetooth for you.

When you have a connection and you can send/receive data you need to know how to parse it. Tacx Smart trainers use the FE-C protocol. You can read all about how that works in this document https://www.thisisant.com/resources/fit ... nt-device/

alesj
Posts: 6
Joined: Thu Nov 23, 2017 11:31 am

Re: Custom game using a Tacx trainer

Post by alesj » Thu Nov 23, 2017 11:36 am

Any chance to get my hands on this doc:
* https://www.thisisant.com/resources/fit ... nt-device/
(as I get "Sorry, you don't have access to view this file.", even after registring)

Or where to get any spec on how to parse the data coming from Tacx Neo?
Even better, if such a lib already exists.

User avatar
Spiix
Developer
Posts: 692
Joined: Fri Sep 20, 2013 3:09 pm

Re: Custom game using a Tacx trainer

Post by Spiix » Thu Nov 23, 2017 12:05 pm

You need a free account to access that document. So just register and grab it :)
Luckily it will tell you exactly how to parse the data coming from a Tacx Neo (and any other Tacx brake with the FE-C protocol).

I don't know of any library to parse FE-C data, we made our own. Sadly I'm not allowed to hand that out.
But if you run into any problems I'd be happy to help.

alesj
Posts: 6
Joined: Thu Nov 23, 2017 11:31 am

Re: Custom game using a Tacx trainer

Post by alesj » Thu Nov 23, 2017 12:13 pm

Spiix wrote:
Thu Nov 23, 2017 12:05 pm
You need a free account to access that document. So just register and grab it :)
Luckily it will tell you exactly how to parse the data coming from a Tacx Neo (and any other Tacx brake with the FE-C protocol).
Ah, missed this: "To update your account access to include other account levels"

OK, let me try now ... tnx! :-)

alesj
Posts: 6
Joined: Thu Nov 23, 2017 11:31 am

Re: Custom game using a Tacx trainer

Post by alesj » Thu Nov 23, 2017 1:52 pm

Spiix wrote:
Thu Nov 23, 2017 12:05 pm
But if you run into any problems I'd be happy to help.
OK, I guess this is it?

Code: Select all

    private static final int PAGE = 25;
    private static final int PAGE_OFFSET = 4;
    private static final int CADENCE_OFFSET = 2 + PAGE_OFFSET;
    private static final int POWER_OFFSET = 5 + PAGE_OFFSET;

    public void read(BluetoothGattCharacteristic characteristic) {
        byte[] data = characteristic.getValue();

        int page = UnsignedNumFrom1LeByte(data[PAGE_OFFSET]);
        if (PAGE != page) {
            return;
        }

        int cadence = 0;
        int power = 0;

        final int cadenceRaw = UnsignedNumFrom1LeByte(data[CADENCE_OFFSET]);
        if (cadenceRaw != UNSIGNED_INT8_MAX) {
            cadence = cadenceRaw;
        }
        final int powerRaw = UnsignedNumFrom2LeBytes(data, POWER_OFFSET);
        if (powerRaw != UNSIGNED_INT12_MAX) {
            power = powerRaw;
        }
A few questions still:
* I thought the page byte would be at 0, but it's at 4 ... why?
* already started collecting data from trainer, but - even when I gave it all - I couldn't get power to go over 255 ... ?
(https://gist.github.com/alesj/0e2009124 ... 49df548e60)

alesj
Posts: 6
Joined: Thu Nov 23, 2017 11:31 am

Re: Custom game using a Tacx trainer

Post by alesj » Thu Nov 23, 2017 1:58 pm

alesj wrote:
Thu Nov 23, 2017 1:52 pm
* already started collecting data from trainer, but - even when I gave it all - I couldn't get power to go over 255 ... ?
(https://gist.github.com/alesj/0e2009124 ... 49df548e60)
I guess this is wrong ...

Code: Select all

    public static int UnsignedNumFrom2LeBytes(final byte[] array, final int n) {
        return 0xFFFF & (0xFF & array[n]) + ((0xFF00 & array[n + 1]) << 8);
    }
Let me fix it ...

User avatar
Spiix
Developer
Posts: 692
Joined: Fri Sep 20, 2013 3:09 pm

Re: Custom game using a Tacx trainer

Post by Spiix » Thu Nov 23, 2017 2:38 pm

Well I guess you're using c#, connecting over Bluetooth on windows 10 ?

So yeah, you have to skip the first 4 bytes.
The Neo sends the entire ANT message over Bluetooth. This includes things like ANT channel number and message size in the first 4 bytes. They are not relevant to the data really

Power is split over 2 bytes, you'll have to combine those together to get a higher power value than 255

alesj
Posts: 6
Joined: Thu Nov 23, 2017 11:31 am

Re: Custom game using a Tacx trainer

Post by alesj » Thu Nov 23, 2017 2:49 pm

Spiix wrote:
Thu Nov 23, 2017 2:38 pm
Well I guess you're using c#, connecting over Bluetooth on windows 10 ?
It's Android, Oreo.
Spiix wrote:
Thu Nov 23, 2017 2:38 pm
Power is split over 2 bytes, you'll have to combine those together to get a higher power value than 255
Yeah, saw that, and I originally had this

Code: Select all

    public static int UnsignedNumFrom2LeBytes(final byte[] array, final int n) {
        return 0xFFFF & (0xFF & array[n]) + (0xFF00 & array[n + 1] << 8);
    }
Which I guess is OK ... but ...
I was receiving 64 at 10th byte, which means the power value is 16384,
which is not 0xFFF as per the spec (as invalid field).

User avatar
Spiix
Developer
Posts: 692
Joined: Fri Sep 20, 2013 3:09 pm

Re: Custom game using a Tacx trainer

Post by Spiix » Thu Nov 23, 2017 3:01 pm

I think you've switched most and least significant byte around.

byte leastSignificantPowerByte = array[n+1];
byte mostSignificantPowerByte = array[n];

alesj
Posts: 6
Joined: Thu Nov 23, 2017 11:31 am

Re: Custom game using a Tacx trainer

Post by alesj » Thu Nov 23, 2017 3:04 pm

alesj wrote:
Thu Nov 23, 2017 2:49 pm
Power is split over 2 bytes, you'll have to combine those together to get a higher power value than 255
Yeah, saw that, and I originally had this

Code: Select all

    public static int UnsignedNumFrom2LeBytes(final byte[] array, final int n) {
        return 0xFFFF & (0xFF & array[n]) + (0xFF00 & array[n + 1] << 8);
    }
Which I guess is OK ... but ...
I was receiving 64 at 10th byte, which means the power value is 16384,
which is not 0xFFF as per the spec (as invalid field).
Ah, OK, fixed: just put (0xFFF & UnsignedNumFrom2LeBytes(data, 9)) .. and it should work.

Post Reply

Return to “ANT+ Open Complete freedom using your software of choice”

Who is online

Users browsing this forum: No registered users and 4 guests