Im editing the code for my hexapod to include some new functions and changing some of the buttons around, but I am not quite sure where to start. Ill describe what I would like my robot to do, and link some of the code I think needs to change. If anyone could give me a hand, or point me to another topic where this is covered (I did a search, but couldnt find anything relevant) I would be very appreciative.
So, the next big coding problem I have is... coding the Left analog stick to pan and tilt the turret-torso.
Currently, the Left Analog Stick code looks like this:
Steering = DualShock(5) - 128 ; Left Stick Horizontal
StepFlag = (GaitSpeedTmp - 2) max 3
if HeightAdjust or LockLegs then
Height = LastHeight + (((DualShock(6) - 128) / 5) - LastHeight) / StepFlag; Left Stick Vertical
Height = (Height Max HeightLimit) min - HeightLimit
if Steering or (Height <> LastHeight) or YSpeed or XSpeed or LockLegs then
MovesDelay = 8
if MovesDelay > 0 then
LastHeight = Height
DCoord = SQR(XSpeed * XSpeed + YSpeed * YSpeed)
TmpCos = XSpeed * 127 / DCoord
DAngle = TmpAngle
if YSpeed > 0 then
DAngle = 256 - DAngle
I want to change this code so that instead of rotating left and right with the Left Stick Horizontal, I want it to be rotated left when pushing L1 and right when pushing R1.
Currently the code for L1 and R1 is this:
if (DualShock(2).bit3 = 0) and LastButton(1).bit3 then ;R1 Button test
Height = 0 ; average BH, low LUS, max speed
LegUpShift = 20
GaitSpeed = 3
elseif (DualShock(2).bit2 = 0) and LastButton(1).bit2 ;L1 Button test
Height = 5 ; tile floor
LegUpShift = 30
GaitSpeed = 3
The new function for Left Stick Horizontal, I want to turn Servo X left when pushing left, and right when pushing right. The new function for Left Stick Vertical, I want to turn Servo Y left when pushing up, and right when pushing down. What I need to do as well, however, is make sure the servos dont turn too far and break, so there would be need to be a maximum limit for the servos.
Ill add the full code at the bottom of this post, if you need to see the constants as well. (on second thoughts, its way too big - I will add it as an attachment instead)
Ill be putting the panning servo on Pin 31, as detailed in this code:
; Deck Pin
DeckP Con "3" ;Deck Panning servo : pin 31
DeckP2 Con "1"
and the Tilt servo on Pin 28, as detailed in this code:
; Additional Tilt servo for 180Â° Deck
DeckTilt Con "2"
DeckTilt2 Con "8"
Ill show the example of the max limits that I found, i suspect ill need to copy this for panning and tilting limits - I would like to start off with the maximum limits of the servos, and then cut down the maximum limits after experimentation with the actual robot.
Deck_PulseMin con 600
Deck_PulseMax con 2400
LGripLR_PulseMin con 750
LGripLR_PulseMax con 2250
LGripOC_PulseMin con 750
LGripOC_PulseMax con 2250
HipH_AngleMin con 21 ;30Â°
HipH_AngleMax con 107 ;150Â°
HipH_PulseMin con 910
HipH_PulseMax con 2090
HipV_AngleMin con 25 ;35Â°
HipV_AngleMax con 103 ;145Â°
HipV_PulseMin con 960
HipV_PulseMax con 2040
Knee_AngleMin con 36 ;50Â°
Knee_AngleMax con 107 ;150Â°
Knee_PulseMin con 1107
Knee_PulseMax con 2090
Anyway, I hope you guys can help me understand this, as I am struggling a little trying to figure it out myself, and dont want to accidentally "break" the code by putting the wrong stuff in.
The servos I currently have have a range of 180 degrees.