{{{



# Useful Python Code for Beginning





###

# most useful modules to import:



import math

import Global

import Constant

import VisionLink

import Action

import Indicator

import hMath





###

# head stuff



Action.setHeadParams(pan, tilt, crane)



Action.setHeadToLastPoint()



# current head params

Global.pan

Global.tilt

Global.crane



# N.B. these are the [same as/source for] the above:

VisionLink.getJointSensor(Constant.jHeadPan)

VisionLink.getJointSensor(Constant.jHeadTilt)

VisionLink.getJointSensor(Constant.jHeadCrane)





# maximum / minimum values for the head:

Constant.MAX_PAN   # = 93

Constant.MIN_PAN   # = -93

Constant.MAX_TILT  # = 3

Constant.MIN_TILT  # = -80

Constant.MAX_CRANE # = 50

Constant.MIN_CRANE # = -20









###

# walking



Action.walk(forward/back, left/right, rotation)



Action.kick(Action.SOMEKICKTYPE)



hMath.walkSpeedToDistance(speed, type)

hMath.walkDistanceToSpeed(distance, type)









###

# maths





# arctan( a / b )

math.atan2(a, b)







# the following are some pickings from hMath:



hMath.dotProduct2D(vec1x, vec1y, vec2x, vec2y)



hMath.normaliseVector2D(vec1x, vec1y)



# returns -1, 1 or 0 according to the sign of the input

hMath.sign(x)



hMath.getLength(vec)



hMath.normalise(vec)



# Rotates a 2D vector counter-clockwise by the given angle in degrees

hMath.rotate(vec, angle, rad = False)









###

# Coordinates:





# Clip a coordinate to a point in the field

hMath.clipPosition((x,y))





# convert a point from local to global coordinates

hMath.localToGlobalCoordinates(x, y):



# convert a point from global to local coordinates

hMath.globalToLocalCoordinates(x, y):









###

# Time:



VisionLink.getCurrentTime()



# RETURN: the time elapsed in MILLI-seconds

# takes 2 time tuples in (sec, mirco-sec) form,

hMath.getTimeElapsed(oldTime, newTime = None)











###

# ball stuff





Global.vBall.isVisible()







# this is the Visible x and y position of a point on the ball, on the *ground*, relative to the ground-point under the dog's head

# these are local coordinates

# top-view:

#

#  ^ 

#  |

#  y

#  |    -'ve     0       +'ve

#  v   <-------- x ---------->

#              _____

#             / head \		

x, y = VisionLink.getProjectedBall()







# x and y of a point on the ball (local coords),

# heading and

# distance (both relative to neck base)

# as determined by the Kalman Filter / Baysian stuff i.e. dog's vision can see the ball

Global.gpsLocalBall.getPos()

Global.gpsLocalBall.getHeading()

Global.gpsLocalBall.getDistance()



# x and y of a point on the ball (global),

# heading and

# distance (both relative to neck base)

# as seen on the camera

Global.vBall.getPos()

Global.vBall.getHeading()

Global.vBall.getVobDistance()

	



# Global's best guess (i.e. when dog's vision can't see the ball) at where the ball is (using vision AND gps)

Global.ballX

Global.ballY

# distance to the ball

Global.ballD

# ball's heading

Global.ballH





# variance of the ball

# N.B. standard deviation is the square root of the variance

# assumed to be in cm.

VisionLink.getGPSBallMaxVar()





###

# robot stuff



# the position of the robot in global coordinates

Global.selfX

Global.selfY



# robot's heading

Global.selfH





# Note: these values are retrieved from VisionLink in Global using:

selfLoc.setVals(*VisionLink.getGPSSelfInfo())

(selfX, selfY, selfH) = selfLoc.getPose()







###

# pretty/cute/debug stuff



Indicator.setFaceLed( a number 1-15 )

# 13 = red eyes

# 9 and 10 = white eyes





Indicator.lowerTail()



Indicator.raiseTail()





Indicator.showHeadColor(Indicator.RGB_??)

# RGB Color Information for the light on head, used in showHeadColor

RGB_NONE                      = (False, False, False)

RGB_BLUE                      = (False, False, True)

RGB_GREEN                     = (False, True, False)

RGB_CYAN    = RGB_LIGHT_BLUE  = (False, True, True)

RGB_RED     = RGB_ORANGE      = (True, False, False)

RGB_MAGENTA = RGB_PURPLE      = (True, False, True)

RGB_YELLOW                    = (True, True, False)

RGB_WHITE                     = (True, True, True) 	



###

# Sensors



VisionLink.getPressSensorCount(pressSensorID)

pressSensorID = 

PRESS_HEAD,

PRESS_BACK_FRONT,

PRESS_BACK_MIDDLE,

PRESS_BACK_REAR



###

#Walk Types for rotation and sideways movement with the ball



#Rotation

#Action.walk(0,0,100,"ssd",Action.GrabWT) #Crashes with these parameters

#Action.walk(0,0,100,"ssd",Action.SkellipticalWalkWT,Action.SkeGrabDribbleMWT) #excellent performance. Ball bounces back and forth between paws.

#Action.walk(0,0,100,"ssd",Action.SkellipticalWalkWT,Action.SkeGrabDribbleHoldMWT) #wrists a little farther forward

#Action.walk(0,0,100,"ssd",Action.NormalWalkWT,Action.NorGrabDribbleMWT) #arms farther apart, useful for approach, not spin

#Action.walk(0,0,100,"ssd",Action.NormalWalkWT,Action.NorGrabForwardOnlyMWT)

#Action.walk(0,0,100,"ssd",Action.NormalWalkWT,Action.NorGrabSideOnlyMWT)  #arms forward and apart!

#Action.walk(0,0,100,"ssd",Action.NormalWalkWT,Action.NorGrabTurnOnlyMWT)

Action.walk(0,0,100,"ssd",Action.SkellipticalWalkWT,Action.GrabDribbleMWT)#like first

#Action.walk(0,0,100,"ssd",Action.SkellipticalWalkWT,Action.GrabForwardOnlyMWT)#arms apart a little, still grabbing

#Action.walk(0,0,100,"ssd",Action.SkellipticalWalkWT,Action.GrabSideOnlyMWT)#maybe a little more sensitive

#Action.walk(0,0,100,"ssd",Action.SkellipticalWalkWT,Action.GrabTurnOnlyMWT) #horrible!  useless!



#Sideways Movement

#Action.walk(0,100,0,"ssd",Action.SkellipticalWalkWT,Action.SkeGrabDribbleMWT) #turns a little

##Action.walk(0,100,0,"ssd",Action.SkellipticalWalkWT,Action.SkeGrabDribbleHoldMWT)#is better!

#Action.walk(0,100,0,"ssd",Action.NormalWalkWT,Action.NorGrabDribbleMWT)#bumps ball away, bad

#Action.walk(0,100,0,"ssd",Action.NormalWalkWT,Action.NorGrabForwardOnlyMWT)#no good at all

#Action.walk(0,100,0,"ssd",Action.NormalWalkWT,Action.NorGrabSideOnlyMWT) #also not good

#Action.walk(0,100,0,"ssd",Action.NormalWalkWT,Action.NorGrabTurnOnlyMWT)#arms too far apart

#Action.walk(0,100,0,"ssd",Action.SkellipticalWalkWT,Action.GrabDribbleMWT)#okay

#Action.walk(0,100,0,"ssd",Action.SkellipticalWalkWT,Action.GrabForwardOnlyMWT)#heavy rotation

#Action.walk(0,100,0,"ssd",Action.SkellipticalWalkWT,Action.GrabSideOnlyMWT)#little wider our.  spinning pretty hard

#Action.walk(0,100,0,"ssd",Action.SkellipticalWalkWT,Action.GrabTurnOnlyMWT)#bit too heavy rotation



}}}