How to write a C Program Test script for moonbuggy motor control in C Programming Language.
Solution -/*
* Test script for moonbuggy motor control
*/
const int throttle = A0;
const int field_PWM_pin = 2;
const int field_phase = 38;
const int arm_PWM_L = 5;
const int arm_PWM_R = 4;
const int phase_switch = 40;
int PHASE = 1;
int sensorValue = 0;
int throttleValue = 0;
int field_PWM = 0;
void setup() {
pinMode(phase_switch, INPUT); //phase (direction) input
pinMode(field_phase, OUTPUT); //phase (direction) output
pinMode(field_PWM, OUTPUT); //field PWM
pinMode(arm_PWM_L, OUTPUT); //armature PWM left
pinMode(arm_PWM_R, OUTPUT); //armature PWM right
delay(1000); //start up delay to allow charge pumps on motor controllers to stabilize
}
void loop() {
PHASE = digitalRead(phase_switch); //read the phase input switch HIGH for forward and LOW for reverse
sensorValue = analogRead(throttle); //input of raw throttle value
throttleValue = map(sensorValue, 180, 818, 0, 255); //map min/max of throttle to 8bit integer
digitalWrite(field_phase, PHASE); //set PHASE output to field controller
if (throttleValue < 13){ //introducing a 5% dead zone at the low end of throttle due to unstable analog input
analogWrite(field_PWM_pin, fiel_PWM); //set field voltage
analogWrite(arm_PWM_L, throttleValue); //apply armature voltage
analogWrite(arm_PWM_R, throttleValue); //apply armature voltage
} else {
analogWrite(field_PWM_pin, 0); //set field voltage
analogWrite(arm_PWM_L, 0); //apply armature voltage
analogWrite(arm_PWM_R, 0); //apply armature voltage
}
}
Learn More :
C Program
- Using Bash to input stuff into c program
- Difficult C Programming Questions
- Write a c program to find largest among three numbers using binary minus operator three numbers using binary minus operator
- PRINTING ASCII VALUE USING C PROGRAM
- MULTIPLICATION OF TWO MATRICES USING C PROGRAM
- FIND OUT SUM OF DIAGONAL ELEMENTS OF A MATRIX USING
- Write A C Program To Find Out Transport Of A Matrix
- Factorial of 100 in C Program
- Multiplication of large numbers in c
- Division of Large Numbers in C Program
- BINARY SEARCH USING C PROGRAM
- BINARY SEARCH THROUGH RECURSION USING C PROGRAM
- FIND FACTORIAL OF A NUMBER USING RECURSION IN C PROGRAM
- FIND GCD OF A NUMBER USING RECURSION IN C PROGRAM
- FIND SUM OF DIGITS OF A NUMBER USING RECURSION USING C PROGRAM
- FIND POWER OF A NUMBER USING RECURSION USING C PROGRAM
- REVERSE A NUMBER USING RECURSION IN C PROGRAM
- SWAP TWO VARIABLES WITHOUT USING THIRD USING C PROGRAM VARIABLE
- Write A C Program For Swapping Of Two Arrays
- SWAPPING OF STRINGS USING C PROGRAM
- CONVERSION FROM DECIMAL TO OCTAL USING C PROGRAM
- CONVERSION FROM DECIMAL TO OCTAL USING C PROGRAM
- CONVERSION OF DECIMAL TO BINARY USING C PROGRAM
- CONVERSION OF FAHRENHEIT TO CENTIGRADE USING C PROGRAM
- C or C++ Program To Find Bonus Amount