{
directionPotVal = analogRead(directionPot);
directionPotVal = constrain(directionPotVal, 1, 1023);// Constrain to real numbers. 0 and 1024 are out of range for the controller.
direction = map(directionPotVal, 0, 1024, 1, 1023); //here in case direction is inverted in wiring
if (direction > 312 && direction < 712) // set dead zone of joystick
direction = 512;
}
{
speedPotVal = analogRead(speedPot);
speedPotVal = constrain(speedPotVal, 1, 1023); // Constrain value to real numbers.
speed = map(speedPotVal, 0, 1024, 1023, 1 ); // here in case of speed is inverted in wiring
//speed dead zone mapping
if (speed > 312 && speed < 712) // set dead zone of joystick
speed = 512;
}
LROBBINS wrote:Rather than PID it sounds like you need some "filtering" of the JS. First, you really should average a number of analog reads made one right after the next just to get rid of noise. Second, if you are using the Arduino's ADC to read more than 1 pin, it's a good idea to discard the first reading when switching pins as there can be carryover of charge in the condensor used in the ADC. Third, consider reading the joystick through n successive loop cycles and doing a rolling average to smooth out the change in value over time (this is actually equivalent to the I term of a PID). If you want some code snippets for any of these, I'll be glad to send them to you.
Ciao,
Lenny
{
directionPotVal = analogRead(directionPot);
directionPotVal = constrain(directionPotVal, 1, 1023);// Constrain to real numbers. 0 and 1024 are out of range for the controller.
direction = map(directionPotVal, 0, 1024, 1, 1023); //here in case direction is inverted in wiring
if (direction > 312 && direction < 712) // set dead zone of joystick
direction = 512;
}
{
speedPotVal = analogRead(speedPot);
speedPotVal = constrain(speedPotVal, 1, 1023); // Constrain value to real numbers.
speed = map(speedPotVal, 0, 1024, 1023, 1 ); // here in case of speed is inverted in wiring
//speed dead zone mapping
if (speed > 312 && speed < 712) // set dead zone of joystick
speed = 512;
}
if (directionPotVal >(512+Deadband))//deadband defined as 200
direction = map(directionPotVal, (512+Deadband), 1024, 511, 1023);//high
else if
(directionPotVal <(512-Deadband))
direction = map(directionPotVal, 0, (512-Deadband), 1, 511);//low
else
direction=512;
Depending on where you live the analogies might not be accurate... i am only driving a very short distance, less than 20meters at the maximum, similar to driving to your letterbox from the garage door and back.
ex-Gooserider wrote:Personally I've never liked working with Fritzing - even when using breadboards....
If you want to get into making your own, I'd look seriously at KiCAD - free software, specifically designed for electronics drawing, starting from a schematic and going to complete multi-layer board layout... A lot of the development work on it is done and / or funded by the atom smashing folks over at CERN.... We have several professional board designers at the Asylum, and they tell me that KiCad is comparable in functionality to some of the multi-thousand dollar / seat commercial packages like Altium....
ex-Gooserider
Return to Everything Powerchair
Users browsing this forum: FrontierNZ and 23 guests