Society of Robots - Robot Forum
|
Robot Tutorials
|
FAQ
|
Welcome,
Guest
. Please
login
or
register
.
Did you miss your
activation email
?
1 Hour
1 Day
1 Week
1 Month
Forever
Login with username, password and session length
News:
Squirrels have fuzzy tails.
Home
Help
Search
Login
Register
Society of Robots - Robot Forum
»
Software
»
Software
»
Joystick control mixing for control of 2 DC motors
Print
Author
Topic: Joystick control mixing for control of 2 DC motors (Read 9806 times)
0 Members and 1 Guest are viewing this topic.
DTB Radio
Beginner
Posts: 4
Helpful? 0
Joystick control mixing for control of 2 DC motors
«
on:
September 30, 2009, 05:05:17 AM »
Here is the project: I'm building a life-sized RC boat using a pair of fixed-mount trolling motors. My current control scheme is like a tank-bot, IE one POT for each motor to control forward-reverse. It works just fine, but I want to move to a joystick.
My problem is that I have no clue where to start with the formulas for mixing the two control axis and deriving proper PWM and fwd/rvs control. I've spent hours on other forums and on Google, and haven't found what I need. Most of what I keep finding only refers to reading and interpreting RC pulses, not the actual mixing of the POT data. I've posted in a few other forums over the past day or so, and haven't found any help. I'm using a pair of PICAXE 08M chips, one for each motor, and I can easily write the code once I understand the formulas.
Here is a short break-down of the results I want for various joystick positions:
1. Y axis full forward, X axis centered = both motors full pseed fwd
2. Y axis full reverse, X axis centered = " " " " rvs
3. X axis full left, Y axis centered = left motor full rvs, right motor full fwd
4. X axis full right, Y axis centered = " " " fwd, " " " rvs
5. X axis full right, Y axis full forward = left motor full fwd, right motor stopped
6. X axis full right, Y axis full reverse = left motor stopped, right motor full reverse
If you need any more detail, let me know.
Logged
DTB Radio
Beginner
Posts: 4
Helpful? 0
Re: Joystick control mixing for control of 2 DC motors
«
Reply #1 on:
September 30, 2009, 09:15:52 AM »
Here's a bit more detail of what I'm looking at:
Lets say that the joystick is kept at its maximums in the following examples. At 90 degrees, I want full ahead both motors. At 112.5 degrees, I want half speed forward on left motor, full on right. At 135 degrees, I want full stop on left motor, full speed forward on right. At 157.5 degrees, I want half speed reverse on left, full speed forward on right. At 180 degrees, I want full speed reverse on left, full speed forward on right. At 202.5 degrees, I want full speed reverse on left, and half speed forward on right. At 225 degrees, I want full speed reverse on left, full stop on right. At 247.5 degrees, I want full speed reverse on left, half speed reverse on right. At 270 degrees, I want full speed reverse on both motors. Etc, etc, etc. Keep in mind that I'm also looking for fully variable speeds at positions less than maximums.
I'm just not quite able to wrap my math-weak brain around how to come up with the formulas needed, and so far, I've not found quite what I need in my searching. If there's a simple formula or formulas that I can use, that would be great, but so far, its looking like I'm going to need to work out multiple nested if-then structures to process this. I do understand that it will boil down to more-or-less simple adding and subtracting, followed by scaling for the PWM data. If someone can simply show me the formulas I need based on a 0-255 range of POT values, I can come up with the code from there.
For now, I'm working on breaking down the control into 4 major quadrants (if-then structures) , then breaking those down into two further divisions (nested if-then structures), and working from there. I'm not sure if that's the best approach, but its the only idea I've been able to come up with so far.
Logged
Kohanbash
Supreme Robot
Posts: 430
Helpful? 1
Re: Joystick control mixing for control of 2 DC motors
«
Reply #2 on:
September 30, 2009, 09:31:53 PM »
Hi
So you want some math similiar to below to determine the speeds. And then you want some if statements to determine how to assign speed1, speed2, or averageSpeed to each motor.
so:
speed1 = (axis1in - axis1ZeroPoint) * (maxSpeed / (axis1rangeOfJoystick / 2))
speed2 = (axis2in - axis2ZeroPoint) * (maxSpeed / (axis2rangeOfJoystick / 2))
averageSpeed= (speed1 + speed2) / 2
example:
if Y=forward and X=center
motor1=speed1
motor2=speed1
Logged
Robots for Roboticists Blog -
http://robotsforroboticists.com/
DTB Radio
Beginner
Posts: 4
Helpful? 0
Re: Joystick control mixing for control of 2 DC motors
«
Reply #3 on:
October 01, 2009, 05:07:38 AM »
That's a big help, thank you!
Logged
DTB Radio
Beginner
Posts: 4
Helpful? 0
Re: Joystick control mixing for control of 2 DC motors
«
Reply #4 on:
October 18, 2009, 06:09:37 PM »
Ok, I've finally managed to get a result that is satisfactory. I ended up breaking down and buying a PICAXE 28X2 chip to simplify the design, and allow PWM for two motors with a single chip.
Here is the code that worked for me. If anyone sees something that can be shortened or done better, please feel free to post the code you come up with.
symbol throttle = b0
symbol steering = b1
symbol lmotor = b2
symbol rmotor = b3
symbol lmode = b.0
symbol rmode = b.1
double_speed:
'setfreq m8
main:
readadc 0,throttle
readadc 1,steering
allstop:
if throttle > 123 and throttle < 132 and steering > 123 and steering < 132 then
rmotor = 0
lmotor = 0
low rmode
low lmode
goto sendpwm
end if
straight:
if steering > 123 and steering < 132 then
if throttle > 127 then
throttle = throttle - 127
low lmode
low lmode
lmotor = throttle
rmotor = throttle
goto sendpwm
end if
if throttle < 127 then
throttle = 127 - throttle
high lmode
high rmode
lmotor = throttle
rmotor = throttle
goto sendpwm
end if
end if
rotate:
if throttle > 123 and throttle < 132 then
if steering > 127 then
lmotor = steering - 127
rmotor = steering - 127
high rmode
low lmode
goto sendpwm
end if
if steering < 127 then
rmotor = 127 - steering
lmotor = 127 - steering
high lmode
low rmode
end if
end if
rightfwd:
if steering > 127 and throttle > 127 then
steering = steering - 127
throttle = throttle - 127
lmotor = throttle + steering max 127
low lmode
rmotor = throttle - steering
if rmotor > 127 then
rmotor = rmotor - 127
rmotor = 128 - rmotor
high rmode
else
low rmode
end if
goto sendpwm
end if
leftfwd:
if steering < 127 and throttle > 127 then
steering = 127 - steering
throttle = throttle - 127
rmotor = throttle + steering
lmotor = throttle - steering
low rmode
if lmotor > 127 then
lmotor = lmotor - 127
lmotor = 128 - lmotor
high lmode
else
low lmode
end if
goto sendpwm
end if
rightrev:
if steering > 127 and throttle < 127 then
throttle = 127 - throttle
lmotor = steering - throttle
if lmotor > 127 then
lmotor = lmotor - 127
low lmode
else
high lmode
lmotor = 127 - lmotor
end if
rmotor = steering - 127 + throttle max 127
high rmode
goto sendpwm
end if
leftrev:
if steering < 127 and throttle < 127 then
throttle = 127 - throttle
steering = 127 - steering
lmotor = steering + throttle max 127
rmotor = steering - throttle
rmotor = 127 - rmotor
if rmotor > 127 then
high rmode
rmotor = rmotor - 127
else
low rmode
rmotor = 127 - rmotor
end if
high lmode
goto sendpwm
end if
sendpwm:
pwmout c.1, 31, lmotor
pwmout c.2, 31, rmotor
goto main
Logged
momomo68
Jr. Member
Posts: 10
Helpful? 0
Re: Joystick control mixing for control of 2 DC motors
«
Reply #5 on:
February 05, 2011, 10:13:58 AM »
Would anything like this be useful?
http://www.robotmarketplace.com/products/RL-IMX1.html
http://www.robotmarketplace.com/products/0-SABER2X5-RC.html
Logged
BANE
Supreme Robot
Posts: 639
Helpful? 4
E=roboticsC^2
Re: Joystick control mixing for control of 2 DC motors
«
Reply #6 on:
February 05, 2011, 10:24:55 AM »
make sure you include some deadzone. If it is a cheap controller or the PS2 controller you might need as much as +/-10 for deadzone. At least thats what i found to be working
Logged
Print
Society of Robots - Robot Forum
»
Software
»
Software
»
Joystick control mixing for control of 2 DC motors
Get Your Ad Here
data_list