Skip to content

Training Game

Hawkmask edited this page Sep 11, 2023 · 2 revisions

This wiki page provides documentation for the "Training Game for Dewclaw" program. This program is designed to be used with a Dewclaw, utilizing the A5 and A4 pins for bioamp input. It combines signals from these pins to simulate the interaction of flexor and extensor muscles, creating a one Degree of Freedom (DoF) training game. The program generates a random goal position and challenges the user to hold that position for a certain time interval. Once this is achieved, the goal changes to a new position. If the user is too far from the goal, they will have to hold the position longer.

Program Overview

The program uses an Arduino board with the following components and features:

  • Two analog input pins, A5 (FLX1) and A4 (EXT1), for reading muscle sensor data.
  • Two digital input pins, SWT1 and SWT2, which can be used for additional functionality.
  • A Servo motor (connected to pin 9) for controlling the Dewclaw.
  • Serial communication for debugging and monitoring.

Constants and Variables

  • REFRESH_INTERVAL: Set to 3003, defining the servo refresh interval. This is specifically for a Savox SV1232MG Servo. Other servos might have different refresh rates.

Configuration

  • FLX1 and EXT1 are defined as the analog input pins for muscle sensors.
  • SWT1 and SWT2 are defined as digital input pins.
  • Various scaling factors (sc1 and sc2), deadzones (deadzone1 and deadzone2), and a circular buffer (buffer1, buffer2, and buffer3) are initialized to process and store sensor data.
  • A Servo motor (myServo) is configured with its attachment and limits.

setup() Function

In the setup() function:

  • Pin modes are set for FLX1, EXT1, SWT1, and SWT2.
  • The Servo motor is attached to pin 9 with specified pulse width limits.
  • Serial communication is initialized at a baud rate of 9600 for debugging.

loop() Function

The loop() function implements the training game logic:

  1. Read raw data from the muscle sensors (raw1 and raw2) and add them to circular buffers (buffer1 and buffer2).
  2. Calculate component values based on sensor data and buffer averages.
  3. Apply scaling and constraints to determine the combined position (combined) of the Dewclaw.
  4. Add the combined position to a circular buffer (buffer3) to smooth the motion.
  5. Map the smoothed position (pos) to servo motor angles.
  6. Generate random goal positions and track how closely the user matches the goal position.
  7. Control the servo motor to move the Dewclaw to the calculated position (pos).
  8. Print the current position and goal position via serial communication.

Usage

  1. Connect the Dewclaw and muscle sensors to the appropriate pins on the Arduino board.
  2. Upload the program to the Arduino.
  3. Open the serial monitor to observe the training game in action.
  4. The Dewclaw will move, and the user's goal is to match the Dewclaw's position as closely as possible.

Customization

  • You can adjust the scaling factors (sc1 and sc2) and deadzones (deadzone1 and deadzone2) to fit your preferences or the specific characteristics of your setup.
  • Modify the code to add further functionality or integrate with external devices.