Hi all !!
Many thanks to westaust55 for helping me many times specially on the I2C part of the coding, also many of you who where very helpful.
As promised here are the latest news:
1-tested the code with the motor Installed
Here are the actions that took Place: when pot 1 (b1) was moved in either direction the motor would turn in that direction and match (b1) travel or distance. Noted if I physically try to move it out of the position once it had reached b1 to either direction it will go back to match b1 position. COOL!!!
When b1 is released, no matter what previous position it was before it will center or follow b1. Great!!!!! it self centers itself !!
2 Errors I noted (glitches)
A-in the code its specified that IF b2 > 40 AND b2 < 215 THEN Check
problem: when b2 has reached end of travel say 40 or 215 and I try to
move it out that position there is no action no matter in what direction
b1 is moved.
B- when b1 is centered, depending if it was on the right or left b1 has a different center position exp:I move joystick to the left ad let the joystick go it moves to the center position even if I try multiple times it goes to the same center position. But if from that center position I move the joystick center position to the right and let it go now it has a different center position. Its shy by maybe 1-2 inches from matching the other.
Here is the code Used:
any help will be Appreciated. Thanks!!!!!!!
Many thanks to westaust55 for helping me many times specially on the I2C part of the coding, also many of you who where very helpful.
As promised here are the latest news:
1-tested the code with the motor Installed
Here are the actions that took Place: when pot 1 (b1) was moved in either direction the motor would turn in that direction and match (b1) travel or distance. Noted if I physically try to move it out of the position once it had reached b1 to either direction it will go back to match b1 position. COOL!!!
When b1 is released, no matter what previous position it was before it will center or follow b1. Great!!!!! it self centers itself !!
2 Errors I noted (glitches)
A-in the code its specified that IF b2 > 40 AND b2 < 215 THEN Check
problem: when b2 has reached end of travel say 40 or 215 and I try to
move it out that position there is no action no matter in what direction
b1 is moved.
B- when b1 is centered, depending if it was on the right or left b1 has a different center position exp:I move joystick to the left ad let the joystick go it moves to the center position even if I try multiple times it goes to the same center position. But if from that center position I move the joystick center position to the right and let it go now it has a different center position. Its shy by maybe 1-2 inches from matching the other.
Here is the code Used:
Code:
'############################################
'Picaxe 28X1
'Using a 10K Potentiometer for Input
'DC Motor 24V and an MD03 as H-bridge
'############################################
'###################
'SETUP
'###################
Symbol Right=1
Symbol Left=2
Symbol M_Stop=0
Symbol Speed_1=100
Symbol Speed_2=200
Symbol Speed_0=0
SYMBOL proximity = b3
SYMBOL tolerance = 5
HI2CSETUP i2cmaster, %10110000, i2cfast, i2cbyte ; %10110000 = $B0 = default MD03 Slave Address
'###################
'MAIN LOOP
'###################
Main:
READADC 0, b1 ' read value on ADC0 into variable b1 from pot on steering wheel = desired position
READADC 1, b2 ' read value on ADC1 into variable b2 from pot = actual position
IF b2 > 40 AND b2 < 215 THEN Check ' Not at either end stop
GOSUB Motor_stop ' end travel left or right so STOP
GOTO Main
Check:
IF b1 > b2 THEN
proximity = b1 - b2
ELSE
proximity = b2 - b1
ENDIF
IF proximity < tolerance THEN
GOSUB Motor_stop ' stop motor as actual position = selected +/- tolerance
ELSEIF b1 > b2 THEN
GOSUB turn_left ' If steering wheel is further left than feedback (b2) then Go Left
ELSEIF B1 < b2 THEN
GOSUB turn_right ' If steering wheel is further right than feedback (b2) thenGo Right
ENDIF
GOTO Main
'###################
'SUBROUTINES
'###################
Turn_right:
HI2COUT [%10110000], 0, (Right)
HI2COUT 2, (Speed_1)
RETURN
Turn_left:
HI2COUT [%10110000], 0, (Left)
HI2COUT 2, (Speed_1)
RETURN
Motor_stop:
HI2COUT [%10110000], 0, (M_Stop)
HI2COUT 2, (Speed_0)
RETURN