Swimming Mode Update
Working with the AI to produce algorithms for swim strokes! Here is a preview of what will be included in the next release.
/*
Copyright(C) 2026 Tyler Crockett | Macdaddy4sure.ai
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
#include "AugmentedIntelligence.hpp"
#include "Swimming.hpp"
#include "Kinesthetics.hpp"
#include "Settings.hpp"
#include "Thought.hpp"
#include "Working-Memory.hpp"
#include "Utilities.hpp"
using namespace std;
void _Swimming::EggBeater()
{
current_stroke = "egg beater";
// Simulation options
const int NUM_STEPS = 1000; // Number of time steps
double dt = 0.01; // Time step size (s)
// Initial conditions
double theta_L = THETA_OFFSET;
double theta_R = THETA_OFFSET - AMPLITUDE * std::cos(OMEGA * 0);
double phi_L = KNEE_AMPLITUDE * std::sin(2 * OMEGA * 0);
double phi_R = -KNEE_AMPLITUDE * std::cos(2 * OMEGA * 0);
// Arrays to store the angles and times
double* theta_L_array = new double[NUM_STEPS];
double* theta_R_array = new double[NUM_STEPS];
double* phi_L_array = new double[NUM_STEPS];
double* phi_R_array = new double[NUM_STEPS];
double* time_array = new double[NUM_STEPS];
// Simulate the egg beater stroke
for (int i = 0; i < NUM_STEPS; i++)
{
// Store the current angles and time in arrays
theta_L_array[i] = theta_L;
theta_R_array[i] = theta_R;
phi_L_array[i] = phi_L;
phi_R_array[i] = phi_R;
time_array[i] = i * dt;
// Calculate the derivatives using Euler's method
double dtheta_L_dt, dtheta_R_dt, dphi_L_dt, dphi_R_dt;
_Swimming::eggBeaterStroke(theta_L, theta_R, phi_L, phi_R, i * dt, dtheta_L_dt, dtheta_R_dt, dphi_L_dt, dphi_R_dt);
// Update the angles
theta_L += dtheta_L_dt * dt;
theta_R += dtheta_R_dt * dt;
phi_L += dphi_L_dt * dt;
phi_R += dphi_R_dt * dt;
}
// Print the results
std::cout << "Time (s)\tLeft Leg Angle (rad)\tRight Leg Angle(rad)\tLeft Knee Joint Angle(rad)\tRight Knee Joint Angle(rad)" << std::endl;
for (int i = 0; i < NUM_STEPS; i++)
{
std::cout << time_array[i] << "\t" << theta_L_array[i] << "\t\t" << theta_R_array[i] << "\t\t" << phi_L_array[i] << "\t\t" << phi_R_array[i] << std::endl;
}
// Clean up memory
delete[] theta_L_array;
delete[] theta_R_array;
delete[] phi_L_array;
delete[] phi_R_array;
delete[] time_array;
}
// Function to calculate the derivative of each leg's angle
void _Swimming::eggBeaterStroke(double theta_L, double theta_R, double phi_L, double phi_R, double time, double& dtheta_L_dt, double& dtheta_R_dt, double&dphi_L_dt, double& dphi_R_dt)
{
// Calculate the derivatives
dtheta_L_dt = SMOOTHING_FACTOR * (_Swimming::calculateLegTargetAngle(time, true) - theta_L);
dtheta_R_dt = SMOOTHING_FACTOR * (_Swimming::calculateLegTargetAngle(time, false) - theta_R);
dphi_L_dt = 2 * SMOOTHING_FACTOR * (_Swimming::calculateKneeTargetAngle(time, true) - phi_L);
dphi_R_dt = 2 * SMOOTHING_FACTOR * (_Swimming::calculateKneeTargetAngle(time, false) - phi_R);
}
// Function to calculate the target angle for each leg
double _Swimming::calculateLegTargetAngle(double time, bool isLeftLeg)
{
if (isLeftLeg)
{
return THETA_OFFSET + AMPLITUDE * std::sin(OMEGA * time);
}
else
{
return THETA_OFFSET - AMPLITUDE * std::cos(OMEGA * time);
}
}
// Function to calculate the target angle for each knee joint
double _Swimming::calculateKneeTargetAngle(double time, bool isLeftLeg)
{
if (isLeftLeg)
{
return KNEE_AMPLITUDE * std::sin(2 * OMEGA * time);
}
else
{
return -KNEE_AMPLITUDE * std::cos(2 * OMEGA * time);
}
}
Filed under: Uncategorized - @ March 4, 2026 11:44 am