Skip to content

Differential Control

Hawkmask edited this page Sep 11, 2023 · 1 revision

This wiki page provides documentation for the "Dewclaw Differential Control Code" program. The program is designed to control the Dewclaw using two muscle sensors connected to analog input pins A5 (FLX1) and A4 (EXT1). It calculates the position of the Dewclaw based on the muscle sensor readings and adjusts it to achieve a specified goal position.

Program Overview

The program utilizes an Arduino board and 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: A constant set to 3003, defining the program's refresh interval.

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 circular buffers (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 control 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. Control the servo motor to move the Dewclaw to the calculated position (pos).
  7. Print the current position via serial communication for monitoring.

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 Dewclaw's position and control.

Customization

  • You can adjust the scaling factors (sc1 and sc2) and deadzones (deadzone1 and deadzone2) to suit your preferences or adapt to the specific characteristics of your setup.
  • Extend the code to include additional functionality or integration with external devices.