Shop OBEX P1 Docs P2 Docs Learn Events
Emic2 problem need solution — Parallax Forums

Emic2 problem need solution

crazyrobotgirlcrazyrobotgirl Posts: 32
edited 2014-03-31 12:40 in Propeller 1
[code]{{Motor driver for H Bridge driven motors; for instance L298N based driver circuits, based on code by Jev Kuznetsov and the code from AN001 - propeller counters
┌────────────────────────────────────────────┐
│ PWMMotor Driver 0.8 Test Code │
│ Author: Rick Price (rprice@price-mail.com) │
│ Copyright (c) <2009> <Rick Price │
│ See end of file for terms of use. │
└────────────────────────────────────────────┘
date : 11 May 2009
usage
OBJ
pwm : PWMMotorDriver
....
pwm.Start(outputEnablePin,driveForwardPin,driveForwardInversePin,Frequency) ' Start PWM on cog with a base frequency of *frequency*
pwm.SetDuty( duty) ' set duty in % -100 goes full backward, 0 brakes, 100 goes full forward
pwm.Halt ' Brake motor
pwm.Stop ' Brake motor for 1s and then stop cog
}}
' This is example code
CON _clkmode = xtal1 + pll16x
_xinfreq = 5_000_000 ' CHECK THIS!!!
max_duty_forward = 100
max_duty_backward = -100
stopped = 0
enablePin = 16
forwardPin = 17
forwardInversePin = 18
EMIC_TX = 23 ' Serial output (connects to Emic 2 SIN)
EMIC_RX = 22 ' Serial input (connects to Emic 2 SOUT)



VAR long parameter

OBJ
pwm1 : "PWMMotorDriver"
pst : "Parallax Serial Terminal"
serial : "FullDuplexSerial" ' Full Duplex Serial
PUB main
' Set-up serial port for communication with the Emic 2
serial.Start(EMIC_RX, EMIC_TX, %0000, 9_600) ' Start serial port, normal mode, 9600bps
serial.TX(pst#NL) ' Send a CR in case the system is already up
repeat until serial.RxCheck == ":" ' When the Emic 2 has initialized and is ready, it will send a single ':' character, so wait here until we receive
waitcnt(clkfreq >> 1 + cnt) 'Waits 1 second
serial.Str(String("N1", pst#NL)) ' Voice style
serial.Str(String("db18", pst#NL)) ' Volume
serial.Str(String("W295", pst#NL)) ' Speed
serial.Str(String("l0", pst#NL)) ' Language
serial.STR(String("P2", pst#NL)) ' Parses
repeat until serial.RxCheck == ":" ' Wait here until the Emic 2 responds with a ":" indicating it's ready to accept the next command
waitcnt(clkfreq / 100 + cnt) ' Delay 10mS
serial.RxFlush ' Flush the receive buffer serial.RxFlush ' Flush the receive buffer
serial.TX("S")
go
PUB go | x
pwm1.start(enablePin,forwardPin,forwardInversePin,15625) ' start at 10khz
pst.start(115200)
repeat
repeat x from stopped to max_duty_forward
setDutyAndWait(x)
repeat x from max_duty_forward to stopped
setDutyAndWait(x)
waitcnt(clkfreq*1+cnt)
repeat x from stopped to max_duty_backward
setDutyAndWait(x)
repeat x from max_duty_backward to stopped
setDutyAndWait(x)
PUB setDutyAndWait(duty)
pwm1.SetDuty(duty)
dira[14]:=1
if duty > 0
serial.Str(@TextString)
if duty < 0
serial.Str(@TextSome)
waitcnt(clkfreq/4+cnt)
DAT
TextString byte "Moving forward.", 0
TextSome byte "Moving Backwards.",0
[code]

Comments

  • crazyrobotgirlcrazyrobotgirl Posts: 32
    edited 2014-03-30 18:01
    okay can someone please help me out. Im trying to make my Emic talk when my motor is moving forward and when it goes in reverse
  • Duane DegnDuane Degn Posts: 10,588
    edited 2014-03-30 19:07
    Hi Crazy,

    You forgot the slash in the end code tag. In your first post.

    [c0de]
    code here
    [/c0de]

    Except use the letter "o" instead of a zero in "code".

    If no one beats me to it, I'll take a look at your code tomorrow. Too busy right.

    It's good to see you back with your robots.
  • crazyrobotgirlcrazyrobotgirl Posts: 32
    edited 2014-03-30 20:23
    Thank you so very much. I was able to turn on and off an LED when the motor went in different directions. But getting the Emic to do it was an all day deal.
  • Duane DegnDuane Degn Posts: 10,588
    edited 2014-03-30 21:27
    Have you tested the Emic2 on its own?

    How often do you want the Emic2 to speak?

    Don't you need a "S" before you send each string of text?

    Try changing your strings in the DAT section to:
    DAT
    TextString    byte "SMoving forward.", 13, 0
    TextSome      byte "SMoving Backwards.",13, 0
    

    Do the motors turn on?
  • ElectronsRfunElectronsRfun Posts: 5
    edited 2014-03-31 00:37
    Hi,

    noticed in your code these items seem to be in the wrong place. They should be cut and pasted in below your wait 1 second command
    serial.RxFlush ' Flush the receive buffer serial.RxFlush ' Flush the receive buffer
                 serial.TX("S")
    

    Here is some Emic2 code I am working myself. The code does work but fair warning I'm new to programming.
    PUB Emic_main
    
      Emic2.Start(EMIC_RX, EMIC_TX, %0000, 9_600)
      Emic2.TX(13)                                     
      repeat until Emic2.RxCheck == ":"                   
         
      pause(100)                          
      Emic2.RxFlush
      Emic2.Str(String("N8",13))
      Emic2.Str(String("V18",13))
       
      
     Repeat
     
        CASE value
    
    
          %0000_0000 : ' value == %0000_0000   '(bitwise: (value &= 0))
    
    
            next       ' don't need next but left it here anyway.
             
             
          %0000_0001 : ' value == %0000_0001   '(bitwise: (value &= 1))
    
    
             IF  !%0000_0001 
               Emic2.Str(String("X",13))   
               repeat until Emic2.RxCheck == ":"
          
             Emic2.TX("S")                                 
             Emic2.Str(@LisaString0)                               
             Emic2.TX(13)
             repeat until Emic2.RxCheck == ":"                    
              
            
          %0000_0010 : 'value == %0000_0010    '(bitwise: (value &= 2))
    
    
             IF  !%0000_0010 
               Emic2.Str(String("X",13))   
               repeat until Emic2.RxCheck == ":"
                 
             Emic2.TX("S")                                 
             Emic2.Str(@LisaString1)                             
             Emic2.TX(13)
             repeat until Emic2.RxCheck == ":"                    
            
             
        
          %0000_0100 : 'value == %0000_0100      '(bitwise: value &= 4)
    
    
             IF !%0000_0100
               Emic2.Str(String("X",13))   
               repeat until Emic2.RxCheck == ":"
          
             Emic2.TX("S")                                 
             Emic2.Str(@LisaString2)                             
             Emic2.TX(13)
             repeat until Emic2.RxCheck == ":"                    
               
             
          %0000_1000 : 'value == %0000_1000      '(bitwise: value &= 8)
    
    
             IF !%0000_1000
               Emic2.Str(String("X",13))   
               repeat until Emic2.RxCheck == ":"
          
             Emic2.TX("S")                                 
             Emic2.Str(@LisaString3)                             
             Emic2.TX(13)
             repeat until Emic2.RxCheck == ":"                    
               
             
          %0001_0000 : 'value == %0001_0000      '(bitwise: value &= 16)
    
    
             IF !%0001_0000
               Emic2.Str(String("X",13))   
               repeat until Emic2.RxCheck == ":"
          
             Emic2.TX("S")                                 
             Emic2.Str(@LisaString4)                             
             Emic2.TX(13)
             repeat until Emic2.RxCheck == ":"                    
              
    
    
          %0010_0000: 'value == %0010_0000      '(bitwise: value &= 32)
    
    
             IF !%0010_0000
               Emic2.Str(String("X",13))   
               repeat until Emic2.RxCheck == ":"
          
             Emic2.TX("S")                                 
             Emic2.Str(@LisaString5)                             
             Emic2.TX(13)
             repeat until Emic2.RxCheck == ":"                    
              
    
    
          %0100_0000 : 'value == %0100_0000      '(bitwise: value &= 64)
    
    
             IF !%0100_0000
               Emic2.Str(String("X",13))   
               repeat until Emic2.RxCheck == ":"
          
             Emic2.TX("S")                                 
             Emic2.Str(@LisaString6)                             
             Emic2.TX(13)
             repeat until Emic2.RxCheck == ":"                    
              
    
    
          %1000_0000: 'value == %1000_0000      '(bitwise: value &= 128)
    
    
             IF !%1000_0000
               Emic2.Str(String("X",13))   
               repeat until Emic2.RxCheck == ":"
          
             Emic2.TX("S")                                 
             Emic2.Str(@LisaString7)                             
             Emic2.TX(13)
             repeat until Emic2.RxCheck == ":"                    
              
               
    
    
    DAT
    'InitHeader    byte "Emic 2 Text-to-Speech Module Demonstration", pst#NL, pst#NL, 0
    'TextString    byte "Hello. My name is the Emic 2 Text-to-Speech module. I would like to sing you a song.", 0
    LisaString0   byte "The sensor is out of Alignment. Please check sensor Alignment", 0
    LisaString1   byte "My husbands name is jayson .", 0
    LisaString2   byte "Jayson. I need your help right now. I have an Emergency. Please Help me now", 0
    LisaString3   byte "I want to watch music videos on U tube now", 0
    LisaString4   byte "when you get a free minute can you please come and help me", 0
    LisaString5   byte "I want to get into my chair and go do something please", 0
    LisaString6   byte "I have the matrix grid talking now",0
    LisaString7   byte "now I can start building and puting together the talking matrix grid",0
    
  • crazyrobotgirlcrazyrobotgirl Posts: 32
    edited 2014-03-31 07:35
    All works great! I just needed to change the Dat section.
    I only need it to say the commands once while the motors are moving in there proper direction. But that's something I can figure out on my own. Thank you for the reply Duane. I purchased the Easyvr say it module last week, and hopefully it should be in today. Have you had a chance to check it out?
  • Duane DegnDuane Degn Posts: 10,588
    edited 2014-03-31 11:53
    Good to hear the Emic2 is working. It's a fun gadget.
    I purchased the Easyvr say it module last week, and hopefully it should be in today. Have you had a chance to check it out?

    The EasyVR is also fun. Here's a thread discussing it.

    The thing to remember about the EasyVR is it doesn't make decisions for you. It's kind of like having voice activated touch screen. You have to decide what buttons to display. Lets say you can display buttons to control the TV or to control the sound system but not at the same time. You would need to decide when to display one set of buttons and not the other. These buttons correspond to the EasyVR's wordsets. You need to decide which wordset you want active.

    With a touch screen you have to assign actions to button selections. You also need to assign actions to words the EasyVR will hear. You can kind of think of the EasyVR as a voice activated menu selection device. It can tell you which word was spoken but you need to program the actions to perform when these words are heard (recognized).
  • crazyrobotgirlcrazyrobotgirl Posts: 32
    edited 2014-03-31 12:40
    Thanks again. I'll keep you posted on progress.
Sign In or Register to comment.