Hard Reset Problem (Very hard reset)
Chris The Carpenter
Posts: 18
I would like to pre-thank you guys, I have lurked for quite a while and asked my very first question just a week or so ago. I found friendly people and good answers and I appreciate that. I am running into a weird issue and I hope the same will happen with this problem.
I am running a Gadget Gangster USB prop board on Walter, my robot. Walter is about as big as a dog, weighs about 80 lbs and is super awesome. The major parts (that would have any bearing to this conversation) are the main board, a Arduino-based motor driver board speaking i2c, a second arduino that simply fires off my (4) sonars and sends the data to the prop (UART serial), a thumb-drive mp3 player (speaking serial) and a i2c servo driver board. The 5V regulator (on the prop board itself) has been jumped (per manufacturer's instructions) and 5v power is supplied by an external 5v 3A regulator. Everything else --main drive and servos have their own volt regulators. Juice comes from a big ol' 12V SLA battery. There is more --blinkM's etc. but nothing else worth mentioning.
I am having problems with the chip/board doing it's own "hard reset". This is a new problem, and did not exist in the past using the same hardware and similar code. When I say "hard reset" I mean that the main 5V power supply is being pulled low. I even caught it on a scope. This is a picture of the reset. When this was taken, I had the probe on the main 5V supply (from the 5v regulator and the same supply that feeds everything 5v) and the ground.
Attachment not found.
You can see that "something" is yanking my power down to nothing. It is the same swoop down to low then a square corner and it shoots back to high. The O-scope says that every reset is exactly the same length give or take a few uS. If you have turned the board on for the first time, the reset happens after about 4 minutes. If you let it run from there, the resets come more frequently --sometimes every 15 or 20 seconds. They resets seem to also happen more when more cogs are running. Removing the WiiCamera object and code seems to help but I can't confirm that removing it fixes my problem. I would have thought this was an "overflow" or a "null-style" problem (it feels like that kinda problem), but I don't like the looks of the scope trace --This is not just some kinda internal reset from code that blew-up, something is pulling down hard.
A click to the .spin file is just below.
[PHP]
(Don't click the big button when you get there--it is an ad)
Look for "Navigation 20 --Reset Problem"
Code is Here
I thank you all in advance for your time.
I am running a Gadget Gangster USB prop board on Walter, my robot. Walter is about as big as a dog, weighs about 80 lbs and is super awesome. The major parts (that would have any bearing to this conversation) are the main board, a Arduino-based motor driver board speaking i2c, a second arduino that simply fires off my (4) sonars and sends the data to the prop (UART serial), a thumb-drive mp3 player (speaking serial) and a i2c servo driver board. The 5V regulator (on the prop board itself) has been jumped (per manufacturer's instructions) and 5v power is supplied by an external 5v 3A regulator. Everything else --main drive and servos have their own volt regulators. Juice comes from a big ol' 12V SLA battery. There is more --blinkM's etc. but nothing else worth mentioning.
I am having problems with the chip/board doing it's own "hard reset". This is a new problem, and did not exist in the past using the same hardware and similar code. When I say "hard reset" I mean that the main 5V power supply is being pulled low. I even caught it on a scope. This is a picture of the reset. When this was taken, I had the probe on the main 5V supply (from the 5v regulator and the same supply that feeds everything 5v) and the ground.
Attachment not found.
You can see that "something" is yanking my power down to nothing. It is the same swoop down to low then a square corner and it shoots back to high. The O-scope says that every reset is exactly the same length give or take a few uS. If you have turned the board on for the first time, the reset happens after about 4 minutes. If you let it run from there, the resets come more frequently --sometimes every 15 or 20 seconds. They resets seem to also happen more when more cogs are running. Removing the WiiCamera object and code seems to help but I can't confirm that removing it fixes my problem. I would have thought this was an "overflow" or a "null-style" problem (it feels like that kinda problem), but I don't like the looks of the scope trace --This is not just some kinda internal reset from code that blew-up, something is pulling down hard.
A click to the .spin file is just below.
[PHP]
CON _clkmode =xtal1 + pll16x _xinfreq =5_000_000 TO_IN =73_746 'Conversion needed for SRF-05's FWTC =6 'forward way too close FD =18 'standard fwd danger FTC90 =14 'too close to do a 90 slide turn DT =28 'done turning (90 off of sonar) WTT =30 'Want to start turning WSD =14 'Wall side danger CT =2 'Center Threashold STTW =12 'stop turning this way ST =18 'Something there side OFF =100 'motors off SpeedUp =0 'horrible work-around for dying battery --gotta finish calibration thing sclpin =23 'sda = scl+1 clockpin =25 'This is the WiiCamera Stuff resetpin =26 OBJ i2cMotors : "i2cObjectarduino" 'i2c lines for the motor driver i2cObject : "i2cObjectBlinkm" 'all servos, I/O expander, i2cObject2 : "i2cObjectBlinkm" 'BlinkM;s text : "ORE_TV_Text_009" 'I guess we are going with Game Boy Text Encoder : "Quadrature Encoder" Mp3 : "Simple_Serial" Arduino : "Simple_Serial" Numbers : "Numbers" wii : "wiicamera" VAR long Pos[3] 'this is for the encoders byte tbuf[20] 'this is for fsrw SD card ??? I think... byte range[5] 'this is for the sonar byte FLspeed,FRspeed,BLspeed,BRspeed 'FwdLeft, FwdRight, BackLeft BackRight byte FLoff,FRoff,BLoff,BRoff 'These are offsets or "overshoot" numbers when using the encoders to turn and stop byte TXmode,DriveMode,TurnMode,OverRideTurn,TurnRequested byte Rxleft,Rxright,buttons 'these are X-bee numbers coming in byte ServoRequested[11] byte ServoCurrent[11] byte ServoStatic[4] long Seconds byte blinkM byte mp3str[4] byte mp3str2[5] byte mp3str3[10] byte PlayNow long Stack[600] byte BeaconFound,BeaconFollow,GoHome,goingup,PlayingQuirk long Width,Height,WiiCenterX,WiiCenterY long wiix[5] long wiiy[5] long wiisize long out_data[36] byte ArduinoData[5] PUB init | i text.start(12) waitcnt(clkfreq*5 + cnt) 'this is warm-up time for the mp3 player 'wii.Start (sclpin,clockpin,resetpin) 'fire up the wii camera 'wii.initcam(3,@level2) i2cObject.Init(29,28,true) 'Servo driver, Compass, etc i2cObject.Start i2cObject2.Init(9,8,true) 'blinkM's --Gotta desolder pull-ups so these will play nice with the other i2c stuff --get your pins back i2cObject2.Start i2cObject2.blinkroutine(10,3) i:=1 Repeat 10 ServoCurrent[i]:=125 'Pre-load all the servo arrays with "centered" ServoRequested[i]:=125 i++ i2cObject.head(125,125,125) 'Center all the servos i2cObject.tophat(125) i2cObject.sonarservos(125,125) i2cObject.laser(125,125) i2cObject.camera(125,125) Encoder.Stop Encoder.Start(4, 2, 0, @Pos) 'Clear and fire up encoders Mp3.init(10,11,9600) 'mp3 serial Arduino.init(27,22,9600) 'arduino (sensors) serial Mp3.str(string("E")) 'are you there? echo Mp3.tx(13) waitcnt(clkfreq + cnt) Mp3.str(string("IPA")) 'this is "commands in ASCII", I think Mp3.tx(13) waitcnt(clkfreq/2 + cnt) Mp3.str(string("SCS")) 'shortened command set Mp3.tx(13) waitcnt(clkfreq*2 + cnt) FLspeed:=151 'finish the calibration routine stuff and fix this FRspeed:=160 'this "slow down as the battery dies" is getting old. BLspeed:=52 BRspeed:=44 FLoff:=12 FRoff:=3 BLoff:=13 BRoff:=4 DriveMode:=0 'main drive is off BlinkM:=10 'this is the regular loop with all colors Overrideturn:=0 'clear override BeaconFound:=0 'number of points of IR light found BeaconFollow:=0 '1= wiicamera servo will scan (x only) for a beacon -when found, locks on. TurnRequested:=0 'used with docking, "beacon follow" and "IR follow-the-leader" 'COGS So Far 'Main loop 'Servos and "seconds" counter 'Encoders 'TV 'Drive 'Wiimote 'Arduino --this is the arduino doing the sonar, not the motordriver arduino cognew(Servos,@stack) 'to try to fix the hard-reset problem, I have tried removing some and all of these cognew(ArduinoListen,@stack[100]) 'it does not seem to matter what is running cognew(Drive,@stack[200]) Main PUB Main | x,stoppos,remheadsec,remquirksec,firsttime DriveMode:=0 '0=Off 1=Reg Auto 2=IR Follow the Leader with no sensors 3=R/C OverRideTurn:=0 TurnRequested:=0 BeaconFollow:=0 GoHome:=0 Playmp3(64) ' "Hello, I am Walter" waitcnt(clkfreq*3 + cnt) Playmp3(58) ' "Autonomous Mode" RemHeadSec:=seconds ' timer for head moves RemQuirkSec:=seconds ' timer for all personallity events repeat Display(2) if gohome<>1 'If we are not in "follow the beacon" or "docking" mode if seconds=>RemHeadSec+2 StaticHead(x) 'x is "randomized" each loop RemHeadsec:=seconds 'reset the timer if seconds=>RemQuirksec+60 and PlayingQuirk==0 ' "personallity" quirk is just docking for now StaticHead(1) ' center head PlayingQuirk:=1 ' set flag Firsttime:=0 ' clear "do it once" flag gohome:=1 ' set "request for docking" flag BeaconFollow:=1 ' request wiicamera scanning and lock-on routine BlinkM:=14 'red ' eyes to red(s) if gohome==1 ServoRequested[1]:=ServoCurrent[6] 'Head rotate now follows wiicamera rotate --so he looks at the beacon CheckForBeacon 'Duh, its the check-for-beacon routine! if beaconfound>0 'If we have found the beacon if FirstTime==0 'if we just found it FirstTime:=1 ' set "we did it already" flag DriveMode:=0 ' kill drive and stop waitcnt(clkfreq + cnt) PlayMp3(79) ' "beacon detected" waitcnt(clkfreq*2 + cnt) PlayMp3(30) ' "Starting docking routine" waitcnt(clkfreq*2 + cnt) DriveMode:=1 ' Fire up drive again if wiisize<3 DriveMode:=1 'as long as we keep seeing the beam --drive in that direction case ServoCurrent[6] 'angle of the wiicamera servo tells us which way to steer 1..52 : TurnRequested :=11 'slight left 53..105 : TurnRequested :=12 'hard left 106..145: TurnRequested :=0 'fwd 146..198: TurnRequested :=13 'hard right 199..255: TurnRequested :=14 'slight right if wiisize==3 'if the blob size is the same as threashold (we are given distance from target) OverRideTurn:=9 DriveMode:=0 'kill motors BlinkM:=13 'blue 'blue eyes waitcnt(clkfreq/4 + cnt) PlayMp3(61) 'I am docked waitcnt(clkfreq*4 + cnt) PlayMp3(29) ' "I am leaving the dock" waitcnt(clkfreq*2 + cnt) OverRideTurn:=0 'clear everything GoHome:=0 Beaconfollow:=0 TurnRequested:=0 DriveMode:=1 'start drive back up PlayingQuirk:=0 'clear the personallity flag RemQuirkSec:=seconds 'restart the personallity timer x++ if x==25 'this is "random" generator --used to select "random" headmoves during auto mode x:=1 PUB Drive | stoppos i2cMotors.init(21,20,true) 'Main Drive --This is i2c to the arduino slave on the motor driver board i2cMotors.Start repeat if DriveMode==0 'this is main drive on/off motormath(OFF,OFF) if DriveMode==1 'this is main drive on/off and "modes" R/C etc. turnmode:=TurnRequested 'start with a turn request --if we don't do a sensor-turn, it will be executed. if range[1]<FWTC or range[2]<FWTC 'if either fwd is way too close this is WTC routine motormath(OFF,OFF) stoppos:=-60 waitcnt(clkfreq*2 + cnt) Encoder.Stop 'clear encoders Encoder.Start(4, 2, 0, @Pos) 'start encoders repeat until Pos[0]=<stoppos 'backup 6 inches off of left wheel motormath(BLspeed,BRspeed) waitcnt(clkfreq/1000*5 + cnt) ' a little hiccup to keep from fire-hosing my motor driver with data motormath(OFF,OFF) waitcnt(clkfreq + cnt) Encoder.Stop 'clear the encoders Encoder.Start(4, 2, 0, @Pos) stoppos:=35 If range[3]>range[4] repeat until Pos[1]=>stoppos 'spin to the left away from "way too close" off of encoders motormath(BLspeed,FRspeed) waitcnt(clkfreq/1000*5 + cnt) else repeat until Pos[0]=<stoppos 'spin to the right away from "way too close" off of encoders motormath(FLspeed,BRspeed) waitcnt(clkfreq/1000*5 + cnt) motormath(OFF,OFF) waitcnt(clkfreq*2 + cnt) Encoder.Stop 'we're done --restart the encoders --back to the main routine Encoder.Start(4, 2, 0, @Pos) turnmode:=0 if range[3]<WSD 'Wall side danger turnmode:=3 'wall slide to the right if range[4]<WSD 'Wall side danger turnmode:=4 'wall slide to the left if range[1]<WTT and range[2]<WTT 'both forward sonars see something coming up if range[3]>Range[4] and Range[3]>ST 'if left is more open and it is farther than "something there" then turn that way turnmode:=1 else If Range[4]>ST turnmode:=2 'or turn the other way if range[1]<FD turnmode:=5 'one fwd sonar < forward danger if range[2]<FD turnmode:=6 'one fwd sonar < forward danger if turnmode==1 or turnmode==6 if range[2]<FTC90 turnmode:=7 'slide to left is now a spin --we got too close if turnmode==2 or turnmode==5 if range[1]<FTC90 turnmode:=8 'slide right is now a spin --we got too close if overrideturn>0 turnmode:=overrideturn 'screw the sonar, the main loop knows better --override turn and do what I say --then clear it overrideturn:=0 case turnmode 0: motormath(FLspeed,FRspeed) 'Forward 1: repeat motormath(OFF,FRspeed) 'slide to left if range[2]<FTC90 quit if range[2]>DT and range[1]>DT quit if range[1]<FWTC or range[2]<FWTC quit 2: repeat motormath(FLspeed,OFF) 'slide to right if range[1]<FTC90 quit if range[1]>DT and range[2]>DT quit if range[1]<FWTC or range[2]<FWTC quit 3: motormath(FLspeed,FRspeed-20) '1/2 power wall slide to right 4: motormath(FLspeed-15,FRspeed) '1/2 power wall slide to left 5: repeat motormath(FLspeed,OFF) 'slide around corner 90 right if range[1]<FTC90 quit if range[1]>DT quit if range[1]<FWTC or range[2]<FWTC quit 6: repeat motormath(OFF,FRspeed) 'slide around corner 90 left if range[2]<FTC90 quit if range[2]>DT quit if range[1]<FWTC or range[2]<FWTC quit 7: repeat motormath(BLspeed,FRspeed) 'left spin if range[2]>DT and range[1]>DT quit if range[1]<FWTC or range[2]<FWTC quit 8: repeat motormath(FLspeed,BRspeed) 'right spin if range[2]>DT and range[1]>DT quit if range[1]<FWTC or range[2]<FWTC quit 9: motormath(OFF,OFF) 'this is allstop because of WTC ***Remember to deal with this in main loop 10: motormath(OFF,OFF) 'get around to making this a ramped stop 11: motormath(FLspeed-20,FRspeed) 'Hard left wii IR 12: motormath(FLspeed-10,FRspeed)'Soft Left Wii IR 13: motormath(FLspeed,FRspeed-10) 'Soft Right Wii IR 14: motormath(FLspeed,FRspeed-20) 'Hard right wii IR 15: 'fwd off encoders 16: 'rev off encoders 17: 'encoder spin left 18: 'encoder spin right PUB CheckForBeacon | requesttemp,requesttemp2 wii.getblobs (@out_data) wiix[1]:=wii.getx(@out_data,3,0) wiiy[1]:=wii.gety(@out_data,3,0) wiisize:=wii.getsize(@out_data,3,0) wiix[2]:=wii.getx(@out_data,3,1) wiiy[2]:=wii.gety(@out_data,3,1) wiix[3]:=wii.getx(@out_data,3,2) wiiy[3]:=wii.gety(@out_data,3,2) wiix[4]:=wii.getx(@out_data,3,3) wiiy[4]:=wii.gety(@out_data,3,3) beaconfound:=0 if wiix[1]<>1023 beaconfound:=1 if wiix[1]<>1023 and wiix[2]<>1023 beaconfound:=2 if wiix[1]<>1023 and wiix[2]<>1023 and wiix[3]<>1023 beaconfound:=3 if wiix[1]<>1023 and wiix[2]<>1023 and wiix[3]<>1023 and wiix[4]<>1023 beaconfound:=4 if beaconfollow==1 case beaconfound 0: if goingup==1 Servocurrent[6]:=Servocurrent[6]+2 if goingup==0 Servocurrent[6]:=Servocurrent[6]-2 if Servocurrent[6]>245 goingup:=0 if Servocurrent[6]<10 goingup:=1 ServoCurrent[7]:=100 Width:=0 1: Width:=0 if Wiix[1]<400 requesttemp:=Servocurrent[6]+20 requesttemp:=requesttemp<#250 #>1 ServoCurrent[6]:=requesttemp if Wiix[1]>600 requesttemp:=Servocurrent[6]-20 requesttemp:=requesttemp<#250 #>1 ServoCurrent[6]:=requesttemp if WiiY[1]<300 requesttemp2:=Servocurrent[7]+10 requesttemp2:=requesttemp2<#250 #>1 ServoCurrent[7]:=requesttemp2 if WiiY[1]>700 requesttemp2:=Servocurrent[7]-10 requesttemp2:=requesttemp2<#250 #>1 ServoCurrent[7]:=requesttemp2 2: Width:=||(wiix[2]-wiix[1]) WiiCenterY:=(wiiy[1]+wiiy[2])/2 if wiix[1]<wiix[2] WiicenterX:=Wiix[1]+(width/2) else WiicenterX:=Wiix[2]+(width/2) if BeaconFollow:=1 if WiicenterX<400 requesttemp:=Servocurrent[6]+20 requesttemp:=requesttemp<#250 #>1 ServoCurrent[6]:=requesttemp if WiicenterX>600 requesttemp:=Servocurrent[6]-20 requesttemp:=requesttemp<#250 #>1 ServoCurrent[6]:=requesttemp if WiiCenterY<300 requesttemp2:=Servocurrent[7]+10 requesttemp2:=requesttemp2<#250 #>1 ServoCurrent[7]:=requesttemp2 if WiiCenterY>700 requesttemp2:=Servocurrent[7]-10 requesttemp2:=requesttemp2<#250 #>1 ServoCurrent[7]:=requesttemp2 else ServoRequested[6]:=125 ServoRequested[7]:=100 Width:=0 PUB Display(Data) | temp1,temp2,temp3,temp4,temp5,temp6,temp7,temp8,c,d,e c:=$07 'white d:=$78 'blue e:=$78 'blue case Data 1: text.cls drawbox(0,0,20,24,d,d,d) 'main border drawbox(1,1,18,3,d,d,d) 'top title box text.str(2,2,string(" Stand By ")) text.updatescreen 2: ''this is auto temp3:=20 temp1:=range[1] temp1:=temp1<#30 temp1:=temp1#>1 temp1:=temp1/2 temp4:=20 temp2:=range[2] temp2:=temp2<#30 temp2:=temp2#>1 temp2:=temp2/2 temp6:=10 temp5:=range[4]-4 temp5:=temp5<#15 temp5:=temp5#>1 temp5:=temp5/3 #>1 temp8:=9 temp7:=range[3] temp7:=temp7<#15 temp7:=temp7#>1 temp7:=temp7/3 #>1 text.cls drawbox(0,0,20,24,d,d,d) 'main border drawbox(1,4,3,19,d,d,d) 'fwd sonar L drawbox(16,4,3,19,d,d,d) 'fwd sonar R drawbox(4,20,12,3,d,d,d) 'side sonar drawbox(1,1,18,3,d,d,d) 'top title box repeat temp1 text.PokeChar(2,temp3,c,c,c,$0F) temp3-- repeat temp2 text.PokeChar(17,temp4,c,c,c,$0F) temp4-- repeat temp5 text.PokeChar(temp6,21,c,c,c,$0F) temp6++ repeat temp7 text.PokeChar(temp8,21,c,c,c,$0F) temp8-- text.str(2,2,string("Autonomous Mode")) text.str(4,5,string("In/Sec")) text.dec(11,5,9) 'place keepre text.str(4,7,string("LWheel")) text.dec(11,7,Pos[0]) text.str(4,9,string("RWheel")) text.dec(11,9,Pos[1]) text.str(4,11,string("LSpeed")) text.dec(11,11,FLspeed) 'this is a place keeper text.str(4,13,string("RSpeed")) text.dec(11,13,FRspeed) text.str(4,15,string("T.Mode")) text.dec(11,15,turnmode) text.str(4,17,string("Second")) 'this is a place keeper text.dec(11,17,seconds) text.updatescreen 3: text.cls drawbox(0,0,20,24,d,d,d) 'main border drawbox(1,1,18,3,d,d,d) 'top title box text.str(2,2,string(" X-Bee Watching ")) text.str(4,7,string("Left")) text.dec(12,7,Rxleft) text.str(4,9,string("Right")) text.dec(12,9,Rxright) text.str(4,15,string("Buttons")) text.dec(12,15,buttons) text.str(4,17,string("Seconds")) text.dec(12,17,Seconds) text.updatescreen text.updatescreen 4: 'this is mp3 playback text.cls drawbox(0,0,20,24,d,d,d) 'main border drawbox(1,1,18,3,d,d,d) 'top title box text.str(2,2,string(" Mp3 Player ")) text.str(5,8,string("Playing Track")) text.str(5,10,string(" Place Keeper ")) text.UpdateScreen 5: text.cls drawbox(0,0,20,24,d,d,d) 'main border drawbox(1,1,18,3,d,d,d) 'top title box text.str(2,2,string("Wii Camera Watch")) text.str(3,6,string("WiiX")) text.dec(13,6,wiix[1]) text.str(3,8,string("WiiY")) text.dec(13,8,wiiy[1]) text.str(3,10,string("WiiX2")) text.dec(13,10,wiix[2]) text.str(3,12,string("WiiY2")) text.dec(13,12,wiiy[2]) text.str(3,14,string("Size")) text.dec(13,14,WiiSize) text.str(3,16,string("Beacons")) text.dec(13,16,beaconfound) text.str(3,18,string("Seconds")) text.dec(13,18,seconds) text.UpdateScreen 6: text.updatescreen temp3:=20 temp1:=range[1] temp1:=temp1<#30 temp1:=temp1#>1 temp1:=temp1/2 temp4:=20 temp2:=range[2] temp2:=temp2<#30 temp2:=temp2#>1 temp2:=temp2/2 temp6:=10 temp5:=range[4]-4 temp5:=temp5<#15 temp5:=temp5#>1 temp5:=temp5/3 #>1 temp8:=9 temp7:=range[3] temp7:=temp7<#15 temp7:=temp7#>1 temp7:=temp7/3 #>1 text.cls drawbox(0,0,20,24,d,d,d) 'main border drawbox(1,4,3,19,d,d,d) 'fwd sonar L drawbox(16,4,3,19,d,d,d) 'fwd sonar R drawbox(4,20,12,3,d,d,d) 'side sonar drawbox(1,1,18,3,d,d,d) 'top title box repeat temp1 text.PokeChar(2,temp3,c,c,c,$0F) temp3-- repeat temp2 text.PokeChar(17,temp4,c,c,c,$0F) temp4-- repeat temp5 text.PokeChar(temp6,21,c,c,c,$0F) temp6++ repeat temp7 text.PokeChar(temp8,21,c,c,c,$0F) temp8-- text.str(2,2,string("Auto/Wii Mode")) if beaconfound<2 text.str(4,5,string("TargetX")) text.dec(12,5,Wiix[1]) text.str(4,7,string("TargetY")) text.dec(12,7,WiiY[1]) if beaconfound=>2 text.str(4,5,string("TargetX")) text.dec(12,5,WiiCenterX) text.str(4,7,string("TargetY")) text.dec(12,7,WiiCenterY) text.str(4,9,string("Size")) text.dec(12,9,WiiSize) text.str(4,11,string("Beacons")) text.dec(12,11,BeaconFound) 'this is a place keeper text.str(4,13,string("Request")) text.dec(12,13,TurnRequested) text.str(4,15,string("T.Mode")) 'this is a place keeper text.dec(12,15,TurnMode) text.str(4,17,string("Seconds")) 'this is a place keeper text.dec(12,17,Seconds) text.updatescreen 7: text.cls drawbox(0,0,20,24,d,d,d) 'main border drawbox(1,1,18,3,d,d,d) 'top title box text.str(2,2,string(" Arduino Watch")) text.str(3,6,string("One")) text.dec(13,6,Range[1]) text.str(3,8,string("Two")) text.dec(13,8,Range[2]) text.str(3,10,string("Three")) text.dec(13,10,Range[3]) text.str(3,12,string("Four")) text.dec(13,12,Range[4]) text.str(3,16,string("Seconds")) text.dec(13,16,seconds) text.updatescreen PUB drawbox (x1,y1,w,h,c,d,e) | i w-- h-- text.PokeChar(x1,y1,c,d,e,$10) 'upper left text.PokeChar(x1+w,y1,c,d,e,$12) 'upper right text.PokeChar(x1,y1+h,c,d,e,$13) 'lower left text.PokeChar(x1+w,y1+h,c,d,e,$15) 'lower right i:=x1+1 repeat w-1 if i>x1 and i<x1+w text.PokeChar(i,y1,c,d,e,$11) 'Hort. text.PokeChar(i,y1+h,c,d,e,$11) 'Hort. i++ i:=y1+1 repeat h-1 if i>y1 and i<i+h text.PokeChar(x1,i,c,d,e,$16) 'vert text.PokeChar(x1+w,i,c,d,e,$16) 'vert i++ PUB Servos | i,RemTime 'this is all servos, time and 29/28 i2c RemTime := ( clkfreq / 1000 ) * 1000 + cnt Repeat if (RemTime - cnt) < 0 'this is my poor-man's "second" timer --not very accurate but fine for timing "personallity" changes seconds++ RemTime := ( clkfreq / 1000 ) * 1000 + cnt 'leave in /1000 vs. *1000 thing to be able to adjust i:=1 Repeat 10 if i<>6 and i<>7 if ServoRequested[i]>ServoCurrent[i] ServoCurrent[i]++ ServoCurrent[i]:=ServoCurrent[i]<#ServoRequested[i] if ServoRequested[i]<ServoCurrent[i] ServoCurrent[i]-- ServoCurrent[i]:=ServoCurrent[i]#>ServoRequested[i] i++ ServosOut PUB motormath (rcleft,rcright) | sendl,sendr,lmode,rmode ' this simply translates numbers so they will talk to my main loop, my RC transmitter and my motordriver case rcleft 0 : sendl := 0 lmode := 1 98..102 : sendl := 0 lmode := 2 103..200 : sendl := (rcleft-103)+speedup 'convert and fwd lmode := 2 1..97 : sendl := (97-rcleft)+speedup 'convert and add reverse lmode := 0 255 : sendl := 0 lmode := 1 case rcright 0 : sendr := 0 rmode := 1 98..102 : sendr := 0 rmode := 2 103..200 : sendr := (rcright-103)+speedup 'convert and fwd rmode := 2 1..97 : sendr := (97-rcright)+speedup'convert and add reverse rmode := 0 255 : sendr := 0 rmode := 1 i2cMotors.sendmotors(lmode,sendl,rmode,sendr) PUB ArduinoListen | firstbyte,Arduinoecho 'this is an arduino slave that takes care of all my sonar and spits out serial data repeat firstbyte := Arduino.rx if firstbyte==254 Range[2]:= Arduino.rx Range[1]:= Arduino.rx Range[3]:= Arduino.rx Range[4]:= Arduino.rx Arduinoecho:=Arduino.rx 'I have no idea what this extra byte is PUB Playmp3 (playit) | x ' this takes a track number, stringifies it, builds it up with the rest of what we need for the "command" and sends it off to ' the mp3 player x:=Numbers.ToStr(playit,%1010) SetString(@mp3str, (x)) SetString( @mp3str2, String(".mp3")) AddString ( @mp3str3,@mp3str,@mp3str2) ' Mp3.tx(29) 'this is the play command Mp3.str(@mp3str3) 'what track to play Mp3.tx(13) 'end send PUB statichead (Index) 'this is a list of head positions for the 3 servos that move the head ServoRequested[1] := lookup(Index:125,125,125,125,125,190,255,90,10,190,255,90,10,190,255,90,10,190,255,90,10,190,255,90,10) ServoRequested[2] := lookup(Index:125,95,10,190,250,125,125,125,125,95,95,95,95,10,10,10,10,190,190,190,190,250,250,250,250) ServoRequested[3] := lookup(Index:125,160,250,65,10,125,125,125,125,160,160,160,160,250,250,250,250,65,65,65,65,10,10,10,10) PRI AddString( dstStrPtr, srcStrPtr1, srcStrPtr2 ) | len len := StrSize(srcStrPtr1) ByteMove(dstStrPtr, srcStrPtr1, len) ByteMove(dstStrPtr += len, srcStrPtr2, StrSize(srcStrPtr2)) '+1 for zero termination PRI SetString( dstStrPtr, srcStrPtr ) ByteMove(dstStrPtr, srcStrPtr, StrSize(srcStrPtr)) '+1 for zero termination PRI ServosOut 'the main servos routine calls on this --I don't know why I don't just add it to the servos routine --Hmmm.... i2cObject.start i2cObject.writeLocation($C2,10,ServoCurrent[1], 8, 8) 'head rotate i2cObject.writeLocation($C2,11,ServoCurrent[2], 8, 8) 'left tilt i2cObject.writeLocation($C2,12,ServoCurrent[3], 8, 8) 'right tilt i2cObject.writeLocation($C2,3,ServoCurrent[4], 8, 8) 'laser rot i2cObject.writeLocation($C2,4,ServoCurrent[5], 8, 8) 'laser tilt i2cObject.writeLocation($C2,20,ServoCurrent[6], 8, 8) 'camera rot i2cObject.writeLocation($C2,19,ServoCurrent[7], 8, 8) 'camera tilt i2cObject.writeLocation($C2,13,ServoCurrent[8], 8, 8) 'Tophat i2cObject.writeLocation($C2,1,ServoCurrent[9], 8, 8) 'Lsonar i2cObject.writeLocation($C2,2,ServoCurrent[10], 8, 8) 'Rsonar i2cObject.stop DAT ''Bunch of Smile that makes the WiiCamera Go custom_settings byte $00 byte $00 byte $00 byte $00 byte $00 byte $00 byte $90 ' Max blob size byte $00 byte $41 ' Gain byte $40 ' Gain limit byte $03 ' Min blob size ' Some settings used by wii and suggested by others, from http://wiibrew.org/wiki/Wiimote Marcan byte $00,$00,$00,$00,$00,$00,$90,$00,$C0,$40,$00 ' Suggested by Marcan Cliff byte $02,$00,$00,$71,$01,$00,$AA,$00,$64,$63,$03 ' Suggested by Cliff inio byte $00,$00,$00,$00,$00,$00,$90,$00,$41,$40,$00 ' Suggested by inio level1 byte $02,$00,$00,$71,$01,$00,$64,$00,$FE,$FD,$05 ' Wii level 1 level2 byte $02,$00,$00,$71,$01,$00,$96,$00,$B4,$B3,$04 ' Wii level 2 level3 byte $02,$00,$00,$71,$01,$00,$AA,$00,$64,$63,$03 ' Wii level 3 (as per Cliff) level4 byte $02,$00,$00,$71,$01,$00,$C8,$00,$36,$35,$03 ' Wii level 4 level5 byte $07,$00,$00,$71,$01,$00,$72,$00,$20,$1F,$03 ' Wii level 5Here is the code I am running. I did a tidy-up and a bunch of comments.
(Don't click the big button when you get there--it is an ad)
Look for "Navigation 20 --Reset Problem"
Code is Here
I thank you all in advance for your time.