Shop OBEX P1 Docs P2 Docs Learn Events
Encoder programming — Parallax Forums

Encoder programming

prab'zprab'z Posts: 4
edited 2009-02-21 17:29 in Robotics
Hi,

I am facing problem in programming my parallax encoder using BS2P..it supposed to count the ticks for every motor step moving forward and display at the screen..I manage to get the display for the encoder reading when I rotate the wheel..but I couldn't get the result when adding the motor turns to the programming..I need your help to 'repair' my coding..i have attached my coding..

P/S:

I need the two motors to rotate and at the same time, encoder detect the holes and display the results at screen..


thank you.

Regards,
Prabz

Comments

  • GWJaxGWJax Posts: 267
    edited 2009-02-20 01:12
    OK I can help you but in your forward command you are using the AUXIO set for the upper pins on the BS2p40 chip. What are you driving with these codes? If your trying to drive servos then this will not work and from the looks of it your sending Clockwise and counter clockwise at the same time. If your using an Hbridge then this code will not drive your motors.

    Also if you want to drive the motors at somewhat the same time then you need to setup a logic flowchart to help you better understand what your code should do.

    Once you have the answers to this I'll remake your program to run the way you want it and document is well so you know what is happening and why.

    Jax

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    If a robot has a screw then it must be romoved and hacked into..
  • prab'zprab'z Posts: 4
    edited 2009-02-20 04:26
    Hi Jax,
    Thank you for your willingness to help me with the coding. For your information regarding my project, I am doing a mobile platform with two DC geared motors controlled by 2 H bridge motor drivers.

    First I will tell you about my ports.
    P10 - Left Encoder
    P11 - Right Encoder
    P5·· - Left motor CW pin
    P6·· - Left motor CCW pin
    P7·· - Left motor PWM pin
    P1·· - Right motor CW pin
    P2·· - Right motor CCW pin
    P3·· - Right motor PWM pin

    P10 and P11 is connected to MAINIO port, P1-3 and P5-7 is connected to AUXIO port

    I manage to program the motors to rotate using the coding in forward subroutine in seperate page. I also manage to program the encoder to count and display the number of ticks count at the display in separate page. But I am having problem in combining both.

    My desired program should initially send the encoder pulse and detect the reading. The purpose of this check is to calibrate the encoder to get 0 values at both encoders (0 when no hole detected and 1 if hole detected). If one of the encoder couldn't get value 0, the respective wheel have to turn until value 0 is achieved. Then, the motor will move forward for 1 step and check the encoder reading again. If the reading has increase in one of the encoders, the respective encoder count has to be increased or decreased (increased for moving forward, decreased for moving backward). I am using differential drive method on the wheels.

    I hope you can understand the flow of the programming. If you need any other information, kindly revert to me back in this forum. I have attached the coding with comments below:

    Thank you.

    Regards,
    Prab'z
  • GWJaxGWJax Posts: 267
    edited 2009-02-21 04:17
    Prab'z,

    What type of an Hbridge are you using? Is it a home made one or the HB-25 motor controller?

    if it's a home made one then the PWM pin 3 and 7 should be stated as enable for that part of the HBridge. is this correct if not and it's an HB-25 then your code is wrong as this unit uses the same commands as a servo. Get back to me on this as soon as you can so I can complete the code.

    Thanks ,

    Jax

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    If a robot has a screw then it must be romoved and hacked into..
  • prab'zprab'z Posts: 4
    edited 2009-02-21 04:58
    Hi Jax,

    ··· I have purchased the motor driver from Cytron Technologies. I have attached the user guide for the driver.
    ·· The PWM pins have to be high whenever the motor operates and has to be low whenever we stop the motor. I have tested the motor with that·coding and it's works.From my experiment on the motor driver, it has to be high to enable the motor to rotate.

    Please let me know if you need any other information

    P/S: For your information, the transmitter and receiver of the encoder is in the same port

    Thank you.
    Regards,
    Prab'z
  • GWJaxGWJax Posts: 267
    edited 2009-02-21 14:11
    Prab'z,

    OK it is a standard HBridge running at 10A max current, so the PWM is the Enable line, but they just renamed it to PWM so you know that the with out this control the HBridge will not turn on plus so that you can turn it on and off at 10Khz like a PWM circuit. you can also use this pin for ramping up and down the motors speed. With out knowing the diameter of the wheels and the spacing between the encoder disk I can not truly give you an accurate way to make turns because there is alot of calculus math involved when doing turns but I will get you started in keeping it going straight.

    Jax

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    If a robot has a screw then it must be romoved and hacked into..
  • GWJaxGWJax Posts: 267
    edited 2009-02-21 14:45
    OK now that I have a fresh mind this morning and started to re-program your code I realized what had happen in your code. Every time you sent a command to the forward: subroutine you set your pins to AUXIO and never set them back to MAINIO, I can't believe I missed that in the first place. Just make the following change to you code.

    forward:

    AUXIO
    HIGH 5 'CW Run
    LOW 1 'CW Run
    LOW 6 'CCW Dir
    HIGH 2 'CCW Dir
    HIGH 7
    HIGH 3
    PAUSE 20
    LOW 5 'CW Run
    LOW 1 'CW Run
    LOW 6 'CCW Dir
    LOW 2 'CCW Dir
    LOW 7
    LOW 3

    MAINIO ' Rest to Main lower pins

    RETURN

    Sorry for over looking this. Hope you can get it from here.

    Jax

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    If a robot has a screw then it must be romoved and hacked into..
  • prab'zprab'z Posts: 4
    edited 2009-02-21 17:29
    Thanks for the correction..I was not aware of the MAINIO in the first place..the motor is working now..but still i couldn't get the encoder reading..
    For your information, I am using 4 inches wheel..my encoder disk has 4 holes..when the encoder detects the hole, it will turn 1..so, the encoder reading for a full turn of 1 revolution is 011011011011..
    For the encoder calibration, both encoders have to sense 0..if the encoder couldn't detect 0, the respective wheel have to turn until it gets 0..
    And I need your help in doing the coding for control the increase and decrease of each encoder reading..if the wheel moving forward, the value of respective encoder has to be increased and the wheel is moving backward, the value of respective encoder has to be decreased..

    Thank you for your help so far..God bless..
    Regards,
    Prab'z
Sign In or Register to comment.