tag:blogger.com,1999:blog-5548766831424877039.post5681885586102533336..comments2024-03-23T02:41:26.627-07:00Comments on Tinkernology: Lego Lip Synching RobotShephttp://www.blogger.com/profile/02066171011377081272noreply@blogger.comBlogger2125tag:blogger.com,1999:blog-5548766831424877039.post-45836009781266699102009-12-28T11:00:04.612-08:002009-12-28T11:00:04.612-08:00The sound sensor picks up the intensity of the sou...The sound sensor picks up the intensity of the sound.<br />Basically, the mouth opens wider for louder sounds and the mouth closes more for softer sounds. If there is no sound, the mouth tries to go closed (zero). If the sound is louder than it was a moment ago, it opens more and vice versa. <br /><br />Here is the RobotC code. It could be improved quite a bit. I thought of some improvements after I posted the video. I hope this helps!<br /><br />#pragma config(Sensor, S1, soundsensor, sensorSoundDB)<br />#pragma config(Motor, motorA, , tmotorNormal, PIDControl, reversed)<br />//*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//<br /><br />task main<br />{<br />int MouthSpeed = 100;<br />int MouthPosition = 0;<br />int OldMouthPosition = 0;<br />int PlayTime = 400;<br /><br />nMotorEncoder[motorA] = 0;<br />wait1Msec(1000);<br />MouthPosition = SensorValue[soundsensor];<br />time100[T1]=0;<br />while(time100[T1] < PlayTime) {<br /> MouthPosition = 2 * SensorValue[soundsensor];<br /> nxtDisplayBigTextLine(0, "MEA: %d", nMotorEncoder[motorA]);<br /> nxtDisplayBigTextLine(2, "MP: %d", MouthPosition);<br /><br /> if (SensorValue[soundsensor] < 15) { //close more<br /> motor(motorA) = -MouthSpeed;<br /> while (nMotorEncoder[motorA] > 15){}<br /> motor(motorA) = 0;<br /> }<br /> else if (MouthPosition > OldMouthPosition + 10) { //open wider<br /> motor(motorA) = MouthSpeed;<br /> while (nMotorEncoder[motorA] < MouthPosition){}<br /> motor(motorA) = 0;<br /> }<br /> else if (MouthPosition < OldMouthPosition - 10) { //close more<br /> motor(motorA) = -MouthSpeed;<br /> while (nMotorEncoder[motorA] > MouthPosition){}<br /> motor(motorA) = 0;<br /> }<br /> else if (MouthPosition == OldMouthPosition) { //stay<br /> motor(motorA) = 0;<br /> }<br /> OldMouthPosition = MouthPosition;<br /><br /> wait1Msec(20);<br /><br /> }<br />motor(motorA) = -50;<br />while (nMotorEncoder[motorA] > 35){}<br />motor(motorA) = 0;<br />}Shephttps://www.blogger.com/profile/02066171011377081272noreply@blogger.comtag:blogger.com,1999:blog-5548766831424877039.post-84654951234316577102009-12-27T21:14:33.091-08:002009-12-27T21:14:33.091-08:00What's the code for this like? Is it just a st...What's the code for this like? Is it just a straight relationship between sensor value and rotational distance, or are there some hard-coded thresholds?<br /><br />I'm considering bringing a variation of this into the office as a gag.Danhttps://www.blogger.com/profile/00868894814276101467noreply@blogger.com