How to control my Servo Motor with the IR SENSOR in a BS2
Andres
Posts: 10
This program is from parallax and calculates the binary number, Decimal Value and Voltage from a sensor IR.
[noparse][[/noparse] Title ]
' Basic Analog and Digital - PL3_1R0.bs2
' Program Listing 3.1 Revision 0.
' {$STAMP BS2}
' {$PBASIC 2.5}
'
[noparse][[/noparse] Declarations ]
adcBits VAR Byte
v VAR Byte
r VAR Byte
v2 VAR Byte
v3 VAR Byte
'
[noparse][[/noparse] Initialization ]
CS PIN 0
CLK PIN 1
DataOutput PIN 2
DEBUG CLS 'Start display.
'
[noparse][[/noparse] Main Routine ]
DO
GOSUB ADC_Data
GOSUB Calc_Volts
GOSUB Display
LOOP
'
[noparse][[/noparse] Subroutines ]
ADC_Data:
LOW CLK
LOW CS
PULSOUT CLK, 210
SHIFTIN DataOutput,CLK,MSBPOST,[noparse][[/noparse]adcBits\8]
HIGH CS
RETURN
Calc_Volts:
v = 5 * adcBits / 255 '? new line
r = 5 * adcBits // 255 '? new line
v2 = 100 * R / 255 '? new line
v3 = 100 * r // 255 '? new line
v3 = 10 * v3 / 255 '? new line
IF (v3 >= 5) THEN v2 = v2 + 1 '? new line
IF (v2 >= 100) THEN '? new line
v = v + 1 '? new line
v2 = 0 '? new line
ENDIF '? new line
RETURN
Display:
DEBUG HOME
DEBUG "8-bit binary value: ", BIN8 adcBits
DEBUG CR, CR, "Decimal value: ", DEC3 adcBits '? new line
DEBUG CR, CR, "DVM Reading: " '? new line
DEBUG DEC1 v, ".", DEC2 v2, " Volts" '? new line
RETURN
My question is how I can scale my output of ADC to the motion continuous Servo Motor in a program.
I was thinking using PWM FUNCTION TO DO IT !!!!!!!!!!!
Also how I can can store those outputs values from my ADC.
Measurement GP2D12 and ADC031 CONVERTOR ( Room light and hand)
Distance Vin Vout Decimal slope (Vout/Vin Current (A )
10 4.9828 5 255 1.003451874 0 0.11
12 4.9828 4.45 227 0.893072168 0 0.11
14 4.9828 3.72 192 0.746568195 0 0.11
16 4.9828 3.27 167 0.656257526 0 0.11
18 4.9828 2.98 152 0.598057317 0 0.11
20 4.9828 2.57 131 0.515774263 0 0.11
22 4.9828 2.31 119 0.463594766 0 0.11
24 4.9828 2.18 111 0.437505017 0 0.11
26 4.9828 1.94 99 0.389339327 0 0.11
28 4.9828 1.88 96 0.377297905 0 0.11
30 4.9828 1.8 86 0.361242675 0 0.11
[noparse][[/noparse] Title ]
' Basic Analog and Digital - PL3_1R0.bs2
' Program Listing 3.1 Revision 0.
' {$STAMP BS2}
' {$PBASIC 2.5}
'
[noparse][[/noparse] Declarations ]
adcBits VAR Byte
v VAR Byte
r VAR Byte
v2 VAR Byte
v3 VAR Byte
'
[noparse][[/noparse] Initialization ]
CS PIN 0
CLK PIN 1
DataOutput PIN 2
DEBUG CLS 'Start display.
'
[noparse][[/noparse] Main Routine ]
DO
GOSUB ADC_Data
GOSUB Calc_Volts
GOSUB Display
LOOP
'
[noparse][[/noparse] Subroutines ]
ADC_Data:
LOW CLK
LOW CS
PULSOUT CLK, 210
SHIFTIN DataOutput,CLK,MSBPOST,[noparse][[/noparse]adcBits\8]
HIGH CS
RETURN
Calc_Volts:
v = 5 * adcBits / 255 '? new line
r = 5 * adcBits // 255 '? new line
v2 = 100 * R / 255 '? new line
v3 = 100 * r // 255 '? new line
v3 = 10 * v3 / 255 '? new line
IF (v3 >= 5) THEN v2 = v2 + 1 '? new line
IF (v2 >= 100) THEN '? new line
v = v + 1 '? new line
v2 = 0 '? new line
ENDIF '? new line
RETURN
Display:
DEBUG HOME
DEBUG "8-bit binary value: ", BIN8 adcBits
DEBUG CR, CR, "Decimal value: ", DEC3 adcBits '? new line
DEBUG CR, CR, "DVM Reading: " '? new line
DEBUG DEC1 v, ".", DEC2 v2, " Volts" '? new line
RETURN
My question is how I can scale my output of ADC to the motion continuous Servo Motor in a program.
I was thinking using PWM FUNCTION TO DO IT !!!!!!!!!!!
Also how I can can store those outputs values from my ADC.
Measurement GP2D12 and ADC031 CONVERTOR ( Room light and hand)
Distance Vin Vout Decimal slope (Vout/Vin Current (A )
10 4.9828 5 255 1.003451874 0 0.11
12 4.9828 4.45 227 0.893072168 0 0.11
14 4.9828 3.72 192 0.746568195 0 0.11
16 4.9828 3.27 167 0.656257526 0 0.11
18 4.9828 2.98 152 0.598057317 0 0.11
20 4.9828 2.57 131 0.515774263 0 0.11
22 4.9828 2.31 119 0.463594766 0 0.11
24 4.9828 2.18 111 0.437505017 0 0.11
26 4.9828 1.94 99 0.389339327 0 0.11
28 4.9828 1.88 96 0.377297905 0 0.11
30 4.9828 1.8 86 0.361242675 0 0.11
Comments
What do you mean by "how I can can store those outputs values from my ADC"? Store what? Store where?
"using PWM FUNCTION TO DO IT !!!". Do what? Have you read the description of the PWM statement? Do you understand how it's used?
Structure:
Sensor is connected to the AD Converter, then the output of AD converter is a binary number. There is where I don't know what to do with these binary numbers that come from the IR Sensor or where to store it. So I can use the Binary Output for the motion of the servo motor.
Scaling meaning depending the movement of the hand there is different values or voltages that the IR SENSOR WILL DETECT.
These are the scaing values
DistancE (cm) Vin Vout Decimal value
10 4.9828 5 255
12 4.9828 4.45 227
14 4.9828 3.72 192
16 4.9828 3.27 167
18 4.9828 2.98 152
20 4.9828 2.57 131
22 4.9828 2.31 119
24 4.9828 2.18 111
26 4.9828 1.94 99
28 4.9828 1.88 96
30 4.9828 1.8 86
If you're using a continuous motion servo, the pulse width translates into direction and speed rather than position. I don't recommend moving the curtain that way since you lose the position feedback. A continuous motion servo has no way to know its position. If you can, use a standard servo.
The "Robotics with the BoeBot" tutorial will show you how to adjust your continuous motion servo so it stops moving when the control pulse width is 1.5ms (1500us or a PULSOUT count of 750). A longer pulse will cause the servo to rotate in one direction and a shorter pulse will cause the servo to rotate in the other direction.