Register now to access more content    Login  
Main Menu
Login
Username:

Password:

Remember me



Lost Password?

Register now!


Sensors and Accessories

Rotation Sensor

The Meccanisms Rotation Sensor Kit measures rotation by generating pulses as the shaft being measured rotates.

The kit consists of
- Sensor PCB
- Encoder Disk
- MotorVator Cable

The kit is designed to suit the Meccanisms Geared Motors. In this mode, mount the Sensor PCB onto the Motor Mount Plate using double sided tape (thin stuff, not the foam type).

The Encoder Disk is then pressed onto the motor shaft. Use one or two washers to space the encoder disk close to, but not touching, the sensor PCB. Of course the black and white sensors need to be facing the Sensor PCB.

Connect the cable to one of the Timed Input Ports. Now as the shaft turns, the input port will read either High (1) or Low (0), depending on which colour (black or white) is directly over the sensor.

The best way to read these changes is with an Event Handler.


Declare EventHandler Shaft1Event() 
      
Increment Shaft1_Pulse eveytime we see a change in the input on Timed1Input
                                            ; 
increment the shaft pulse counter
End EventHandler

Now in our code we simply use the value of Shaft1_Pulse to count the rotationof the shaft.

As an example, using the disk in the picture above, we have 15 black and 15 white sectors. Therefore, we will get 30 pulses per revolution, and each pulse represents 360/30 = 12 degrees. So to turn the shaft three revolutions, we would do something like


Declare Byte  Shaft1_Pulse
Declare EventHandler Shaft1Event()
Increment Shaft1_Pulse eveytime we see a change in the input on Timed1Input,
increment the shaft pulse counter
End EventHandler

Begin Program
SetEvent Timed1Event
Shaft1Event
Enable Events

Shaft1_Pulse 
reset the count
SetMotor 1
"F"60 Start the shaft moving

Do
DisplayNumber Shaft1_Pulse
Dont need to do anything here
Until Shaft1_Pulse 
90 because the Shaft1Event will increment Shaft1_Pulse
automatically

SetMotor 1
"F"0

End Program

Now you might like to get a bit fancier to ensure that we stop at the exactly the right spot, by slowing the motor down as we get near the target:


Declare Byte Shaft1_Pulse
Declare Byte Shaft1_Speed
Declare Byte Minimum_Speed 10
Declare Byte Fast 60
Declare Byte Current_Pulse_Count
Declare Byte Decellerate_Delta =5

Declare EventHandler Shaft1Event()
Increment Shaft1_Pulse
End EventHandler

Begin Program
SetEvent Timed1Event
Shaft1Event
Enable Events

Shaft1_Pulse 
0
Shaft1_Speed 
Fast
SetMotor 1
"F"shaft1_Speed Start the shaft moving

Do
DisplayNumber Shaft1_Pulse
Don't need to do anything here
Until Shaft1_Pulse = 70 ; because the Shaft1Event will increment Shaft1_Pulse automatically
Current_Pulse_Count = Shaft1_Pulse ; remember where we are up to
Do
If Current_Pulse_Count <> Shaft1_Pulse Then ; each time we get another pulse
    If Shaft1_Speed > Minimum_Speed Then ; if we'
re still turning faster than minimum speed
        Shaft1_Speed 
Shaft1_Speed Decellerate_Delta slow the motor down a bit
    End 
If
    
SetMotor 1,"F",Shaft1_Speed        ; and change the speed
    Current_Pulse_Count 
Shaft1_Pulse so we dont slow down again Until we see the next pulse
End 
If
Until Shaft1_Pulse 90 ; and sneak up on the full 3 rotations

SetMotor 1
"F"0    stop the motor
End Program

Note that the Rotation Sensor can't tell you in which direction the shaft is turning. In most cases you will know this, because you're controlling the motor!If you really need to know which was a shaft is turning, then you need two sensors on the disk, but set up so that one "lags" the other. See the discussion under "User Input" for how this works using a rotary encoder switch.

Printer Friendly Page Send this Story to a Friend







Copyright © 2003-04 Meccanisms Ltd  |  Powered by XOOPS 2.0 © 2001-2003 The XOOPS Project  |  Site by Steadfast Technology