Emic2 problem need solution
crazyrobotgirl
Posts: 32
[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]
┌────────────────────────────────────────────┐
│ 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
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.
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:
Do the motors turn on?
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
Here is some Emic2 code I am working myself. The code does work but fair warning I'm new to programming.
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?
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).