Пример #1
0
void test_drawing_units (int map_layout[MAX_X][MAX_Y])
{
    srand (time (NULL));
    drawing_units(map_layout);
}
Пример #2
0
Python CChamfer::AppendTextForCircularChildren(
	CMachineState *pMachineState,
	const double theta,
	HeeksObj *child,
	CTool *pChamferingBit )
{
	Python python;

	// See what the maximum possible depth is for this chamfering bit.  We want to figure
	// out whether we can cut with the middle part of the chamfering bit rather than
	// cutting using the very tip (we don't want to break it off).  In fact, we should
	// really cut with the top-most cutting edge so that it's as strong as it can be.  This
	// depends on the area available for fitting the chamfering bit.

	double min_chamfer_diameter = pChamferingBit->m_params.m_flat_radius * 2.0;
	double stand_off = m_depth_op_params.m_rapid_safety_space;
	double clearance_height = m_depth_op_params.ClearanceHeight();

	Circles_t circles;

	if (child->GetType() == DrillingType)
	{
		// Get the size of the drilled holes.  We need to know whether we need to just plunge
		// the chamfering bit directly down into the hole or whether we need to run
		// around the edge.

		CDrilling *pDrilling = (CDrilling *) child;
		CTool *pDrillBit = CTool::Find( pDrilling->m_tool_number );
		if (pDrillBit == NULL)
		{
			// It's difficult to drill a hole without a drill bit but apparently this file does.
			printf("Ignoring drilling operation (id=%d) with no  tool defined\n", pDrilling->m_id );
			return(python);	// Empty.
		}

        stand_off = pDrilling->m_params.m_standoff;
        clearance_height = pDrilling->m_params.ClearanceHeight();

		double hole_diameter = pDrillBit->CuttingRadius(false) * 2.0;

		if (hole_diameter < min_chamfer_diameter)
		{
			// The flat radius at the bottom of the chamfering bit is larger than the drilled hole.  It won't fit in.
			printf("Ignoring chamfer for drilled hole due to geometry of selected chamfering bit\n");
			return(python);	// Empty.
		}

		// Get all the point locations relevant for this operation and then adjust their position to align with
		// the current fixture.
		std::vector<CNCPoint> locations = CDrilling::FindAllLocations(pDrilling, pMachineState->Location(), true, NULL);
        for (std::vector<CNCPoint>::const_iterator l_itLocation = locations.begin(); l_itLocation != locations.end(); l_itLocation++)
		{
			CNCPoint point = pMachineState->Fixture().Adjustment( *l_itLocation );
			circles.push_back( Circle( point, hole_diameter, pDrilling->m_params.m_depth ) );
		} // End for
	} // End if - then

	if (child->GetType() == CounterBoreType)
	{
		CCounterBore *pCounterBore = ((CCounterBore *) child);

		stand_off = pCounterBore->m_depth_op_params.m_rapid_safety_space;
        clearance_height = pCounterBore->m_depth_op_params.ClearanceHeight();

		std::vector<CNCPoint> locations = CDrilling::FindAllLocations(pCounterBore, pMachineState->Location(), pCounterBore->m_params.m_sort_locations != 0, NULL);
		for (std::vector<CNCPoint>::const_iterator l_itLocation = locations.begin(); l_itLocation != locations.end(); l_itLocation++)
		{
			CNCPoint point = pMachineState->Fixture().Adjustment( *l_itLocation );
			double max_depth = pCounterBore->m_depth_op_params.m_start_depth - pCounterBore->m_depth_op_params.m_final_depth;
			circles.push_back( Circle( point, pCounterBore->m_params.m_diameter, max_depth ) );
		} // End for
	}

	// Now handle all the chamfering for both the drilled holes and/or the counterbores.
	// The circles indicate both the diameter and the depth of either hole.
	for (Circles_t::iterator l_itCircle = circles.begin(); l_itCircle != circles.end(); l_itCircle++)
	{
		// We want to select a depth such that we're cutting with the top-most part of the chamfering
		// bit as that is the strongest part.  We don't want to break off the tip unless we really can't
		// get into the hole without doing so.

		double max_hole_depth = l_itCircle->MaxDepth();
		double max_bit_plunge_depth = pChamferingBit->m_params.m_cutting_edge_height * cos(theta);

		double min_bit_radius = pChamferingBit->m_params.m_flat_radius;

		double hole_radius = l_itCircle->Diameter() / 2.0;
		double required_bit_plunge_depth =  (m_params.m_chamfer_width * cos( theta ));

		if ((required_bit_plunge_depth >= max_hole_depth) ||
			(required_bit_plunge_depth >= max_bit_plunge_depth) ||
			(hole_radius < min_bit_radius))
		{
			// It's too deep for one pass.
			return(python);	// Empty.
		}

		double plunge_depth = (max_hole_depth<=max_bit_plunge_depth)?max_hole_depth:max_bit_plunge_depth;
		double bit_radius_at_plunge_depth = pChamferingBit->m_params.m_flat_radius + (plunge_depth / tan(theta));

		// This is the gap between the bit and the hole when the bit's bottom is at the top surface.
		double gap_radius = hole_radius - min_bit_radius;

		// We need to figure out how far down to move before this gap is closed by the slope of the cutting edge.
		double gap_closure_depth = gap_radius / tan(theta);

		if ( hole_radius <= bit_radius_at_plunge_depth )
		{
			// We can plunge straight down at the hole's location.

			// If the chamfering bit is at the top of the hole then the diameter of
			// cut is equal to the flat radius.  How far should we plunge down before
			// the edge of the chamfering bit touches the top of the hole?

            CNCPoint point(l_itCircle->Location());

			python << _T("drill(")
				<< _T("x=") << point.X(true) << _T(", ")
				<< _T("y=") << point.Y(true) << _T(", ")
				<< _T("z=") << drawing_units(point.Z(false) - gap_closure_depth) << _T(", ")
				<< _T("depth=") << drawing_units(required_bit_plunge_depth) << _T(", ")
				<< _T("standoff=") << drawing_units(stand_off) << _T(", ")
				<< _T("dwell=") << 0.0 << _T(", ")
				<< _T("peck_depth=") << 0.0 << _T(", ")
                << _T("clearance_height=") << drawing_units(clearance_height)
				<< _T(")\n");
		}
		else
		{
			// We will have to run around the edge of the large hole.  Figure out the offset
			// in from the edge and generate the corresponding tool path.

			CNCPoint centre(l_itCircle->Location());
			CNCPoint point(l_itCircle->Location());

			double radius_of_spiral = hole_radius - bit_radius_at_plunge_depth + (m_params.m_chamfer_width * sin(theta));

			python << _T("rapid( x=") << centre.X(true) << _T(", ")
						<< _T("y=") << centre.Y(true) << _T(", ")
						<< _T("z=") << drawing_units(clearance_height) << _T(")\n");

            python << _T("rapid(z=") << drawing_units(stand_off) << _T(")\n");

			double cutting_depth = point.Z(false) - plunge_depth;

			// Move to 12 O'Clock.
			python << _T("feed( x=") << centre.X(true) << _T(", ")
						_T("y=") << drawing_units(centre.Y(false) + radius_of_spiral) << _T(", ")
						_T("z=") << drawing_units(cutting_depth) << _T(")\n");
			point.SetX( centre.X(false) );
			point.SetY( centre.Y(false) + radius_of_spiral );

			// First quadrant (12 O'Clock to 9 O'Clock)
			python << _T("arc_ccw( x=") << drawing_units(centre.X(false) - radius_of_spiral) << _T(", ") <<
						_T("y=") << centre.Y(true) << _T(", ") <<
						_T("z=") << drawing_units(cutting_depth) << _T(", ") <<	// full depth
						_T("i=") << drawing_units(centre.X(false)) << _T(", ") <<
						_T("j=") << drawing_units(centre.Y(false)) << _T(")\n");
			point.SetX( centre.X(false) - radius_of_spiral );
			point.SetY( centre.Y(false) );

			// Second quadrant (9 O'Clock to 6 O'Clock)
			python << _T("arc_ccw( x=") << centre.X(true) << _T(", ") <<
						_T("y=") << drawing_units(centre.Y(false) - radius_of_spiral) << _T(", ") <<
						_T("z=") << drawing_units(cutting_depth) << _T(", ") <<	// full depth now
						_T("i=") << drawing_units(centre.X(false)) << _T(", ") <<
						_T("j=") << drawing_units(centre.Y(false)) << _T(")\n");
			point.SetX( centre.X(false) );
			point.SetY( centre.Y(false) - radius_of_spiral );

			// Third quadrant (6 O'Clock to 3 O'Clock)
			python << _T("arc_ccw( x=") << drawing_units(centre.X(false) + radius_of_spiral) << _T(", ") <<
						_T("y=") << centre.Y(true) << _T(", ") <<
						_T("z=") << drawing_units(cutting_depth) << _T(", ") <<	// full depth now
						_T("i=") << drawing_units(centre.X(false)) << _T(", ") <<
						_T("j=") << drawing_units(centre.Y(false)) << _T(")\n");
			point.SetX( centre.X(false) + radius_of_spiral );
			point.SetY( centre.Y(false) );

			// Fourth quadrant (3 O'Clock to 12 O'Clock)
			python << _T("arc_ccw( x=") << centre.X(true) << _T(", ") <<
						_T("y=") << drawing_units(centre.Y(false) + radius_of_spiral) << _T(", ") <<
						_T("z=") << drawing_units(cutting_depth) << _T(", ") <<	// full depth now
						_T("i=") << drawing_units(centre.X(false)) << _T(", ") <<
						_T("j=") << drawing_units(centre.Y(false)) << _T(")\n");
			point.SetX( centre.X(false) );
			point.SetY( centre.Y(false) + radius_of_spiral );

			python << _T("rapid( z=") << drawing_units(m_depth_op_params.ClearanceHeight()) << _T(")\n");
		}
	} // End for

	return(python);
}