armored rover

Welcome to my Armored Rover project!

It’s not actually armored yet…and not fully armed even. That’s waiting on either my CNC to be finished or at least my dremel to come back home. Anywho, lets just say this is a work in progress and will be for a while. Its a stock lynxmotion 4wd that I picked up as an autonomous kit, then proceeded add a playstation remote. I added a platform on top, a single pin serial LCD (these things are great, every project should have one) and the fun part: two cannons and a laser sight.

Pictures: (soon!)

Video:

Cannons: These cannons are from Toyseast, cost around $50 for the pair with delivery to Canada. Two aren’t needed of course…but it’s even more awesome that way! There is a bit of a demo in general electronics that goes over how these work, but that uses a rc controlled pulsed relay to control them. Its a lot simpler to just use some transistors, most of us probably have bins of them laying around. Relays could work too. The laser I got on ebay for $5 from China. It’s intended for DJ’s actually, and runs off of 3 to 4.5V. I used the 0.3v drop from a transistor and added an additional diode to drop 0.7V, so it runs comfortably under limits at 4V even. The circuit for all this is attached. I didn’t bother to print a circuit or anything, just used protoboard.

the cannons have 4 wires, an orange and black pair, and a green and black pair. The orange and black pair get wired to the pins 1 and 2. These power the little hobby motors that wind the springs. One of the cannons I had to wire backwards strangely enough. The green and black go from 3 to 4. This is just a standard off the shelf limit switch hidden inside. When the spring is fully forward (just fired) this gets pressed. This is an easy way to stop the cannon after one shot, and keep the springs in a retracted position. I built the circuit with a double set of headers, so I just run the two cannons in parallel. I found one fired slightly faster than the other, so I used the slower cannon’s switch to turn them both off, and just cut the wires on the other. The laser is wired onto the pins below, and a 3 pin header goes out to the bot board to connect the I/O. I also have a 2 pin header to power the circuit.

Code: Again, a work in progress. I particularly like the serial read outs to debug EVERYTHING, my button presses, status bits, motor speeds etc. I’m driving the rover in tank mode, and will be using the L and R buttons to control the cannon aiming once I get some pan and tilts installed. The top L and R will aim up, the top and bottom R to aim right etc, with all 4 firing the cannon. This way you can drive and aim at once without losing any accuracy. I may have a button toggle so that the left joystick steers and right aims, but I tried it and couldn’t get my coordination together :slight_smile: Pretty sad when you can’t drive your own bot!

'---------------------------------------------------------------------
'---------------------------------------------------------------------
'Sparky, the gunbot rover

'June 15th, 2010
'adding in display code, starting laser and gun controls
'need to add in servos for pan and tilt

'june 24th, 2010
'laser is working, code tweaked heavily and debugged
'gun is also firing, on temp control scheme.
'just needs the pan and tilts, and range sensors installed for obstacle detection?
'headlights still on order

'Kevin Cochran, hobby project

'bot board with basic atom pro and playstation 2 remote to drive
'4 wheel rover with laser aiming and airsoft guns
'---------------------------------------------------------------------
'---------------------------------------------------------------------



'pinouts
DAT con P12
CMD con P13
SEL con P14
CLK con P15
     'pin 2 is serial lcd
     'pin 4 is laser
     'pin 5 is gun
     'pin 6 is switch
laser con p4
gun con p5

low laser
low gun

'ps2 controls
index var byte
temp var byte(18)
mode var byte

'joystick positions
rhori var word
rvert var word
lhori var word
lvert var word

'motor speeds
lmotor var sword
rmotor var sword
boost var byte

'button depressing
circlelast var bit
squarelast var bit
trianglelast var bit
xlast var bit

'status bits
laseron var bit
gunswitch var bit
gunswitchlast var bit

'dispays
displaymode var byte
displaybutton var word
displayvalue var word

'---------------------------------------------------------------------

high CLK

test
low SEL
shiftout CMD,CLK,FASTLSBPRE,$1\8,$43\8,$0\8,$1\8,$0\8] ;Config Enable
high SEL

low SEL
shiftout CMD,CLK,FASTLSBPRE,$01\8,$44\8,$00\8,$01\8,$03\8,$00\8,$00\8,$00\8,$00\8] ;Set Mode and Fix(Analog
high SEL

pause 100

low SEL
shiftout CMD,CLK,FASTLSBPRE,$01\8,$4D\8,$00\8,$00\8,$01\8,$ff\8,$ff\8,$ff\8,$ff\8] ;Vibration Enable
high SEL

low SEL
shiftout CMD,CLK,FASTLSBPRE,$01\8,$4F\8,$00\8,$FF\8,$FF\8,$03\8,$00\8,$00\8,$00\8] ;Enable Pressure
high SEL

low SEL
shiftout CMD,CLK,FASTLSBPRE,$01\8,$43\8,$00\8,$00\8,$5A\8,$5A\8,$5A\8,$5A\8,$5A\8] ;Press_trans_start
high SEL

low SEL
shiftout CMD,CLK,FASTLSBPRE,$01\8,$43\8,$00\8,$00\8,$00\8,$00\8,$00\8,$00\8,$00\8] ;Config Exit
high SEL

main
' This section find the mode the PSX controller is in.

low SEL
shiftout CMD,CLK,FASTLSBPRE,$1\8]
shiftin DAT,CLK,FASTLSBPOST,[mode\8]
high SEL

low SEL
' asking data to PS2 controller
shiftout CMD,CLK,FASTLSBPRE,$1\8,$42\8]
' reading data from controller
shiftin DAT,CLK,FASTLSBPOST,[temp(0)\8,temp(1)\8,temp(2)\8,temp(3)\8,temp(4)\8,temp(5)\8,temp(6)\8,temp(7)\8,temp(8)\8, |
temp(9)\8,temp(10)\8,temp(11)\8,temp(12)\8,temp(13)\8,temp(14)\8,temp(15)\8,temp(16)\8,temp(17)\8,temp(18)\8]
high SEL

'---------------------------------------------------------------------

'temp 3-6 are joysticks
'temp 7-10 are d-pad buttons
'11=triangle    12=circle    13=X    14=square
'15=L1          16=r1        17=L2   18=R2         255 is full on, 0 is off

' this section takes the status of circle, if on, double the speed
if (temp(12) >10) and circlelast = 0 then

	if (boost = 1) then
		boost = 2
	elseif (boost = 2 or boost = 0)
		boost = 1
	endif
	
	circlelast = 1
	
elseif temp(12) = 0

	circlelast = 0
	
endif

'---------------------------------------------------------------------

' this section will control servo position using L & R buttons -interrupts?







'---------------------------------------------------------------------
' this section toggles laser using square button
' if button is on (one shot) trigger laser state

if (temp(14) >10) and squarelast = 0 then
	
	if laseron = 1 then
		low laser
		laseron = 0
	else
		high laser
		laseron = 1
	endif
		
	squarelast = 1
		
elseif temp(14) = 0

	squarelast = 0
	
endif

'---------------------------------------------------------------------
' this section fires the gun, using X for now
' if button is on (one shot) trigger laser state

'input switch
;if switch is off and was on last
	'turn off gun
	'switch last is off
'if switch was not off, turn on from last time
'logic all reversed!

gunswitch = in6

if gunswitch = 0 and gunswitchlast = 1 then
	low gun
	gunswitchlast = 0

elseif gunswitch = 1
	gunswitchlast = 1
	
endif


if (temp(13) >10) and xlast = 0 then

	xlast = 1
	high gun

elseif temp(13) = 0
	xlast = 0
endif

'---------------------------------------------------------------------
'prep the inputs to be displayed to screen. this is debugging more than anything

if (temp(11) >10) and trianglelast = 0 then
	trianglelast = 1
	
	
	displaymode = displaymode + 1
	
	
elseif temp(11) = 0
	trianglelast = 0
endif


	
if displaymode = 1 then

	if temp(11)>0 then
	
		displaybutton = "^" 'triangle
		displayvalue = temp(11)
	
	elseif temp(12)>0
	
		displaybutton = "O" 'circle
		displayvalue = temp(12) 
		
	elseif temp(13)>0
	
		displaybutton = "X" 'x
		displayvalue = temp(13)
		
	elseif temp(14)>0
	
		displaybutton = "=" 'Square
		displayvalue = temp(14)
		
	else
		displaybutton = "  " 'blank
		displayvalue = 0
	
	endif
		
	serout 2,i9600,[254]                            		 'send command
   	serout 2,i9600,[128]                            		 'send position to move to
   	serout 2,i9600,"button ", displaybutton, " pressed"]    'write the text

   	serout 2,i9600,[254]
   	serout 2,i9600,[192]
   	serout 2,i9600,"force = ", dec3 displayvalue\3, "/255"]
    	
elseif displaymode = 2
    
   	if boost = 1 then
   		serout 2,i9600,[254]                            		 
   		serout 2,i9600,[128]                            	
   		serout 2,i9600,"Boost Enabled   "] 
   	else
   		serout 2,i9600,[254]                            		 
   		serout 2,i9600,[128]                            	
   		serout 2,i9600,"Boost Disabled  "]
   	endif 

	if laseron = 1 then
   		serout 2,i9600,[254]
   		serout 2,i9600,[192]
   		serout 2,i9600,"Laser Enabled   "]
    		
   	else
   		serout 2,i9600,[254]                            		 
   		serout 2,i9600,[192]                            	
   		serout 2,i9600,"Laser Disabled  "]
   	endif
    		
elseif displaymode = 3
    
   'put something on motor speeds here?
	if lvert < 80 then
		serout 2,i9600,[254]                             'send command
    	serout 2,i9600,[128]                             'send position to move to
   		serout 2,i9600,"l: forward ", dec3 lvert\3]
    elseif lvert > 200
    	serout 2,i9600,[254]                             
    	serout 2,i9600,[128]                             
   		serout 2,i9600,"l: reverse ", dec3 lvert\3]
   	else
    	serout 2,i9600,[254]                             
    	serout 2,i9600,[128]                             
   		serout 2,i9600,"l: stopped ", dec3 lvert\3]
	endif   
    
	if rvert < 80 then
		serout 2,i9600,[254]                             'send command
    	serout 2,i9600,[192]                             'send position to move to
   		serout 2,i9600,"r: forward ", dec3 rvert\3]
    elseif rvert > 200
    	serout 2,i9600,[254]                             
    	serout 2,i9600,[192]                             
   		serout 2,i9600,"r: reverse ", dec3 rvert\3]
   	else
    	serout 2,i9600,[254]                             
    	serout 2,i9600,[192]                             
   		serout 2,i9600,"r: stopped ", dec3 rvert\3]
	endif
	
	else
	
	displaymode = 0

endif

'---------------------------------------------------------------------
' this section does the mixing for throttle steering on a diff steered vehicle.
rhori = (temp(3))
rvert = (temp(4))
lhori = (temp(5))
lvert = (temp(6))



if lvert < 80 then
    lvert = 0
elseif lvert > 200
    lvert = 255  
else
    lvert = 128
endif


if rvert < 80 then
    rvert = 0
elseif rvert > 200
    rvert = 255 
else
    rvert = 128
endif


lmotor = 3000 - ((4 * boost) * (128-lvert))  ;converts 0 to 2000, 128 to 3000, 255 to 4000
rmotor = 3000 - ((4 * boost) * (128-rvert))



pulsout 0, lmotor
pulsout 1, rmotor

'---------------------------------------------------------------------

goto main 

I’m keeping this post for edits, comments etc on this project

and the first of those notes: The bot boards regulator cannot output enough current to drive both motors without occasionally browning out. I’m adding a 7805 of similar and using battery power instead of regulated 5v. The motors could run straight off of the battery power and probably never have a problem. The laser cannot. In fact you will get a faster rate of fire by jumping the voltage up slightly. I may instead just add another diode or two in for the laser and run it higher… I’ll sleep on that one for now

sounds like you are having some fun. and some problems. iv just typed this but this is what id expect it to look like.

[code]IF gunswitch = 0 then
IF(gun) THEN
'Turn off
gun = 0
ELSE
'Turn on

  gun = 1	
ENDIF

ENDIF [/code]

maybe? :wink:

your project sound really cool. any pictures? 8)

I don’t think you can do math and read an input at the same time. Perhaps separate them.

[code]my_variable = in12

if my_variable bla bla bla[/code]

got it! combination of strange logic (the switch is normally 5v, and gets pulled down when activated, but I was referring to off as 1 in my head) and the fact that in this version of the IDE the in6 shows up black as if its an error until you compile it, and it compiles fine. This evening I’ll be changing this into a page of info from the project, some pictures and a video in a few days, when I can borrow a camera.

gunswitch = in6

if gunswitch = 0 and gunswitchlast = 1 then
	low gun
	gunswitchlast = 0

elseif gunswitch = 1
	gunswitchlast = 1
	
endif


if (temp(13) >10) and xlast = 0 then

	xlast = 1
	high gun

elseif temp(13) = 0
	xlast = 0
endif

apparently when you power it up, it automatically fires. Now I have bruise on my ankle bone. Note to self, fix that and remove the ammo!

Lol, i like your humor. :laughing:
look forward to the pictures… Oooh and vid!