예제 #1
0
파일: gcode.py 프로젝트: getarun/raspberry
            costheta=(Dx*e1[0]+Dy*e1[1])/r**2;
            sintheta=(Dx*e2[0]+Dy*e2[1])/r**2;        #theta is the angule spanned by the circular interpolation curve
                
            if costheta>1:  # there will always be some numerical errors! Make sure abs(costheta)<=1
        costheta=1;
        elif costheta<-1:
        costheta=-1;

            theta=arccos(costheta);
            if sintheta<0:
                theta=2.0*pi-theta;

            no_step=int(round(r*theta/dx/5.0));   # number of point for the circular interpolation
            
            for i in range(1,no_step+1):
                tmp_theta=i*theta/no_step;
                tmp_x_pos=xcenter+e1[0]*cos(tmp_theta)+e2[0]*sin(tmp_theta);
                tmp_y_pos=ycenter+e1[1]*cos(tmp_theta)+e2[1]*sin(tmp_theta);
                moveto(MX,tmp_x_pos,dx,MY, tmp_y_pos,dy,speed,True);
        
except KeyboardInterrupt:
    pass

GPIO.output(Laser_switch,False);   # turn off laser
moveto(MX,0,dx,MY,0,dy,50,False);  # move back to Origin

MX.unhold();
MY.unhold();

GPIO.cleanup();
예제 #2
0
#     linear motion                                                                #
#       Xiang Zhai,   May 2, 2013                         				       #
#       zxzhaixiang at gmail.com							       #
#  For instruction on how to build the laser engraver and operate the codes, please visit      #
#   funofdiy.blogspot.com                                                                      #
#											       #
################################################################################################

import RPi.GPIO as GPIO
from Bipolar_Stepper_Motor_Class import Bipolar_Stepper_Motor
import time
from numpy import pi, sin, cos, sqrt, arccos, arcsin

GPIO.setmode(GPIO.BOARD)
M = Bipolar_Stepper_Motor(11, 7, 5, 3)

speed = 200
#step/sec

try:
    for i in range(30):
        print "Move to %s .." % ((i + 1) * 1000)
        M.move(-1, 1000, 1.0 / speed)

except KeyboardInterrupt:
    pass

M.unhold()

GPIO.cleanup()
예제 #3
0
                    costheta = 1
                elif costheta < -1:
                    costheta = -1

                theta = acos(costheta)
                if sintheta < 0:
                    theta = 2.0 * pi - theta

                # number of point for the circular interpolation
                no_step = int(round(r * theta / dx / 5.0))

                for i in range(1, no_step + 1):
                    tmp_theta = i * theta / no_step
                    tmp_x_pos = xcenter+e1[0] * \
                        cos(tmp_theta)+e2[0]*sin(tmp_theta)
                    tmp_y_pos = ycenter+e1[1] * \
                        cos(tmp_theta)+e2[1]*sin(tmp_theta)
                    moveto(MX, tmp_x_pos, dx, MY, tmp_y_pos, dy)

except KeyboardInterrupt:
    pass

SetPenDown(False)  # up the pen
moveto(MX, 0, dx, MY, 0, dy)  # move back to Origin

MZ.stop()
MX.unhold()
MY.unhold()

GPIO.cleanup()
                         dy * center_distance1[1]) / radius**2
            sin_theta = (dx * center_distance2[0] +
                         dy * center_distance2[1]) / radius**2
            #theta is the angule spanned by the circular interpolation curve
            if cos_theta > 1:
                cos_theta = 1
            elif cos_theta < -1:
                cos_theta = -1
            theta = arccos(cos_theta)

            if sin_theta < 0:
                theta = 2.0 * pi - theta
            num_steps = int(
                round(radius * theta / max_precision /
                      5.0))  # number of point for the circular interpolation

            for i in range(1, num_steps + 1):
                tmp_theta = i * theta / num_steps
                tmp_x = xcenter + center_distance1[0] * cos(
                    tmp_theta) + center_distance2[0] * sin(tmp_theta)
                tmp_y = ycenter + center_distance1[1] * cos(
                    tmp_theta) + center_distance2[1] * sin(tmp_theta)
                x, direction_x, y, direction_y = getDirection(tmp_x, tmp_y)
                total_steps, step_x, step_y = getTotalSteps(x, y)
                runMotor(motorX, x, direction_x, step_x, motorY, y,
                         direction_y, step_y, total_steps, speed)

motorX.unhold()
motorY.unhold()
servo_motor.clean()