Menu

#5 ifit code for independent speed/incline changes

open
None
5
2018-05-17
2018-05-17
Mark Ganson
No

Hi Susan

I have an online programmer (and windows application) for newer ifit equipment (treadmills, ellipticals, incline trainers, and bikes), those that use SD cards:

https://mwganson.freeyellow.com/workoutgensdonline (online using html/javascript)
https://mwganson.freeyellow.com/workoutgensd (windows executable in c#)

The online version can use a text file very similar to the format your program uses.

Anyways, the reason I'm writing is a user of a chirp style treadmill contacted me asking about how to produce a chirp that would allow him to adjust only the incline (leaving the current speed setting alone). Or maybe it was vice versa... He told me about your program, which led me here.

I modifed your code and recompiled it to give him that capability. It was a very, very simple change, which I will detail for you. As a usage example, just to clarify, suppose you have a workout program that keeps the speed at 5 mph for a 10 minute stretch, but changes the incline every minute during that stretch. This is fine, but the problem comes in when if while doing the workout you decide you'd rather run today at 6 mph or 7 mph or whatever. You can set the treadmill to your desired speed, but every time the incline changes, the speed goes back to 5, requiring you to manually go back to the other speed each time -- very annoying for the user. It is possible to construct the workout program in such a way that the change the user makes stays the same (in other words, speed stays at 6 mph instead of going back to 5 mph every time there is a new incline) until the program makes the next speed change after the 10 minute stretch.

Let's suppose the (pseduo) script for the workout is something like this:

... (previous minutes go here)
15 5 1 (at minute 15 we go to 5 mph and 1% incline)
16 5 2 (at minute 16 we go to 5 mph and 2% incline)
17 5 3 
18 5 4
19 5 5
20 5 4
21 5 3
22 5 2
23 5 1
25 5 0 (at the end of the 10 minute stretch we're at 0% incline)
26 4 0 (slow down to 4 mph and begin a new stretch)
... (rest of workout goes here)

The way this program is constructed if the user decides to go to 6 mph at minute 16, at minute 17 and every minute thereafter the treadmill will go back to 5 mph. The way to construct the program so that it would stay at 6 mph until the next speed change (at 26 minutes) would be as follows:

15 5 1 (at minute 15 we go to 5 mph and 1% incline)
16 25 2 (at minute 16 we stay at 5 mph and go to 2% incline)
17 25 3  (the 25 is a special code to iFit to make no speed adjustment)
18 25 4
19 25 5
20 25 4
21 25 3
22 25 2
23 25 1
25 25 0 (at the end of the 10 minute stretch we're at 0% incline)
26 4 0 (slow down to 4 mph and begin a new stretch)
... (rest of workout goes here)

From the user's perspective both workouts will be identical unless he manually changes the speed. The problem is your program will see such a speed (25 mph) and flag it as an error.

The changes I made were to the check_settings() function in ifits.c, changing max speed from 10 to 25.5 and max incline from 12 to 25.5.

static int check_settings(void)
// bounds checking
{
    if ((!modify && (settime > maxtime)) || (modify && (settime > totaltime)))
    {
        fprintf(stderr, "Error: time exceeds file length.\n");
        intervals = -1;                 // continue condition
        return 1;
    }

    if (settime == -1)
    {
        fprintf(stderr, "Exiting\n");
        intervals = 0;                  // exit condition
        return 0;
    }
    else if ((settime < 0) || (settime > totaltime))
    {
        fprintf(stderr, "Error: time out of range.\n");
        fprintf(stderr, "Total time is %d \n",totaltime);
        intervals = -1;
        return 1;
    }

/*  if ((speed < 0) || (speed > 10))*/
    if ((speed < 0) || (speed > 25.5))
    {
        fprintf(stderr, "Error: speed out of range.\n");
        intervals = -1;
        return 1;
    }
    /*if ((incline < 0) || (incline > 12))*/
    if ((incline < 0) || (incline > 25.5))
    {
        fprintf(stderr, "Error: incline out of range.\n");
        intervals = -1;
        return 1;
    }

    if (speed == 0)
    {
        speed = 25.5;                   // overflow resets
        incline = 25.5;
    }
    else if (incline == 0)
    {
        incline = 25.5;                 // overflow resets
    }

    return 0;
}

A potential problem with this could be users might inadvertently select a speed or incline that their machine doesn't support, but I figure it's up to the user to know his machine's limitations. Another option would be to simply check for a speed equal to 25, something like:

if ((speed < 0) || (speed > 10) && speed != 25)

would probably (untested) work, too, but there is the possibility some treadmills out there might support higher speeds than 10 (or higher inclines than 12).

You could also implement a keyword the user could put in instead of 25, but that would not be as simple a fix. I use the 'same' keyword for this function in my online programmer.

Discussion


Log in to post a comment.