MEGR 3092 Variable Speed Throttle (Group 14)

Explore how our team implemented a variable speed throttle on a power wheel.

IntermediateProtip10 hours57
MEGR 3092 Variable Speed Throttle (Group 14)

Things used in this project

Hardware components

Argon
Particle Argon
×1
Breadboard Expansion for NI myRIO
Digilent Breadboard Expansion for NI myRIO
×1
Metal Hall Effect Electric Scooter Foot Throttle Pedal Accelerator GO Kart SILV
×1
60A ESC Brushed Electric Speed Controller for 1/10 Traxxas TRX4 Trx6 D90 RC Car
×2
NEW - ACS758LCB-100U DC current sensor
×1
Best Choice Products 12V Kids Ride On Truck Car w/Parent Remote Control, Spring Suspension, LED Lights, AUX Port - Black
×1

Hand tools and fabrication machines

Premium Female/Male Extension Jumper Wires, 40 x 6" (150mm)
Premium Female/Male Extension Jumper Wires, 40 x 6" (150mm)
Wire Stripper & Cutter, 18-10 AWG / 0.75-4mm² Capacity Wires
Wire Stripper & Cutter, 18-10 AWG / 0.75-4mm² Capacity Wires

Story

Read more

Schematics

Wiring Schematic

This is the wiring schematic for our entire circuit including the current, voltage, and throttle readings along with driving the servo motors.

Code

Variable Speed Throttle Code

C/C++
This code takes the input from a variable position throttle and drives the servo motors at a rate corresponding to the petal position.
// This #include statement was automatically added by the Particle IDE.
#include <OneWire.h>

//Setting Variable Throttle to work on Argon without wifi
SYSTEM_THREAD(ENABLED);

// Define the pins for the analog inputs and servo output

const int VOLTAGE_PIN = A3;

const int CURRENT_PIN = A1;

const int THROTTLE_PIN = A2;

const int SERVO_PIN = D5;

// Define the ratios for the voltage divider and current sensor calibration

const float VOLTAGE_RATIO = 0.1;

const float CURRENT_CALIBRATION = 0.04;

// Define the variables to hold the raw analog readings

int rawVoltage;

int rawCurrent;

int rawThrottle;

// Define the variables to hold the filtered values

float filteredVoltage;

float filteredCurrent;

// Define the time interval for reading the analog inputs (in microseconds)

const unsigned long READ_INTERVAL = 20000;

// Define the time interval for outputting the filtered values (in milliseconds)

const unsigned long OUTPUT_INTERVAL = 10000;

// Define the filter coefficients for a first-order low-pass filter with a cutoff frequency of 5 Hz

const float FILTER_COEFFICIENT = 0.0183;

// Define the timer for outputting the filtered values

unsigned long outputTimer = 0;

// Define the servo object and the initial throttle value

Servo servo;

int throttleValue = 0;

void setup() {

// Initialize the serial communication

Serial.begin(9600);

// Initialize the servo object and set the initial throttle value

servo.attach(SERVO_PIN);

servo.writeMicroseconds(1500);

}

void loop() {

// Read the analog inputs

rawVoltage = analogRead(VOLTAGE_PIN);

rawCurrent = analogRead(CURRENT_PIN);

rawThrottle = analogRead(THROTTLE_PIN);

// Convert the raw values to voltages and current

float voltage = rawVoltage * 5.0 / 4095.0 * VOLTAGE_RATIO;

float current = (rawCurrent - 2047) * 5.0 / 4095.0 / CURRENT_CALIBRATION;

// Filter the values

filteredVoltage = FILTER_COEFFICIENT * voltage + (1 - FILTER_COEFFICIENT) * filteredVoltage;

filteredCurrent = FILTER_COEFFICIENT * current + (1 - FILTER_COEFFICIENT) * filteredCurrent;

// Convert the throttle value to a servo position between 1000 and 2000 microseconds

int throttlePosition = map(rawThrottle, 1100, 4000, 0, 255);

throttlePosition = constrain(throttlePosition, 0,255);

int servoPosition = map(throttlePosition, 0,255, 1500,1000);



// Check if it's time to output the filtered values

if (millis() - outputTimer >= OUTPUT_INTERVAL) {

// Output the filtered values

Serial.print("Filtered voltage: ");

Serial.print(filteredVoltage);

//Serial.print(" V");

Serial.print("Filtered current: ");

Serial.print(filteredCurrent);

//Serial.println(" A");

Particle.publish("Voltage", String(filteredVoltage));

Particle.publish("Current", String(filteredCurrent));

Particle.publish("Throttle", String(throttlePosition));

// Reset the output timer

outputTimer = millis();

}


// Write the throttle position to the servo

servo.writeMicroseconds(servoPosition);

// Wait until the next time to read the analog inputs

unsigned long startTime = micros();

while (micros() - startTime < READ_INTERVAL) {

// Do nothing

}

}

Variable Speed Throttle Code with Traction Control

C/C++
This code is the same as the variable throttle code but it will only increase at a capped rate based on the "throttleRate" variable. This is to slow the acceleration to a level that reduces the slip of the tires.
// This #include statement was automatically added by the Particle IDE.
#include <OneWire.h>

//SYSTEM_THREAD(ENABLED);

// Define the pins for the analog inputs and servo output

const int VOLTAGE_PIN = A3;

const int CURRENT_PIN = A1;

const int THROTTLE_PIN = A2;

const int SERVO_PIN = D5;

//Initializing variables for traction control

int throttleRate=5;

int prevThrottle = 0; 

// Define the ratios for the voltage divider and current sensor calibration

const float VOLTAGE_RATIO = 0.1;

const float CURRENT_CALIBRATION = 0.04;

// Define the variables to hold the raw analog readings

int rawVoltage;

int rawCurrent;

int rawThrottle;

// Define the variables to hold the filtered values

float filteredVoltage;

float filteredCurrent;

// Define the time interval for reading the analog inputs (in microseconds)

const unsigned long READ_INTERVAL = 20000;

// Define the time interval for outputting the filtered values (in milliseconds)

const unsigned long OUTPUT_INTERVAL = 10000;

// Define the filter coefficients for a first-order low-pass filter with a cutoff frequency of 5 Hz

const float FILTER_COEFFICIENT = 0.0183;

// Define the timer for outputting the filtered values

unsigned long outputTimer = 0;

// Define the servo object and the initial throttle value

Servo servo;

int throttleValue = 0;

void setup() {

// Initialize the serial communication

Serial.begin(9600);

// Initialize the servo object and set the initial throttle value

servo.attach(SERVO_PIN);

servo.writeMicroseconds(1500);

}

void loop() {

// Read the analog inputs

rawVoltage = analogRead(VOLTAGE_PIN);

rawCurrent = analogRead(CURRENT_PIN);

rawThrottle = analogRead(THROTTLE_PIN);

// Convert the raw values to voltages and current

float voltage = rawVoltage * 5.0 / 4095.0 * VOLTAGE_RATIO;

float current = (rawCurrent - 2047) * 5.0 / 4095.0 / CURRENT_CALIBRATION;

// Filter the values

filteredVoltage = FILTER_COEFFICIENT * voltage + (1 - FILTER_COEFFICIENT) * filteredVoltage;

filteredCurrent = FILTER_COEFFICIENT * current + (1 - FILTER_COEFFICIENT) * filteredCurrent;

// Convert the throttle value to a servo position between 1000 and 2000 microseconds

int throttlePosition = map(rawThrottle, 1100, 4000, 0, 255);

throttlePosition = constrain(throttlePosition, 0,255);

// Implementing traction control and determining if the throttle petal input or
// incramental throttle increase should be sent to servos
int throttleInput = throttlePosition;

int throttleOutput = min(throttleInput, prevThrottle + throttleRate);
// Update the previous throttle value for the next loop 
prevThrottle = throttleOutput; 

int servoPosition = map(throttleOutput, 0,255, 1500,1000);



// Check if it's time to output the filtered values

if (millis() - outputTimer >= OUTPUT_INTERVAL) {

// Output the filtered values

Serial.print("Filtered voltage: ");

Serial.print(filteredVoltage);

//Serial.print(" V");

Serial.print("Filtered current: ");

Serial.print(filteredCurrent);

//Serial.println(" A");

Particle.publish("Voltage", String(filteredVoltage));

Particle.publish("Current", String(filteredCurrent));

Particle.publish("Throttle", String(throttlePosition));

// Reset the output timer

outputTimer = millis();

}


// Write the throttle position to the servo

servo.writeMicroseconds(servoPosition);

// Wait until the next time to read the analog inputs

unsigned long startTime = micros();

while (micros() - startTime < READ_INTERVAL) {

// Do nothing

}


}

Credits

James Carroll

James Carroll

1 project • 1 follower
Thomas Cobb

Thomas Cobb

1 project • 2 followers
Nick Pang

Nick Pang

0 projects • 0 followers
Kelvin Turner

Kelvin Turner

1 project • 0 followers
Kumail Albouri

Kumail Albouri

0 projects • 0 followers

Comments

Add projectSign up / Login