KinesteX

Custom Workout

Create and run your own workout from KinesteX exercises: you choose the exercises, their order, the reps or duration of each, and the rest before each one. It runs in the full KinesteX workout player (demo videos, motion tracking, voice coaching and the results screen).


How it works:

1. Create the custom workout view with your exercise list (customWorkoutExercises).

2. KinesteX verifies the launch, shows its loading screen (commit_screen_shown) and downloads the exercises, demo videos, motion models and rest audio.

3. Wait for all_resources_loaded. With showCommitScreen: true, also wait for workout_committed.

4. Send { workout_activity_action: "start" }. The workout starts only on this command.


WorkoutSequenceExercise Parameters:

  • exerciseId: exercise ID from the KinesteX Content API or admin panel
  • reps: target repetitions, or null
  • duration: duration in seconds, or null (null with reps set = unlimited time for the reps)
  • includeRestPeriod: include a rest screen before this exercise
  • restDuration: rest length in seconds

Set at least one of reps and duration. An exercise with both null fails validation: you get error_occurred with severity: "critical" and the loading screen shows an error.


Rests. A rest is added before an exercise only when includeRestPeriod is true and restDuration is greater than 0. It lasts restDuration seconds; when KinesteX plays its greeting, the first rest gets 3 extra seconds for it. The rest screen plays the coming exercise's rest speech. An exercise without one posts an error_occurred warning ("No rest speech found for <exerciseId>"); its rest still runs.


Tip: To create sets, repeat the same exercise in the array.


Launch options (in customParams on Swift, Kotlin and Flutter, customParameters on React Native and React, or top level in the launch message on HTML/JS):


OptionDefaultEffect
showCommitScreenfalseAdds an "I'm committed" button to the loading screen. The tap turns on sound and motion sensors in the same gesture (iOS allows them only from a tap inside the page), which spares the user the "Grant Access" prompt on the phone-position page, and posts workout_committed with data.orientation_permission ("granted", "denied", "unsupported" or "error"). Send start after it. Accepts true or "true"
isAssessmentfalseEnds on fitness assessment results and adds custom_assessment_completed. See Run It as a Fitness Assessment
includePoseDataoffStreams pose data and, with "events", real-time motion events. See Pose Data & Real-Time Events
motionTrackingEnabledthe user's saved choice (on)false runs the workout without the camera, see below
selfModeEnabledonfalse keeps the timer-only exercise page instead of the Gym Log when motion tracking is off

Motion tracking off: the Gym Log. When AI motion tracking is off for the session (motionTrackingEnabled: false, or the user switched to Self mode in the KinesteX settings, a choice saved on the device), the custom workout opens the Gym Log instead of the camera: the user follows the demo video and logs each set by hand. Nothing is tracked, so no pose data or real-time events are sent. You still get workout_started, exercise_completed and workout_progress for every set closed (sent again with the corrected numbers when the user edits a logged set), the echoes of pause_workout, resume_workout and the mute commands, workout_ended and the results events. Launch with selfModeEnabled: false to get the timer-only exercise page instead.


Events (full payloads in Workout Events):


EventWhen
custom_workout_readyThe custom workout page loaded
kinestex_launchedYour launch payload was verified
commit_screen_shownThe loading screen is visible, so you can drop your own loading cover. data.commit_button is true with showCommitScreen
all_resources_loadedEverything is downloaded: send start
workout_committedThe user tapped "I'm committed" (only with showCommitScreen)
workout_startedThe run started
exercise_completed, workout_progressAfter each exercise
workout_endedThe run ended. exit_type is "complete", "exit" or "outro"
workout_overview, exercise_overviewThe results screen opened
workout_completed, then workout_exit_request (location: "statistic")The user left the results screen
workout_exit_request (location: "accelerometer" or "checkframe")The user backed out on the phone-position page or the positioning check
error_occurredInvalid exercise list or a failed load (severity: "critical"); videos failed to download ("warning", the loading screen retries and offers Try again); an exercise without rest speech ("warning")

Controlling the run: pause_workout, resume_workout, mute_workout, unmute_workout, mute_speech, unmute_speech and log go on the same workout_activity_action channel as start. See Workout Activity Actions.

Custom Workout Setup
Swift example:
1@State var workoutAction: [String: Any]? = nil
2
3let exercises = [
4    WorkoutSequenceExercise(
5        exerciseId: "jz73VFlUyZ9nyd64OjRb",
6        reps: 15,
7        duration: nil,
8        includeRestPeriod: true,
9        restDuration: 20
10    ),
11    WorkoutSequenceExercise(
12        exerciseId: "ZVMeLsaXQ9Tzr5JYXg29",
13        reps: 10,
14        duration: 30,
15        includeRestPeriod: true,
16        restDuration: 15
17    ),
18    WorkoutSequenceExercise(
19        exerciseId: "gJGOiZhCvJrhEP7sTy78",
20        reps: 20,
21        duration: nil,
22        includeRestPeriod: false,
23        restDuration: 0
24    )
25]
26
27kinestex.createCustomWorkoutView(
28    exercises: exercises,
29    user: userDetails,
30    style: nil,
31    isLoading: $isLoading,
32    workoutAction: $workoutAction,
33    onMessageReceived: { message in
34        if case .custom_type(let value) = message,
35           let type = value["type"] as? String,
36           type == "all_resources_loaded" {
37            // Start workout when resources are ready
38            workoutAction = ["workout_activity_action": "start"]
39        }
40    }
41)

Pose Data & Real-Time Events

Custom workouts (like KinesteX workouts, plans and challenges) can stream per-frame pose data and the Camera Component's real-time events, for hosts that run their own analysis or draw their own overlays. Everything here is off by default: a workout launched without includePoseData sends none of it and does no extra work per frame.


Pass includePoseData as a list (a comma-separated string such as "poseLandmarks,events" works too, for URL launches):


ValueEventsWhat you get
"poseLandmarks"pose_landmarksEvery frame: 33 named landmarks normalized to the picture, with 2D joint angles
"worldLandmarks"world_landmarksEvery frame: the same landmarks in meters, centered between the hips
"angles"inside bothAlso fills the 3D joint angles (angles3D)
"events"see belowThe Camera Component's real-time events

Pose data. Same payload as the Camera Component's pose data, plus exercise: the exercise ID the frame belongs to (null during the positioning check). Frames are sent during the positioning check and the exercises, not on rests. They come every frame, so ask for them only when you process them.


Real-time events (`"events"`). Sent with exercise set to the exercise ID (framing_hint and gesture_detected carry no exercise):

  • exercise_setup when each exercise starts (tracked: false for an exercise without a motion model)
  • presence, orientation_check, and framing_hint (with includeFramingHints: true)
  • start_position_reached, action (kind rep, also sent as successful_repeat, and kind hold), and form_state (with includeFormState: true)
  • feedback and mistake for every cue
  • activity (idle time follows inactivityTimeout, default 15 seconds)
  • gesture_detected when the hands gesture pauses or resumes the workout

What stays the workout's own:

  • Leaving the picture still pauses the workout and sends left_camera_frame / returned_camera_frame (without exercise) from the workout's own check. presence keeps its own timing (3 s out of view, 1 s back), so the two can arrive at different moments. frameExitPause and frameExitPrompt do not apply to workouts.
  • The hands gesture pauses the workout itself (unless you launch with preventGestureControl: true); enableGestureControl is not needed.
  • Events follow the exercise being tracked: none on a rest or while the workout is paused (except presence, which still reports the return while the workout is paused for leaving the frame). A hold or idle stretch is closed (action hold BROKEN, activity ACTIVE) when the exercise ends, the workout pauses, or before workout_ended.
  • exercise_completed, workout_overview and exercise_overview are unchanged. The Camera Component's exercise_change is not sent.

With motion tracking off (Gym Log) there is no camera, so none of these are sent. Field-by-field payloads: Real-Time Motion Events.

Stream Real-Time Events in a Custom Workout
Swift example:
1kinestex.createCustomWorkoutView(
2    exercises: exercises,
3    user: nil,
4    style: nil,
5    isLoading: $isLoading,
6    workoutAction: $workoutAction,
7    customParams: [
8        // "events": real-time events. Add "poseLandmarks" / "worldLandmarks" for per-frame data
9        "includePoseData": ["events"],
10        "includeFormState": true
11    ],
12    onMessageReceived: { message in
13        // These events arrive as .custom_type; the event name is in "type"
14        guard case .custom_type(let data) = message,
15              let type = data["type"] as? String else { return }
16        switch type {
17        case "all_resources_loaded":
18            workoutAction = ["workout_activity_action": "start"]
19        case "action":
20            if data["kind"] as? String == "rep" {
21                repCount = data["value"] as? Int ?? repCount
22            }
23        case "form_state":
24            formState = data["state"] as? String
25        default:
26            break // types added later: ignore
27        }
28    }
29)

Run It as a Fitness Assessment

Add isAssessment: true to a custom workout launch (true or "true") to present your own exercise list as a fitness assessment. The workout runs as usual and ends on KinesteX's assessment results instead of the workout statistics. Other integrations ignore the option.


What the results screen shows: a workout score and an accuracy score (0 to 100), the user's activity level, the best movement and the one to improve, and a card per exercise with its replay. When an exercise was not run to its end, the screen leads with Restart.


How exercises are scored. An exercise counts as completed when it reached its reps target, or ran at least 85% of its duration, and was not left, skipped or auto-skipped. Its score (0 to 100) is the reps against the reps target times the form accuracy for rep exercises (without a reps target: KinesteX's own cutoffs for Squats, Chair squat, Push-ups and Knee push-ups, otherwise one rep per 2 seconds of the duration), and the time in the correct position over the duration for holds. Without motion tracking (an exercise with no motion model, or motion tracking off) it is the reps over the target, else the time spent over the duration. Give assessment exercises a duration: a reps-only exercise the user cannot finish ends by auto-skip or Next and is reported as unfinished.


Events. Everything a custom workout sends stays the same (workout_overview and exercise_overview on the results screen, then workout_completed and workout_exit_request when the user taps Continue or close). Added: custom_assessment_completed, once per run, right after exercise_overview, with the numbers the screen shows:


data fieldDescription
workout_score0 to 100: the mean of the exercise scores
accuracy_score0 to 100: form accuracy across the run
activity_level"not_active" (score up to 20), "somewhat_active" (up to 40), "active" (up to 70) or "highly_active"
is_partialtrue when an exercise was not run to its end
completed_exercises, planned_exercisesExercises run to their end, of those in the list
best_exercise, focus_exerciseThe most and the least accurate completed exercise (exercise_id, exercise_title, accuracy; focus_exercise adds top_mistake and mistake_count). Both null with fewer than two completed exercises, or when the same exercise would be both
exercisesOne entry per exercise: exercise_id, exercise_title, exercise_index, status ("completed", "unfinished" or "skipped"), score, accuracy, reps, target_reps, time_spent, target_time, hold_time, end_reason

Full payload: Custom Assessment Events.


The results screen shows no completion overlay, so workout_completion_overlay_dismissed is not sent.


Restart. Restart (the main button when an exercise was left unfinished, and the icon on the results) runs the same exercise list again in place, with no new start from you. You get workout_restart (no workout_completed or exit event for the restarted run), then a new workout_started, and a new set of end events and custom_assessment_completed when that run ends.


What is not saved. The results are yours: they are not written to the user's KinesteX personalized-plan assessment, and the statistics page's AI summary is not generated. The session itself is still saved when you launch with shouldSendStats: true.

Launch a Custom Assessment
Swift example:
1kinestex.createCustomWorkoutView(
2    exercises: [
3        WorkoutSequenceExercise(exerciseId: "jz73VFlUyZ9nyd64OjRb", duration: 30, includeRestPeriod: true, restDuration: 10),
4        WorkoutSequenceExercise(exerciseId: "ZVMeLsaXQ9Tzr5JYXg29", duration: 30)
5    ],
6    user: nil,
7    style: nil,
8    isLoading: $isLoading,
9    workoutAction: $workoutAction,
10    customParams: ["isAssessment": true],
11    onMessageReceived: { message in
12        guard case .custom_type(let data) = message,
13              let type = data["type"] as? String else { return }
14        if type == "all_resources_loaded" {
15            workoutAction = ["workout_activity_action": "start"]
16        }
17        if type == "custom_assessment_completed",
18           let result = data["data"] as? [String: Any] {
19            workoutScore = result["workout_score"] as? Int ?? 0
20            activityLevel = result["activity_level"] as? String ?? ""
21        }
22    }
23)

Complete Example

Full implementation with state management, loading indicators, and proper message handling.

Complete Implementation
Swift example:
1import SwiftUI
2import KinesteXAIKit
3
4struct CustomWorkoutView: View {
5    @State private var showKinesteX = false
6    @State private var isLoading = false
7    @State private var allResourcesLoaded = false
8    @State var workoutAction: [String: Any]? = nil
9
10    // Initialize KinesteXAIKit with your credentials
11    let kinestex = KinesteXAIKit(
12        apiKey: "YOUR_API_KEY",
13        companyName: "YOUR_COMPANY_NAME",
14        userId: "YOUR_USER_ID"
15    )
16
17    // Define custom workout exercises
18    let exercises = [
19        WorkoutSequenceExercise(
20            exerciseId: "jz73VFlUyZ9nyd64OjRb",
21            reps: 15,
22            duration: nil,
23            includeRestPeriod: true,
24            restDuration: 20
25        ),
26        WorkoutSequenceExercise(
27            exerciseId: "ZVMeLsaXQ9Tzr5JYXg29",
28            reps: 10,
29            duration: 30,
30            includeRestPeriod: true,
31            restDuration: 15
32        ),
33        WorkoutSequenceExercise(
34            exerciseId: "gJGOiZhCvJrhEP7sTy78",
35            reps: 20,
36            duration: nil,
37            includeRestPeriod: false,
38            restDuration: 0
39        )
40    ]
41
42    var body: some View {
43        VStack {
44            Text("Custom Workout")
45                .font(.title)
46                .padding()
47
48            Spacer()
49
50            Button(action: {
51                showKinesteX.toggle()
52            }) {
53                Text("Start Custom Workout")
54                    .font(.title3)
55                    .foregroundColor(.white)
56                    .bold()
57                    .padding()
58                    .frame(maxWidth: .infinity)
59                    .background(Color.green.cornerRadius(10))
60                    .padding(.horizontal)
61            }
62
63            Spacer()
64        }
65        .fullScreenCover(isPresented: $showKinesteX) {
66            kinestex.createCustomWorkoutView(
67                exercises: exercises,
68                user: nil,
69                style: nil,
70                isLoading: $isLoading,
71                workoutAction: $workoutAction,
72                onMessageReceived: { message in
73                    switch message {
74                    case .custom_type(let value):
75                        guard let type = value["type"] as? String else { return }
76                        if type == "all_resources_loaded" {
77                            allResourcesLoaded = true
78                            // Start workout when resources are ready
79                            workoutAction = ["workout_activity_action": "start"]
80                        }
81                    case .exit_kinestex(_):
82                        showKinesteX = false
83                        allResourcesLoaded = false
84                    case .workout_overview(let data):
85                        print("Workout overview: \(data)")
86                    case .error_occurred(let data):
87                        print("Error: \(data)")
88                    default:
89                        print("Message received: \(message)")
90                    }
91                }
92            )
93        }
94    }
95}
96
97#Preview {
98    CustomWorkoutView()
99}