The Elvinator Source Code and Video along with other helpfull code and Video

104 posts / 0 new
Last post
GWJax
GWJax's picture
The Elvinator Source Code and Video along with other helpfull code and Video

This thread is intended for Pbasic Coding using the Parallex Basic stamps on the Elvinator and other helpfull PBasic code. Video will also be added when needed. If you have any PBasic code that you would like to share PLEASE do so as this will help out others in need. Some of the first code has already been posted in another thread and will be reposted in this thread. As changes are made they will reflect in a new post or at least part of the code that has been changed. Use copy and paste functions to import the code into your compiler as you see fit. Enjoy the code and please change it to suit your needs. The Code that I post have no copyrights on them unless otherwise noted. And this code is for NON commercial use and for personial use ONLY! So I hope you enjoy this ever changing thread. GWJax

GWJax
GWJax's picture

This first code is for checking the eye assy in the Elvis Eye Assy. It will allow you to check for Eye side to side, Up Down, Lid right and left up/down and lip up/down movements. Once these checks are made, make sure you write them down and subtract 200 from each one to allow for extra flow during motor off cycles. This data will be used in the next post I make. My numbers may vary from yours so make sure you do this test first so you don't bind up the motors or break a gear in the gearbox's. In the following pic use this a base for all VR connections. One circuit per VR. Use the center wire and the black wire on all VR pinouts. now here is the pic. and then the code.

RCTIMECircuit

' use this program to find the max an min VR setting for the Elvis Eye Assy.
' Follow the schematic and add one circuit per VR that is being checked.
' on each VR plug use the center wire and the black wire for all connections.
' used with a circuit with R = 10 k or 5K pot and C = 1.0 uf Tantalum Capacitor.
' On the capacitor make sure of the poliarity of the cap + side goes to VDD 5V
' Adjust the pot and watch the value shown on the Debug screen change.
' Use this program to make the nessary distance checks for up/down on the eyes and lip
' {$STAMP BS2} 'STAMP directive (specifies a BS2)
' {$PBASIC 2.5}
EyeRT_LT VAR Word 'Word variable to hold result for rt/lt eye.
EYES_U_D VAR Word 'word variable to hold results for eyes up down
EyeLidLF VAR Word ' Word variable to hold results for eye lid left up down
EyeLidRT VAR Word  ' Word variable to hold results for eye lid right up down
LIP_U_D VAR Word ' Word variable to hold results for the lip up down

CheckVRs:
HIGH 0 'Discharge the cap for EyeRT_LT
  PAUSE 1 'for 1 ms.
RCTIME 0, 1, EyeRT_LT 'Measure RC charge time in 1ms for EYE right and left.
  HIGH 1 ' Discarge the cap for EYES_U_D
    PAUSE 1
RCTIME 1, 1, EYES_U_D
  HIGH 2
    PAUSE 1
RCTIME 2, 1, EyeLidLF
  HIGH 3
    PAUSE 1
RCTIME 3, 1, EyeLidRT
  HIGH 4
    PAUSE 1
RCTIME 4, 1, Lip_U_D

' show results on debug screen
DEBUG CLS, "EyeRT_LT = ", DEC EyeRT_LT, CR 'clear screen and Show value on screen then to next line.
DEBUG "EYES_U_D = ", DEC EYES_U_D, CR
DEBUG "EyeLidLF = ", DEC EyeLidLF, CR
DEBUG "EyeLidRT = ", DEC EyeLidRT, CR
DEBUG "LIP_U_D = ", DEC LIP_U_D, CR
LOW 0
LOW 1
LOW 2
LOW 3
LOW 4
GOTO CheckVRs

Enjoy! GWJax

GWJax
GWJax's picture

This next one is to move the eyes right and left, Make sure the vr signal center wire is at pin 7 for this and use your data for the eye left and right movement to make changes to match your data. Look at the notes in the program to determine where you need to change the data. here is the program and the video will follow:

' {$STAMP BS2}
' {$PBASIC 2.5}
' test motor movement and check vr's for proper poition and move eyes rt and lt
Result VAR Word 'Word variable to hold result.
LOW 10 ' set pin 10 low eye right
HIGH 8 ' set pin 8 high  eye left to move motor eye left
LOW 8  ' ser pin 8 low eye left to stop motor eye left

Main:
GOSUB checkeyes
  IF RESULT =1 OR RESULT =0 THEN GOTO BUG ' if vr has no signal stop program
  IF result <= 1100 THEN GOTO EYELEFT ' change left eye min
  IF result >= 2300 THEN GOTO eyeright ' change right eye max
    GOTO eyeright
GOTO MAIN

BUG:
DEBUG "bug found in VR READINGS = ", DEC RESULT,CR ' if signal loss stop routine
STOP

checkeyes:  ' checking the VR location

HIGH 7 'use pin 7 to Discharge the cap circuit
PAUSE 1 'for 1 ms.
RCTIME 7, 1, Result 'Measure RC charge time. convert analog to digital

RETURN

eyeright: ' move right eye to the right
HIGH 10   ' turn motor on

CHECKRT:
DEBUG "eye right mode", DEC result, CR
GOSUB checkeyes
  IF Result < 1100  THEN GOTO LINESLOW 'check to see if it at the lower limits change to min

GOTO CHECKRT

eyeleft: 'move eye to the left

HIGH 8 'turn on motor

CHECKLT:
DEBUG "eyeleft mode", DEC result

GOSUB checkeyes
  IF Result > 2300 THEN GOTO LinesLow ' if over limit turn off motor change to max

GOTO CHECKLT

LinesLow: ' turn off motor
  LOW 8
  LOW 10
  DEBUG "droped lines low" , CR
GOTO main

here is the video:

Enjoy! GWJax

RobosapienV2-4mem8
RobosapienV2-4mem8's picture

Nice, This is an interesting section and wil help most of us contemplating building this mod.

GWJax
GWJax's picture

Great I'm glad you think so. I will have all programs in this thread for the Elvinator and some others that arn't related to the Elvinator also. GWJax

GWJax
GWJax's picture

Please be alert that if you run the eye movement code, the programming cord must be plugged into the computer to work. If you do not want to have the computer plugged in PLEASE make the DEBUG commands as a remark with an ' or delete it from the program prior to downloading to the stamp. This will ensure that your eyes will move. The DEBUG command is for the debug window and if it is there it waits for the RX signal to return from the computer and will halt the program if not connected. Thanks GWJax

GWJax
GWJax's picture

More code and video on the Fadding of the Elvinator eye. The program sets the LED in the eye at a low voltage using the PWM command and will increase the voltage to the max at 5V and then dim out. There are 3 components to this circuit a 4.7uF cap and a 1K resistor and a LED connected to P6 of the basic stamp: the code is as follows:

' {$STAMP BS2}
' {$PBASIC 2.5}
' This program sets the brightness of the eye and fades in and the out
pwmduty VAR Byte
pwmout PIN 6 'LED connected to P6

'init
pwmduty=0 'set duty cycle to 0

runhigh:
DO WHILE pwmduty<255 'keep increasing dutycycle till 255 is reached
  PWM PWMout, pwmduty,19 ' run to increase voltage to LED
    pwmduty=pwmduty+1 'Increase duty cycle by 1
LOOP

runlow:
IF pwmduty>=255 THEN pwmduty=254 'set duty cycle to 254
  DO WHILE pwmduty >=1 'continue to decrease voltage to LED
    PWM pwmout,pwmduty,19 ' run to decrease voltage to LED
      pwmduty=pwmduty-1  'Decrease cycle by 1
  LOOP

GOTO runhigh 'start over

and here is the video:

Enjoy, GWJax 

RobosapienV2-4mem8
RobosapienV2-4mem8's picture

Cool video GW, Thanks for posting it. Man I wish I had you programming skills. I can see I will have to knuckle down when it comes to programming Wall-E, Your help will definately be required. Great work GW.

GWJax
GWJax's picture

The code that I have posted is just for demo purposes, the real code for the Elvinator is still in the works. This demo code gives you a good idea about what is happing behind the seens. When the Elvinator code is posted, I most likely will post it in sections. As of helping you with Wall-E I'll need to get with you soon so you can test your creation before your done with it to at least get the feel of what you want and this will help you out before you make the fibreglass mold for the cover just incase you made a design error and you can fix it first. I't looks like that you have the tracks on and ready for some movements if you have not done this yet. Just let me know in a PM and we'll keep it closed before the big review! Some test code will be posted here so the people will learn how to test diffrent parts of their robot before writing a complete set of codes and finding out that the wheels or sensors need to be modified to work. This is the most important part of programming for robots because taking software to control a mechanical part can be time consumming and if you get the code wrong it may damage the bot or give you undisired results. So document everything you do folks so you can backtrack if need be. Like I said in the promo post thread if ANYONE has code that they would like to share PLEASE do so. This thread is not just about the Elvinator but about programming the Basic Stamp and PBasic Coding. I know some of you are out there has coding experience so come out of your shell and post. We all learn and feed of each other. Thanks for reading. GWJax

GWJax
GWJax's picture

Hey 4mem8 why don't you post your laser pointer tilt-pan routine in here and the video as well along whi any schenatics that you needed if neede at all.

RobosapienV2-4mem8
RobosapienV2-4mem8's picture

That's a great idea GW, Unfortunately like most of my idea's they dont all get finished and this is one of them. I do have some neat code that runs one of my bots, but is not finished and it may be copyright as it uses bluebell designs co-processor code and I may not be able to post it, but it is quite neat in what it does. The co-processor runs the two servos, 1 IRPD ranger and bump sensors, it has facility for another 4 servos and 5 A/D converters for say sharp GP sensor range.

http://www.bluebelldesign.com/ Neat site to look at.

Unfinished coded sensor bot

Bluebells design co-processor board.

If this is inapropiate here it can be deleted. 

GWJax
GWJax's picture

Do you have any code that you changed to your liking or is the code stright from the books. Because if you change the code at least 10-20% its no longer copyrighted. This would be your code not theirs. Just a little FYI, But do give them credit for what is theirs Or send a link to the code section if they have one.GWJax

RobosapienV2-4mem8
RobosapienV2-4mem8's picture

Gw, The code is as is from the cd that came with the co-processor, I'm not clued up enough to alter it or add code that's why it's not finished, It needs code for emic speech, ultra sonic ranger with pan/tilt servos, 3 GP2D12 ir sensors and pir detector.

GWJax
GWJax's picture

the ping ranger finder is easy I post some code to get you started in finding distance with pan and tilt and I'll have to do some research on the sony GP2D12 and 15 sensors, PIR dector is a very one too I have that one so I can do some experiments with if if you want.

GWJax
GWJax's picture

here is a simple Ping mesurment for distance in Inch and cm. Use this program to determaine what distance you would like for the bot to sence and wite down the code to input into your subroutine for checking objects:

' Measure distance with Ping))) sensor and display in both in & cm
' you'll find out that you should get 134 in max and 364 cm max
' use this program to get the maximum didtsnace required you need and write down the numbers
' {$STAMP BS2}
' {$PBASIC 2.5}
' Conversion constants for room temperature measurements.
CmConstant CON 2260
InConstant CON 890
cmDistance VAR Word
inDistance VAR Word
time VAR Word
DO
PULSOUT 15, 5
PULSIN 15, 1, time
cmDistance = cmConstant ** time
inDistance = inConstant ** time
DEBUG HOME, DEC3 cmDistance, " cm"
DEBUG CR, DEC3 inDistance, " in"
PAUSE 100
LOOP

GWJax
GWJax's picture

I will motify two servos and make a routine for tilt and pan with ping installed for 6 inch and closer distance and make the servos move to their new locations. and have it check again. I think I will install it in the Radio Shack spider R/C I have. Hold tight and and I have it ready tomorrow.

RobosapienV2-4mem8
RobosapienV2-4mem8's picture

Nice, Thanks GW, I will put this into my editor. I have BS2P, so I take it it will be ok as you are usuing BS2. It should convert ok if I click on BS2P and save it.

GWJax
GWJax's picture

Ya it should work fine.

Peter Redmer
Peter Redmer's picture

Hey everybody, part 3 of the awesome Elvinator Hack has been posted!!

Read the article here!

Have fun, and thanks for your enthusiasm for this great project!

Pete

GWJax
GWJax's picture

cool thanks Peter.

GWJax
GWJax's picture

4mem8 Here is the diagram for an H-Bridge controller for use in your Wall-E project. This diagram came fron Nuts-N-Volts this will help you in coding better than the HB25 units, You have a little bit more control of what your doing and you don't have to worry about the 2ms and 1.5 ms delay between signals as with the HB25. Make 2 of them for Wall-E on one board:

Stamp Applications no. 23 (January ’97):


Electronic Control for DC Motors

Using Discrete Bridge Circuits

 

GWJax
GWJax's picture

4mem8 here is a simple test program for finding the max and min of your tilt pan unit use this first before the next program I will post with a video showing a random movement of tilt paan functions.

here is the code to use first also use this for each servo, just change out the plug connection:

' {$STAMP BS2}
' {$PBASIC 2.5}
' calibrate - find the center/not moving point of servo

' variables
servo PIN 14
currentdelay  VAR  Word
i             VAR Byte

' initialization/maxline
  LOW servo
  currentdelay = 750

  DO
    DEBUG "current servo delay value = ", DEC currentdelay, CR
    FOR i = 0 TO 100
      PULSOUT servo, currentdelay
      PAUSE 18

   NEXT
    DEBUG "enter in new delay value "
    DEBUGIN DEC currentdelay
    DO WHILE (currentdelay < 10) OR (currentdelay >1400)
      DEBUG "invalid value, must be between 10 and 1,400",CR
      DEBUG "enter in new delay value "
      DEBUGIN DEC currentdelay
    LOOP
  LOOP

GWJax
GWJax's picture

Here is the next program for the random movements. Video first and then the code will follow:

her is the code. Remember the max and min movements are for my servos yours will be diffrent:

' {$STAMP BS2}
' {$PBASIC 2.5}
' random movements for tilt and pan movements

' variables
Tilt               PIN            14   ' set tilt to pin 14
Pan                PIN            13   ' set pan to pin 13
tiltseed           VAR           Word  ' set var seed for tilt
panseed            VAR           Word  ' set var seed for pan
TPseed             VAR           Word  ' set to check for tilt or pan
tpselect           VAR     tpseed.BIT0 ' Bit0 of the random number
tiltdelay          VAR           Word  'tiltdelay
pandelay           VAR           Word  'pandelay
i                  VAR           Byte  'counter
tilttime           VAR           Byte  'tilttime
pantime            VAR           Byte  'pantime

' initialization/maxline
  LOW tilt
  LOW pan
  tilttime = 10
  pantime = 30
  tiltdelay = 450
  pandelay = 700
  tiltseed=460
  panseed=1100
  TPseed=1
 main:
  RANDOM tpseed
  IF tpselect = 0 THEN GOSUB panit 'for tilt or pan direction

  RANDOM tiltseed ' give a random number
  tiltdelay=tiltseed
  DO WHILE (tiltdelay > 450 OR tiltdelay < 101 ) 'check to see if tilt is within specs
  RANDOM tiltseed  ' mixup numbers
  tiltdelay=tiltseed
  LOOP 'continue till values are right for movement
  GOSUB tiltit
  GOTO main ' start all over

tiltIt:

    FOR i = 0 TO tilttime
      PULSOUT tilt, tiltdelay 'send out pulse to servo
      PAUSE 18
    NEXT
    RETURN

PanIt:
RANDOM panseed ' mix random number with seed value
  pandelay=panseed
  DO WHILE (pandelay > 1100 OR pandelay < 101 ) ' wait till within movement specs
    RANDOM panseed ' mix numbers up again
    pandelay=panseed
  LOOP ' loop until numbers are within correct movement range

    FOR i = 0 TO pantime 'Start pan movements
      PULSOUT pan,pandelay
      PAUSE 18
    NEXT
    RETURN

RobosapienV2-4mem8
RobosapienV2-4mem8's picture

Thanks GWjax, great stuff. There is another question for the above code GW, but I will not ask this until I have gone through the above excersises, including building the H-bridge and testing. I will be using a 3,000ma 7.2v battery pack, so this should be ok with the H bridge diagram, any components need changing as the diagram indicates 5v. Do the pull up resistors need to be changed?. Probably not as these are for the cpu signal. Thanks for your time.

GWJax
GWJax's picture

No your ok with the parts listed as described but just incase I will test it out first and make changes if nessary and will post the results or maybe an easier way I'll plug it into the simulator.

Nocturnal
Nocturnal's picture

It should be fine at 7.2v, I'd be more concerned that its only rated to 300ma (at 6v).

GWJax
GWJax's picture

ya I noticed that, but I have no problems yet with over heating. Everything is working fine. I'll let it run over night and see what happens.

GWJax
GWJax's picture

never mind the last post. Break down the voltage to 5V wih a voltage regulator 78L05 this will correct the problem. If you don't want to do this then I'll change the Transistors to a higher value.

GWJax
GWJax's picture

Nocturnal do you know coding? If so why don't you post some here?

Nocturnal
Nocturnal's picture

I doubt the motors in the Elvis Bust pull 300ma, but the motors 4mem8 is using in Wall-E might.

I dont own a basic stamp, hence I dont do PBasic.

GWJax
GWJax's picture

they really do, they pull about 500ma under load and more for the head and neck movements, thats why I'm using the boards already installed in elvis so I don't have to make them.

What programming do you do. I'd like to see some if you would post it here and note it as such. If you program in PIC code that would be great! I do a little in PIC and would like to learn more.

Pages