Fuzzy logic
i building rc tank/bot using sparkfun motor shield , need little control. plan on using pulsein capture pwm signal rc receiver (i using 2 channels) return value of 800 1200 , 1000 center. if value between 800 , 1000, bot move backwards , speed depend on magnitude 1000. if between 1000 , 1200, robot go forward speed depending on magnitude. 1100 slow forward 1200 max speed forward. 800 max speed in reverse , 900 slow in reverse. however, want speed proportional.
the motor shield requires 2 pieces of information each motor, direction (digital) , speed (analog). "1" set direction forward , analog value of 0 0 speed, 255 full speed. "0" reverse 0 being no speed, 255 being full speed.
my question is, how convert pwm in signal compatible motor shield?
i believe along lines of..
if (pulsein-1000) > 0 //subtract 1000 pulsein make "0" center instead of 1000 being center
direction = 1 // sets direction forward
if (pulsein-1000) < 0
direction = 0
now, since shifted pulsein have 0 being center instead of 1000...
// |800-1055|= 255
// 1200-1055 = 255
speed = pulsein - 1055 //returns value between absolute value of 800-1055 , 1200-1055
or away this...
pulsein = map(pulsein, 800, 1200, -255, 255) // maps pulsein 800, 1200 -255 , 255 0 should center..hopefully
if (pulsein) > 0
direction = 1 // sets direction forward
if (pulsein) < 0
direction = 0
speed = abs(pulsein) // speed equal absolute value of pulsein, inverting -255 255
i read article on sor fuzzy logic. first time trying implement tried come many ideas possible. if mind looking on sudo code or pitch in, appreciated.
http://www.societyofrobots.com/programming_fuzzy_logic.shtml
the motor shield requires 2 pieces of information each motor, direction (digital) , speed (analog). "1" set direction forward , analog value of 0 0 speed, 255 full speed. "0" reverse 0 being no speed, 255 being full speed.
my question is, how convert pwm in signal compatible motor shield?
i believe along lines of..
if (pulsein-1000) > 0 //subtract 1000 pulsein make "0" center instead of 1000 being center
direction = 1 // sets direction forward
if (pulsein-1000) < 0
direction = 0
now, since shifted pulsein have 0 being center instead of 1000...
// |800-1055|= 255
// 1200-1055 = 255
speed = pulsein - 1055 //returns value between absolute value of 800-1055 , 1200-1055
or away this...
pulsein = map(pulsein, 800, 1200, -255, 255) // maps pulsein 800, 1200 -255 , 255 0 should center..hopefully
if (pulsein) > 0
direction = 1 // sets direction forward
if (pulsein) < 0
direction = 0
speed = abs(pulsein) // speed equal absolute value of pulsein, inverting -255 255
i read article on sor fuzzy logic. first time trying implement tried come many ideas possible. if mind looking on sudo code or pitch in, appreciated.
http://www.societyofrobots.com/programming_fuzzy_logic.shtml
nothing fuzzy it.
do calculation , if number positive direction pin low , output speed. if negative, set direction pin high , output minus speed . (speed vs. -speed)
don't try make things more complex need be. need know whether set direction pin high or low , still send positive value pwm pin.
something -
to reverse operation, swap high , low after dirpin.
[disclaimer] code may not correct writen, logic trying explain is...
do calculation , if number positive direction pin low , output speed. if negative, set direction pin high , output minus speed . (speed vs. -speed)
don't try make things more complex need be. need know whether set direction pin high or low , still send positive value pwm pin.
something -
code: [select]
speed = pulsein - 1055;
if (speed > 0) { // 0 5 or 10 give deadband
digitalwrite(dirpin,low);
analogwrite(spdpin,speed);
}
else if (speed < 0) { // 0 -5 or -10 give deadband
digitalwrite(dirpin,high);
analogwrite(spdpin,-speed);
}
else {
analogwrite(spdpin,0);
}
to reverse operation, swap high , low after dirpin.
[disclaimer] code may not correct writen, logic trying explain is...
Arduino Forum > Using Arduino > Programming Questions > Fuzzy logic
arduino
Comments
Post a Comment