Shop OBEX P1 Docs P2 Docs Learn Events
Senior Design Project - RC car object detection — Parallax Forums

Senior Design Project - RC car object detection

d(-_-)bd(-_-)b Posts: 3
edited 2009-11-16 03:17 in Learn with BlocklyProp
As the title says my team mates and I have bought a stamp2 microcontroller along with the super carrier board to program it. From the topics I've read so far I'm concerned that we won't be able to use PMW modulation and controlling the duty cycle as a means of motor speed control. The RC car we are using has 2 DC motors one for the front to control the left and right steering of the car and a second that control the forward and backward motion of the car. Since we aren't dealing with servos, will we need to be using HWPM to give us a cleaner duty cycle? We are using two parallax proximity sensors on the front and back as a means of collision detection, and the final goal of the project is to make the car autonomous and parallel park itself. I'm brand new to basic stamp programming and currently working on a sample program which moves the car forward and brings it to a complete stop when it senses an object a foot in front of it. Any references as far as motor control is concerned or any other info would be greatly appreciated.

Comments

  • SRLMSRLM Posts: 5,045
    edited 2009-11-10 02:27
    What is "HWPM"?
  • Mike GreenMike Green Posts: 23,101
    edited 2009-11-10 07:28
    Look at the DC motor controllers that are in the Parallax webstore. Also look at the Wikipedia article on H-Bridges. The Stamps are not really designed for PWM control of DC motors, so you need some kind of external motor driver. If you want to control the motor's speed, you need a PWM-based controller for the H-Bridge which handles On/Off switching and reversing the direction of the motor.
  • d(-_-)bd(-_-)b Posts: 3
    edited 2009-11-10 20:04
    Would this be all that is needed in order to accomplish the speed control obviously with the addition of an H-bridge circuit?

    http://www.parallax.com/Store/Accessories/MotorServoControllers/tabid/160/CategoryID/35/List/0/Level/a/ProductID/67/Default.aspx?SortField=ProductName,ProductName

    Also I'm attempting to modify the sample code provided on the parallax site for the prox sensors using two at once. I keep receiving an error message when I try and check the syntax. It's giving me an Error: 174 - Label is missing ":" where it is highlighting the word Ping in the subroutine Get_Sonar. I'm not certain why I'm getting the error as the subroutine is identical to the sample code which Tokenizes Successfully when checked for syntax. Thanks again for any help.

    '
    [noparse][[/noparse] I/O Definitions ]

    Ping1 PIN 15
    Ping2 PIN 14


    '
    [noparse][[/noparse] Constants ]

    #SELECT $STAMP
    #CASE BS2, BS2E
    Trigger CON 5 ' trigger pulse = 10 uS
    Scale CON $200 ' raw x 2.00 = uS
    #CASE BS2SX, BS2P, BS2PX
    Trigger CON 13
    Scale CON $0CD ' raw x 0.80 = uS
    #CASE BS2PE
    Trigger CON 5
    Scale CON $1E1 ' raw x 1.88 = uS
    #ENDSELECT

    RawToIn CON 889 ' 1 / 73.746 (with **)

    IsHigh CON 1 ' for PULSOUT
    IsLow CON 0


    '
    [noparse][[/noparse] Variables ]

    rawDist VAR Word ' raw measurement
    inches VAR Word


    '
    [noparse][[/noparse] Initialization ]

    Reset:
    DEBUG CLS, ' setup report screen
    "Parallax Ping Sonar ", CR,
    "=====================", CR,
    CR,
    "Time (uS)..... ", CR,
    "Inches........ ", CR


    '
    [noparse][[/noparse] Program Code ]

    Main:
    DO
    GOSUB Get_Sonar ' get sensor value
    inches = rawDist ** RawToIn ' convert to inches

    DEBUG CRSRXY, 1, 3, ' update report screen
    DEC rawDist, CLREOL,
    CRSRXY, 1, 4,
    DEC inches, CLREOL,
    CRSRXY, 2, 3, ' update report screen
    DEC rawDist, CLREOL,
    CRSRXY, 2, 4,
    DEC inches, CLREOL

    PAUSE 100
    LOOP
    END


    '
    [noparse][[/noparse] Subroutines ]

    ' This subroutine triggers the Ping sonar sensor and measures
    ' the echo pulse. The raw value from the sensor is converted to
    ' microseconds based on the Stamp module in use. This value is
    ' divided by two to remove the return trip -- the result value is
    ' the distance from the sensor to the target in microseconds.

    Get_Sonar:
    Ping = IsLow ' make trigger 0-1-0
    PULSOUT Ping, Trigger ' activate sensor
    PULSIN Ping, IsHigh, rawDist ' measure echo pulse
    rawDist = rawDist */ Scale ' convert to uS
    rawDist = rawDist / 2 ' remove return trip
    RETURN
  • Mike GreenMike Green Posts: 23,101
    edited 2009-11-11 00:25
    "Ping" isn't defined anywhere. That's why you're getting the error message.

    You've got two definitions for I/O pins, "Ping1" and "Ping2". Neither one is "Ping".
  • Mike GreenMike Green Posts: 23,101
    edited 2009-11-11 00:28
    You could certainly use the PWMpal to generate the PWM signal for the H-Bridge. You could also use the Pololu dual motor controller if the voltage and current for your motor is compatible with the controller.
  • d(-_-)bd(-_-)b Posts: 3
    edited 2009-11-16 02:03
    Thanks very much for the help. Finally got the code for both sensors to work correctly. Now I need to make the code into an infinite loop and define the motor control outputs. Will definitely try and post a youtube video of the car. As a test run we want the car to move forward until it detects an object a foot away then reverse, no speed control as of yet want to make sure the fundamentals are working first. smile.gif Also wanted to know if the VSS pin on the Basic stamp 2 module is ground for the purposes of putting plus or minus 5 volts to a motor.

    Post Edited (d(-_-)b) : 11/16/2009 2:13:51 AM GMT
  • Mike GreenMike Green Posts: 23,101
    edited 2009-11-16 03:17
    I would be careful in how you connect your grounds to avoid ground loops (search for "wiki ground loop" for details). You really want to connect the grounds together at the power source (like the battery). There would be a ground wire from the motor and a separate ground wire from the Stamp or Stamp board. You would also have separate (+) power leads connected at the battery. This is less important if your motor is small and low current, but that's probably not the case for you.
Sign In or Register to comment.