;;; AutoCAD Wiki AutoLISP code header. ;;; ;;; Copy this code to a file on your computer. ;;; Start highlighting OUTSIDE the code boxes and use the mouse or keyboard to ;;; highlight all the code. ;;; If you select too much, simply delete any extra from your destination file. ;;; In Windows you may want to start below the code and use [Shift]+[Ctrl]+[Home] ;;; key combination to highlight all the way to the top of the article, ;;; then still holding the [Shift] key, use the arrow keys to shrink the top of ;;; the selection down to the beginning of the code. Then copy and paste. ;;; This program is free software: you can redistribute it and/or modify ;;; it under the terms of the GNU General Public License as published by ;;; the Free Software Foundation, either version 3 of the License, or ;;; (at your option) any later version. ;;; ;;; This program is distributed in the hope that it will be useful, ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ;;; GNU General Public License for more details. ;;; ;;; The working version of this software is located at the AutoCAD Wiki. ;;; Please Be Bold in adding clarifying comments and improvements at ;;; http://autocad.wikia.com/wiki/Turning_path_tracker_(AutoLISP_application) ;;; This program is free software: you can redistribute it and/or modify ;;; it under the terms of the GNU General Public License as published by ;;; the Free Software Foundation, either version 3 of the License, or ;;; (at your option) any later version. ;;; ;;; This program is distributed in the hope that it will be useful, ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ;;; GNU General Public License for more details. ;;; ;;; The working version of this software is located at the AutoCAD Wiki. ;;; Please Be Bold in adding clarifying comments and improvements at ;;; http://autocad.wikia.com/wiki/Turning_path_tracker_%28AutoLISP_application%29 ;;; This program is free software: you can redistribute it and/or modify ;;; it under the terms of the GNU General Public License as published by ;;; the Free Software Foundation, either version 3 of the License, or ;;; (at your option) any later version. ;;; ;;; This program is distributed in the hope that it will be useful, ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ;;; GNU General Public License for more details. ;;; ;;; The working version of this software is located at the AutoCAD Wiki. ;;; Please Be Bold in adding clarifying comments and improvements at ;;; http://autocad.wikia.com/wiki/Turning_path_tracker_%28AutoLISP_application%29 ;;; ;;; TURN.LSP ;;; Copyright 2009 Thomas Gail Haws ;;; Copyright 2008 Stephen Hitchcox ;;; TURN.LSP draws vehicle turning paths in AutoCAD. ;;; ;;; OVERVIEW ;;; TURN.LSP draws a polyline representing a theoretical rear wheel path ;;; as it follows the polyline front wheel path of a turning/weaving ;;; vehicle and also draws the body of the vehicle and a single trailer. ;;; While TURN.LSP is theoretically accurate only for ;;; two-wheeled vehicles, its tested results correlate very well to ;;; published AASHTO turning templates, even for articulated vehicles. ;;; ;;; This version of TURN.LSP has no default vehicle information. It requires ;;; use of attributed blocks made using the sister program "BuildVehicle". ;;; which contain all required information other than the path. Note that ;;; Turn.lsp at this moment is at a beta level, and has no error correction, ;;; and does not check for minimum radius paths allowed by each vehicle. It ;;; also does not take into account speed, friction, slope, and other variables. ;;; Refer to commercially available programs if you really want a verified ;;; algorithm. ;;; ;;; GETTING STARTED ;;; At minimum, all TURN.LSP needs from you is a front left wheel path polyline ;;; and a BuildVehicle block. Try the following exercise. ;;; ;;; First, draw a good, long, polyline representing a front wheel path. ;;; For good looks, begin and end the path with plenty of straight length. ;;; then (just for convenience and clarity, not necessity) offset the ;;; polyline the vehicle width to create the other wheel path. ;;; ;;; Second, load and run TURN. TURN currently has two behavior methods or versions. ;;; They are presented to you as options User block method/Generated block method: ;;; The User Block method doesn't keep track of as many vehicle dimensions and paths. ;;; It merely drags your block along a path. ;;; It also doesn't model hitches at this time, which limits its accuracy for trailers. ;;; The Generated Vehicle method doesn't show the nuances of a vehicle as well. ;;; It merely draws rectangles along with multiple calculated wheel paths. ;;; While we hope to harmonize the two methods, they are currently rather independent. ;;; If you choose the Generated vehicle method, TURN will ask you for all of the parameters ;;; for your vehicle, and draw a unique attributed block. You can build a library ;;; of vehicles for future use. For any any group of multiple axles, use their "centroid" ;;; to model them as a single axle. ;;; ;;; enter "N" for no trailer, but still give place holder data for the non-existent ;;; trailer. It will not be drawn. ;;; ;;; The parameters are used to build a scale block of the vehicle you are ;;; defining, which is made into a block. ;;; ;;; You can change the attributes in the block if you make a mistake, but the block ;;; itself does not change size (it is not dynamic). ;;; ;;; If you make a new block with the same name as an existing one, it will overwrite ;;; the old one. ;;; ;;; Draw the path for the vehicle as the route taken by the front left tire. A future ;;; version of this program might add path by centre or by right side of vehicle, to ;;; suit other driving standards. ;;; ;;; Move the BuildVehicle block of your choice to the beginning of the polyline path. ;;; ;;; Then, run TURN. When prompted, select the BuildVehicle block, and then ;;; select the front wheel path very near the starting end. ;;; Turn.lsp uses the dimensions of the vehicle block for calculations. ;;; Accept TURN.LSP's suggestions for a calculation step and plotting accuracy ;;; or enter your own. ;;; ;;; Note: Place the vehicle at the start of the path using the centre of the ;;; FRONT LEFT WHEEL, which should be marked with an "x" type figure. Rotate the ;;; vehicle to the approximate correct starting angle. ;;; ;;; Note: Select the LEFT WHEEL PATH (Drivers Side in most locations). The right ;;; side is drawn off of this. Note that there is no functional difference ;;; for the path of the vehicle based on where the driver is sitting. ;;; ;;; Turn draws several POINT objects, then erases them and draws the path of the ;;; rear wheel, along with the tractor and trailer bodies, as well as all other tire ;;; paths. ;;; ;;; REFERENCE ;;; Vehicle dimensions (ft) Min. Outside Min. Inside ;;; Vehicle Width WB1 WB2 Rad Rad. (check) ;;; P (passenger) 7 11 24.0 13.8 ;;; SU (single truck) 8.5 20 42.0 27.8 ;;; BUS 8.5 25 42.0 24.4 ;;; WB-40 8.5 13 27 40.0 18.9 ;;; WB-50 8.5 20 30 45.0 19.2 ;;; ;;; THEORY ;;; For each computation step, a vehicle wheel pair (front and back) is assumed ;;; to be traveling in a circle as though the steering wheel or articulating hinge ;;; were locked. The front and back wheels are circumscribing two concentric ;;; circles, with the line between back and front wheel always tangent to the ;;; inner circle being made by the back wheel, as shown: ;;; ;;; <= Counter-clockwise Travel ;;; ooo ;;; o o F0 ;;; o /o ;;; o _ L/ o ;;; o / \/ o ;;; o B1 C B0 o ;;; o L/ \ _ / o ;;; o/ o ;;; F1 o o ;;; ooo ;;; => Counter-clockwise Travel ;;; ;;; The initial locations of the back and front wheels are known (B0 and F0), and the ;;; final location of the front wheel is known (F1). ;;; Then the turned angle F0|C|F1=B0|C|B1=2*atan{sin(alpha)/[2*L/S-cos(alpha)]} ;;; where ;;; S=the distance from F0 to F1 ;;; L=the distance from B0 to F0, the wheelbase length ;;; alpha=angle F1|F0|B0 ;;; ;;; ;;; Development Notes: ;;; DEVELOPMENT PLANS ;;; 1) implement better error correction ;;; ;;; 2) collect and share correctly dimensioned standard vehicles ;;; ;;; 3) revise to allow multiple ;;; trailers ;;; ;;; 4) revise to draw tires centred on the tire paths ;;; ;;; 5) 080205 imperial scaling issue resolved, and input for dimensional information ;;; revised to allow picks from drawing ;;; (DEFUN TURN-INITIALIZESETTINGS () ;;; REVISION HISTORY (TURN-SETVAR "General.Version" "1.1.12") ;;; Date Programmer Revision ;;; 20110405 TGH 1.1.12 For CADDIT, changed local variable name from "layer" to "layer-list" ;;; 20100504 TGH 1.1.11 For Bricscad, changed "endp" osnap to "end" ;;; 20090312 TGH 1.1.10 Turned trailer box from bowtie into box (Again?!? See v. 1.1.7) ;;; 20090226 TGH 1.1.9 Minor tweak to version reporting ;;; 20081112 TGH 1.1.8 Added layer settings functions to consolidate names in one place ;;; 20080522 SH 1.1.7 Revised layers to an identifiable set, using AIA type standard. placed under C for Civil ;;; and using TURN as a reserve header. Also fixed trailer to draw as a box not a cross. ;;; 20080416 TGH 1.1.6 Added block plotting method with more modular code and defined data structure. ;;; combined both methods into one routine ;;; 20080410 TGH 1.1.5 Simplified prompts, added layer defaults, and fixed a few errors. ;;; 20080206 SH 1.1.4 Fixed Imperial dimension storage, and made input consistent to type of data ;;; 20080120 SH 1.1.3 Various, including Centre of Wheels used instead of Outside of Wheels (vehicles ;;; steer on the centroids of the wheels, not the rims), "Set-out" point added at Front Left ;;; wheel ;;; 20070327 SH 1.1.2 Trailer plotting ;;; 20061213 TGH 1.1.1 Initial vehicle orientation from mandatory block selection instead of prompt. ;;; 20060324 SH 1.1.0 Added BUILDVEHICLE interface to allow overhang and sideswipe analysis. ;;; 20040507 TGH 1.0.1 Added osnap shutoff and restore. ;;; 20021025 TGH Replaced tracking equation with better algorithm. Removed plot point reduction algorithm. ;;; 20020627 TGH Added GETDISTX function to distribution file. ;;; 20020625 TGH Added capability to follow reverse drawn polylines. ;;; ;;;---------------------------------------------------------------------------- ;;; Program settings users can edit-------------------------------------------- ;;;---------------------------------------------------------------------------- ;;; ;;; Layer settings. (TURN-SETLAYER "TruckBody" "C-TURN-TRCK-BODY" "1" "") (TURN-SETLAYER "TrailerBody" "C-TURN-TRAL-BODY" "2" "") (TURN-SETLAYER "HitchPath" "C-TURN-HTCH-PATH" "3" "") (TURN-SETLAYER "TruckBackLeftTirePath" "C-TURN-TRCK-RLTR-PATH" "3" "dashed" ) (TURN-SETLAYER "TruckBackRightTirePath" "C-TURN-TRCK-RRTR-PATH" "3" "dashed" ) (TURN-SETLAYER "TruckFrontRightTirePath" "C-TURN-TRCK-FRTR-PATH" "3" "dashed" ) (TURN-SETLAYER "TrailerBackRightTirePath" "C-TURN-TRAL-RLTR-PATH" "4" "dashed" ) (TURN-SETLAYER "TrailerBackLeftTirePath" "C-TURN-TRAL-RRTR-PATH" "4" "dashed" ) ) ;;; ;;;---------------------------------------------------------------------------- ;;; End of program settings users can edit------------------------------------- ;;;---------------------------------------------------------------------------- ;;; ;;; TURN-SETVAR (DEFUN TURN-SETVAR (VARNAME VALUE / NEWGROUP OLDGROUP) ;;; For future compatibility with other storage options, ;;; We're keeping all values as strings (text). ;;Put VarName and Value together into a setting group. (SETQ VARNAME (STRCASE VARNAME) NEWGROUP (CONS VARNAME VALUE) ) (COND ;;If the variable is already set, then ((SETQ OLDGROUP (ASSOC VARNAME *TURN:SETTINGS*)) ;;Replace the old setting with the new setting. (SETQ *TURN:SETTINGS* (SUBST NEWGROUP OLDGROUP *TURN:SETTINGS*)) ) ;;Else, (T ;;Add the setting. (SETQ *TURN:SETTINGS* (CONS NEWGROUP *TURN:SETTINGS*)) ) ) ) ;;; ;;; TURN-GETVAR (DEFUN TURN-GETVAR (VARNAME / VARNAMEMIXED) (SETQ VARNAMEMIXED VARNAME VARNAME (STRCASE VARNAME) ) (COND ;;If the setting is found, then return it ((CDR (ASSOC VARNAME *TURN:SETTINGS*))) ;;Else (T ;;1. Send an error message. (ALERT (PRINC (STRCAT "\nNo setting was found for " VARNAMEMIXED ".\nGeotables can't continue." ) ) ) ;;2. Exit (EXIT) ) ) ) ;;Sets up a layer setting (DEFUN TURN-SETLAYER (BASENAME LANAME LACOLOR LALTYPE) (TURN-SETVAR (STRCAT "Layers." BASENAME ".Name") LANAME) (TURN-SETVAR (STRCAT "Layers." BASENAME ".Color") LACOLOR) (TURN-SETVAR (STRCAT "Layers." BASENAME ".Linetype") LALTYPE ) ) ;;Gets a layer list from a layer base name string. (DEFUN TURN-GETLAYER (BASENAME) (LIST (TURN-GETVAR (STRCAT "Layers." BASENAME ".Name")) (TURN-GETVAR (STRCAT "Layers." BASENAME ".Color")) (TURN-GETVAR (STRCAT "Layers." BASENAME ".Linetype")) ) ) ;;; Layer settings added by Tom Haws 2008-04-10 (DEFUN TURN-MAKELAYERS (/ LAYER-LIST) ;;Layer change 2008-02-22 Stephen Hitchcox (FOREACH BASENAME '("TruckBody" "TrailerBody" "HitchPath" "TruckBackLeftTirePath" "TruckBackRightTirePath" "TruckFrontRightTirePath" "TrailerBackRightTirePath" "TrailerBackLeftTirePath" ) (SETQ LAYER-LIST (TURN-GETLAYER BASENAME)) (COMMAND "._layer" "t" (CAR LAYER-LIST) "on" (CAR LAYER-LIST) "un" (CAR LAYER-LIST) "m" (CAR LAYER-LIST) "c" (CADR LAYER-LIST) "" "lt" (CADDR LAYER-LIST) "" "" ) ) ) (TURN-INITIALIZESETTINGS) (TURN-MAKELAYERS) (DEFUN C:TURN (/ METHOD VEHNAME) (INITGET "User Generated ?") (SETQ METHOD (GETKWORD "\nTracking method [User block/Generated vehicle/?]: " ) ) (COND ((= METHOD "User") (TURN-MAIN-USER-BLOCK-METHOD)) ((= METHOD "Generated") (SETQ VEHNAME (GETSTRING "\nName for new vehicle or