Award
Congratulations Rich, for answering the question and has received an EZ-Credit award! Share what you have learned and create a tutorial to help others by clicking here.

Adc To Move Jaw New Software

Assistance Requested

Help merne with their question and receive $10 of EZ-Credit to get more robots and parts from our store. The following information was provided about their previous efforts searching tutorials for a resolution.

merne claims to have checked these sources:
 
#11

hi rich. I updated the software and I used your commands I need to tweak it a little and it seems to work. not quite as good as I'd like i need to figure that out. I did try PC servo sound but when you talk the mouth moves. so I am using your script now but like I said I need to tweak it. I may have more questions down the road but thank you both very much.
Mike

#12

To be honest, when I read the code I didn't expect it to be how you wanted it. The principals of the code should remain though (i.e. the loop label and goto, the ADC part etc.). It's probably the actual movement that you aren't satisfied with but that's simply a case of adding in more steps in the code, possibly adding in more conditions for the If...

I wont re-write the code as I don't know the specifics and I'd like for you to try yourself, it'll be more rewarding. But if you do need more help just shout, that's what I'm here for Smile

#13

Hi Rich,

You're right about more rewarding. However, I've been working on the jaw sync for 8 hrs and it makes my head hurt. I just don't understand programming and the logic. Do you mind giving me more examples please? If you need more info please let me know.
Thank you!

#14

It would be great if I could get the jaw sync like the inmoov robot jaw does.

#15

Hi again.

Here is what I have so far.
:loop
adc_wait(adc0, higher, 0)
servo(d4,45)
sleep(50)
release(d4)
if (getadc(adc0) < 1)
servo(d4,80)
endif
goto(loop)

It works some what, but it moves when there is no sound out of the speaker

#16

Sorry I posted before I was finished. The d4, 45 opens the jaw and the d4, 80 closes the jaw.

#17

When the sound is playing does the ADC value vary with the volume? I assume so however I'd like to know for sure as it could make the scripting quite different.

One method would be to write a script that just loops around the movement of the jaw, moving the servo from position 45 to 80 to 45 to 80 etc.

Then have another script which checks the ADC value with either an If(GetADC(ADC0) > 1) or with an ADC_Wait command. Once the ADC value change is detected then use a ControlCommand to start the movement script. When the ADC value is 0 (or below a small tolerance) use the ControlCommand to stop the movement script.

You may also be able to use the Auto Position control and set up a few different frames and actions which can be started and stopped with ControlCommand.

So have something like these;

Movement Script

Code:

:loop
Servo(D4, 45)
Sleep(200)
Servo(D4,80)
Sleep(200)
Goto(loop)



Detection Script

Code:

:loop
# Wait for sound to be detected
ADC_Wait(ADC0, higher, 3)
# Start the movement script
ControlCommand("Movement Script", ScriptStart)

# Wait for sound to stop
ADC_Wait(ADC0, lower, 3)
# Stop the movement script
ControlCommand("Movement Script", ScriptStop)
# Close the mouth
Servo(D4,80)

# Loop back
Goto(loop)



If your ADC value varies with volume you could have a bunch of IFs in the movement script which check the ADC value and move the servo to a different position. You could use the random number command to adjust the sleeps for random gaps to make it look a bit more realistic. There are a number of things you could do to improve the motion which I'll cover if you need it once you get the actual detection and starting of the movement sorted.

Note: it's 3:40am here, I haven't been to sleep in almost 24 hours now, I apologies if my code has any errors but if it does just check the EZ-Script manual and correct them Smile

#18

Hi Rich. Yes, when the sound plays the ADC value does vary with the volume. When the sound does play through the speakers the ADC value goes up and down. What I am seeing is the ADC value sometimes goes to zero, even when there is sound playing through the speakers. I am not sure why? Maybe it's my wiring or it's my PC AMP to my speakers and the ADC0 port, I really don't know for sure.

I tried both of your scripts you wrote and I ended up using the movement script because of the ADC value not going above zero, even when the speakers have sound going through them. I tried many combinations last night and ended up just using the movement script(s). It still misses jaw/mouth movement sometimes but it's better then it was before. See Below,,,
:loop
If (GetADC(ADC0) > 0)
Servo(D4, 45)
Sleep(100)
EndIF

If (GetADC(ADC0) > 0)
Servo(D4, 55)
Sleep(60)
EndIF

If (GetADC(ADC0) > 0)
Servo(D4, 45)
Sleep(50)
EndIF

If (GetADC(ADC0) > 0)
Servo(D4, 55)
Sleep(50)
Servo(D4,80)
Sleep(10)
EndIF

I know it's very simple for you because you know programming so well. I want to thank you for the guidance and examples you write very fast. Even when getting no sleep in 24 hours. Wow!

I am hoping the new ez v4 board will be better for the jaw/mouth movement. Because it has the built in speaker and digital, I'm not really sure on that. I will see if I can figure out how to send you a video of the mouth moving, I am not sure when that will happen. I was having trouble setting up a Youtube account yesterday and will try later.

Again many thanks for always helping and getting back very fast!

One more thing, I will try and figure out how to use the Auto Position script when I have a little more time.
PS I like your tattoo. Sincerely, Mike

#19

I am here to help Smile And thanks, it's my latest ink, very pleased with it so kinda having it on display everywhere Smile



If sometimes the ADC is 0 for a short moment you could always write in some delay and checking to avoid that.

Code:


ADC_Wait(ADC0, equals, 0)
Sleep(500)
If(GetADC(ADC0) > 0)
# Ignore the blip in quiteness
Goto(mainloop)
EndIf



This isn't a complete script but rather an idea and a guide to how you can add in a sleep after the ADC_Wait then check the ADC value and either accept it as quiet or decline it and say "no, keep going, it was just a blip".


Or you could use the ADC value to set the Servo position. You would need to do a few calculations but it may work. The louder the sound or the higher the ADC value the more the mouth opens. While it's not an exact simulation of a mouth the effects can be pretty good.

First you would need to work out how many servo positions you have between closed (80) and open (45)

80-45 = 35

Then see how high the ADC value goes with the loudest of sounds. Do this by watching the ADC value (use an ADC control temporarily). Let's say for example it hits 125 at it's loudest.

So we have 35 positions for 125 ADC values. 125/35 = 3.5. At this point I would round that down to 3, which would mean the mouth would vary in position between ADC values of 0 to 105, anything above 105 would be fully open and the positions would be in steps of an ADC change of 3. (Hopefully this is all making sense).

So next we make the script to convert the ADC value to servo position. It's pretty a simple script.

Code:


# Get the ADC value and assign it to a variable
$volume = GetADC(ADC0)

# Ensure the ADC value doesn't cause errors by being above the max mark (105)
IF($volume > 105)
$volume = 105
EndIf

# Convert the ADC value to a servo position
$servo_position = $volume/3
# Make it an integer
$servo_position = Round($servo_position, 0)
# Convert the ADC to position by subtracting the position from the closed position (80)
$servo_position = 80 - $servo_position



A lot of that code can be combined in to a single line however, to make it easier to follow I did each step bit by bit. Extra lines of code, while unnecessary, sometimes make it easier to follow scripts.

Now we have our servo position, using either code above (I would use the first since it's easier to follow and change for future) we just need to move the servo to the correct position;

Code:

Servo(D4, $servo_position)



Then piece it all together, add in any sleeps to delay certain parts as necessary and you should have something like this;

Code:


:loop
# Get the ADC value and assign it to a variable
$volume = GetADC(ADC0)

# Ensure the ADC value doesn't cause errors by being above the max mark (105)
IF($volume > 105)
$volume = 105
EndIf

# Convert the ADC value to a servo position
$servo_position = $volume/3
# Make it an integer
$servo_position = Round($servo_position, 0)
# Convert the ADC to position by subtracting the position from the closed position (80)
$servo_position = 80 - $servo_position

# Move the servo
Servo(D4, $servo_position)

# Delay as necessary (if necessary)
Sleep(100)

# Loop back to the start
Goto(loop)




Now, what should happen is the ADC port will be read and the volume of the audio will be saved to the variable $volume.

The volume is then checked to make sure it isn't over 105, if it is it could move the servo to a position that shouldn't be available. So we check it with an IF and if the conditions are met we over ride the value to the maximum.

Then we take the volume and convert it to the correct position first by dividing it by 3 (as previously calculated), making it a round number (as you can't have decimals in servo positions) and then subtracting it from the closed position.

Then we tell the servo to move to that position.

A slight delay, if required, to stop the mouth going too mad.

The we go back and do it all over again.


I haven't checked the script. I haven't really checked if I worked it all out correctly so check it out on something which doesn't matter if the position goes to the wrong place (or above/below the max/min points) before you use it on the jaw.

#20

Hi Rich. Now I am really confused, maybe I need to start over with Baby steps?
I need to step back to the really basics. FYI, The volume voice/jaw sync is working but could work better. I will work on that later.

I have a new question, what is the difference of the Modified Servo versus Modified Servo Movement Panel. I have 2 modified motors with gears and a worm shaft that moves. Using the arrow buttons and the stop buttons, I can move it back and forth.

I want to move both motors independently with a script I have tried the Movement script with the Servo Movement control panel but it moves both motors. Is the a way to move them independently?

Please be very simple, as my brain does not seem to process this stuff very well. I dp understand most on the logic you have sent, I am just don't know all the commands? Not sure!

Also maybe I should start a new thread?

V/R
Mike