def __init__(self): self.servo_hat = pi_servo_hat.PiServoHat() self.servo_hat.restart() self.pan_servo = Servo(self.servo_hat, pan_servo_channel, pan_zero_angle, pan_multiplier, pan_min, pan_max) self.tilt_servo = Servo(self.servo_hat, tilt_servo_channel, tilt_zero_angle, tilt_multiplier)
def main(): #Servo parameters servo = pi_servo_hat.PiServoHat() # Restart hat servo.restart() servo.set_pwm_frequency(pwm_freq) rospy.init_node('PanAndTilt', anonymous=True) ROM(servo) Tracking = Motor_CMD(servo) rospy.spin()
def main(): servo_hat = pi_servo_hat.PiServoHat() servo_hat.restart() pan_servo = Servo(self.servo_hat, pan_servo_channel, pan_zero_angle, pan_multiplier, pan_min, pan_max) tilt_servo = Servo(self.servo_hat, tilt_servo_channel, tilt_zero_angle, tilt_multiplier) rospy.init_node('pan_tilt_listener') listener()
def main(): #Servo parameters rospy.init_node('PanAndTilt', anonymous =True) servo = pi_servo_hat.PiServoHat() # Restart hat servo.restart() servo.set_pwm_frequency(pwm_freq) ROM(servo) pub = rospy.Publisher('/AT_yaw', AprilTagYaw, queue_size= 10) Tracking = Motor_CMD(servo,pub) rospy.spin()
def runExample(): print("\nSparkFun Pi Servo Hat Demo\n") mySensor = pi_servo_hat.PiServoHat() # if mySensor.isConnected() == False: # print("The Qwiic PCA9685 device isn't connected to the system. Please check your connection", sys.stderr) # return mySensor.restart() # Test Run ######################################### # Moves servo position to 0 degrees (1ms), Channel 0 mySensor.move_servo_position(1, 0) # Pause 1 sec time.sleep(1) mySensor.move_servo_position(1, 54) # Moves servo position to 90 degrees (2ms), Channel 0 # mySensor.move_servo_position(1, 20) h = 2 # print("Servo 1 at position 0") # for i in range(-10,140,10): # print ("Servo " ,h, " at position ",i) # mySensor.move_servo_position(h, i) # time.sleep(3) #Forard is near 50, left is 0 and right is 130-ish print("Test in the forward position = 54") mySensor.move_servo_position(h, 54) time.sleep(2) # for i in range(52,56,1): # print ("Servo " ,h, " at position ",i) # mySensor.move_servo_position(h, i) # time.sleep(5) print("Test in the right position =130") mySensor.move_servo_position(h, 130) time.sleep(2) # for i in range(120,140,1): # print ("Servo " ,h, " at position ",i) # mySensor.move_servo_position(h, i) # time.sleep(3) print("Test in the left position=-21") mySensor.move_servo_position(h, -21)
def main(win): limlo = -44 limhi = 140 delta = 1 x = 64 y = 7 key = "" servo = pi_servo_hat.PiServoHat() servo.restart() win.nodelay(True) servo.move_servo_position(1, x) servo.move_servo_position(0, y) while True: try: key = win.getkey() except Exception as e: key = "" pass if key != "": if key == os.linesep: break if key == "KEY_LEFT": x = max(limlo, x - delta) if key == "KEY_RIGHT": x = min(limhi, x + delta) if key == "KEY_UP": y = min(limhi, y + delta) if key == "KEY_DOWN": y = max(limlo, y - delta) win.clear() win.addstr(str(x) + " " + str(y)) servo.move_servo_position(1, x) servo.move_servo_position(0, y)
import pi_servo_hat import time arm_range = [0, 232] # min, max base_range = [-5, 230] # min, max arm_channel = 0 base_channel = 1 prev_arm_angle = 0 prev_base_angle = 0 # setting up library servo_controller = pi_servo_hat.PiServoHat() servo_controller.restart() def linear_scale(rangelist, inputangle): '''returns corrected angle''' scale = (rangelist[1] - rangelist[0])/180 yoffset = rangelist[0] outputangle = inputangle * scale + yoffset return outputangle def move_arm(angle): global prev_arm_angle servo_controller.move_servo_position(0, linear_scale(arm_range, angle), 180) time.sleep(1.5/180*abs(angle-prev_arm_angle)) prev_arm_angle = angle def move_base(angle): global prev_base_angle
# these parameters are set as variables here to improve readability # of this code, 0-100 percent is the most logical input limit to apply # although others are possible. Realistically, these values can be set # to any arbitrary numbers as long as the user is prepared to send # commands which properly utilize the arbitrarily set limits # for this class, students will command motor speed in terms of # percentage with a max value of 100 and a min value of 0, this is an # improvement over commanding the ms value for the RC pwm duty cycle # since it doesn't require the odious explanation of the mechanics # of the difference in RC and standard PWM square wave signals max_in = 100.0 # percent min_in = 0.0 # percent # set up functions at this outermost scope, these have been borrowed # from Sparkfun Examples servos = pi_servo_hat.PiServoHat() # not entirely sure why we need to restart here, no diagnostic # "is connected?" function seems to be provided so we cannot check # intelligently here and instead resort to blindly following some # example code we found which always restarts during setup servos.restart() servos.set_pwm_frequency(pwm_frequency) ###------------MAKE SQUARE WAVE PWM BEHAVE LIKE RC PWM------------### # set up some vars which will be used inside the range function dt = 1 / pwm_frequency # convert from ms to percentage duty cycle for standard square # wave since that is the language that our provided driver natively
""" This example should be used with a 180 degree (range of rotation) servo on channel 0 of the Pi Servo Hat. The extended code (commented out), at the end of the example could be used to test the full range of the servo motion. However, users should be wary as they can damage their servo by giving it a position outside the standard range of motion. """ import pi_servo_hat import time # Initialize Constructor test = pi_servo_hat.PiServoHat() # Restart Servo Hat (in case Hat is frozen/locked) test.restart() # Test Run ######################################### # Moves servo position to 0 degrees (1ms), Channel 0 test.move_servo_position(0, 0, 180) # Pause 1 sec time.sleep(1) # Moves servo position to 180 degrees (2ms), Channel 0 test.move_servo_position(0, 180, 180)
#!/usr/bin/env python import rospy from std_msgs.msg import Twist import pi_servo_hat import time import sys #instantiate the servo hat myServoHat= pi_servo_hat.PiServoHat() myServoHat.restart() #move the servos def camera_servo_cmd(data): #pan servo is in poisition 1 mySensor.move_servo_position(1, data.angular.x * 130) #pan servo is in poisition 0 mySensor.move_servo_position(0, data.angular.y * 130) # #camera_cmd is the node that moves the camera servos after changing the position of the camera_orientation frame def camera_cmd(): rospy.init_node('camera_cmd', anonymous=True) sub = rospy.Subscriber('camera_orientation',Twist, camera_servo_cmd) rospy.spin()
def __init__(self): self.servo = pi_servo_hat.PiServoHat() self.servo.restart()