assembly.lisp 12.5 KB
Newer Older
1
;;
2
;; Copyright 2002, 2009 Genworks International
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
;;
;; This source file is part of the General-purpose Declarative
;; Language project (GDL).
;;
;; This source file contains free software: you can redistribute it
;; and/or modify it under the terms of the GNU Affero General Public
;; License as published by the Free Software Foundation, either
;; version 3 of the License, or (at your option) any later version.
;; 
;; This source file 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
;; Affero General Public License for more details.
;; 
;; You should have received a copy of the GNU Affero General Public
;; License along with this source file.  If not, see
;; <http://www.gnu.org/licenses/>.
;; 

#|

NOTE:

This is the original Robot example and uses the old-style user
interface approach. It is not recommended to continue with this
28
approach; the preferred approach is to use form-control objects for             
29
30
31
32
33
34
35
36
37
38
39
40
41
42
the form fields, as will be in other newer examples soon to be added
to the src/ directory distributed with GDL.  

|#


(in-package :robot)

(define-object army (base-object)
  :objects
  ((robots :type 'assembly
           :sequence (:size 50)
           :center (translate (the center) :right (* 10 (the-child index))))))

Dave Cooper's avatar
Dave Cooper committed
43
(define-object   assembly (application-mixin)
44
45
46
47
48
49
50
  
  :input-slots
  ((width 5 :settable)
   (length 2 :settable)
   (torso-type 'box :settable)
   (height 10 :settable)
   (head-angle 0 :settable)
51
   (body-angle 20 :settable)
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
   (arm-angle-right 0 :settable)
   (arm-angle-left 0 :settable)
   (pincer-distance-right (number-round (* .15 3/5 (the width)) 3) :settable)
   (pincer-distance-left (number-round (* .15 3/5 (the width)) 3) :settable)
   
   
   
   (transparency .2)
   (shininess .8)
   
   (graphics-width 460)
   
   )

  :computed-slots
  (
   
   (image-file "~/tmp/slack_in.gif")

   (strings-for-display "Robot Assembly")
   (ui-display-list-objects (list ;;(the bounding-bbox) 
                             (the robot)))
   (background-color :white)
   (foreground-color :blue)
   )

  :objects
Dave Cooper's avatar
Dave Cooper committed
79
80
  (
   (robot :type 'robot
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
          :pass-down (torso-type 
                      head-angle width length height transparency shininess
                      body-angle arm-angle-right arm-angle-left
                      pincer-distance-right pincer-distance-left))))

#+nil
(define-lens (html-format assembly)()
  
  :skin infinite
  
  :output-functions
  ((model-inputs
    ()
    (with-html-output (*stream* nil :indent t)
      (htm ((:table  :cellpadding 0)
            (:tr ((:td :colspan 2) (:b "Dimensions:")))
            (dolist (slot (list :width :length :height))
              (htm 
               (:tr ((:td :bgcolor :yellow)
                     (str (string-capitalize slot)))
                    (:td ((:input :type :string :name slot :size 5
                                  :value (format nil "~a" 
                                                 (the (evaluate slot)))))))))
      
            ((:input :type :hidden :value "hidden value" :name :hidden-field))
      
            (:tr ((:td :colspan 2) :br))
            (:tr ((:td :colspan 2) (:b "Angles:")))
            (dolist (angle '(("Head" :head-angle)("Body" :body-angle)
                             ("Left Arm" :arm-angle-left) 
                             ("Right Arm" :arm-angle-right)))
              (htm
               (:tr ((:td :bgcolor :yellow) 
                     (htm (str (first angle))))
                    (:td ((:input 
                           :type :string :name (second angle) 
                           :size 5 :value 
                           (format nil "~a" (the (evaluate (second angle))))))))))
            (:tr ((:td :colspan 2) :br))
            (:tr ((:td :colspan 2) (:b "Grip Opening:")))
            (dolist (side (list :left :right))
              (htm
               (:tr 
                ((:td :bgcolor :yellow) (str (string-capitalize side)))
                (:td 
                 ((:input 
                   :type :string 
                   :name (format nil "pincer-distance-~a" side) 
                   :size 5 
                   :value 
                   (the (evaluate (make-keyword 
                                   (format nil "pincer-distance-~a" side))))))))))
            (:tr ((:td :colspan 2) :br))
            (:tr ((:td :colspan 2 :align :center)
                  ((:input :type :submit :value " OK " :name :refresh))))))))))


(define-lens (html-format assembly)()
  :output-functions
  ((model-inputs
    ()
    (html 
     ((:table  :cellpadding 0)
      (:tr ((:td :colspan 2) (:b "Dimensions:")))
      (dolist (slot (list :width :length :height))
        (html 
         (:tr ((:td :bgcolor :yellow)
               (:princ (string-capitalize slot)))
              (:td ((:input :type :string :name slot :size 5
                            :value (format nil "~a" 
                                           (the (evaluate slot)))))))))
      
      ((:input :type :hidden :value "hidden value" :name :hidden-field))
      
      (:tr ((:td :colspan 2) :br))
      (:tr ((:td :colspan 2) (:b "Angles:")))
      (dolist (angle '(("Head" :head-angle)("Body" :body-angle)
                       ("Left Arm" :arm-angle-left) 
                       ("Right Arm" :arm-angle-right)))
        (html
         (:tr ((:td :bgcolor :yellow) 
               (html (:princ (first angle))))
              (:td ((:input 
                     :type :string :name (second angle) 
                     :size 5 :value 
                     (format nil "~a" (the (evaluate (second angle))))))))))
      (:tr ((:td :colspan 2) :br))
      (:tr ((:td :colspan 2) (:b "Grip Opening:")))
      (dolist (side (list :left :right))
        (html
         (:tr 
          ((:td :bgcolor :yellow) (:princ (string-capitalize side)))
          (:td 
           ((:input 
             :type :string 
             :name (format nil "pincer-distance-~a" side) 
             :size 5 
             :value 
             (the (evaluate (make-keyword 
                             (format nil "pincer-distance-~a" side))))))))))
      (:tr ((:td :colspan 2) :br))
      (:tr ((:td :colspan 2 :align :center)
            ((:input :type :submit :value " OK " :name :refresh)))))))))



(define-object robot (base-object)

  :input-slots
  ((torso-type 'box :settable)
   head-angle
   body-angle
   arm-angle-right
   arm-angle-left
   pincer-distance-right
196
197
198
   pincer-distance-left
   shininess transparency
   )
199
200
201
202
203
204
205
206
207

  :computed-slots
  ((display-controls (list  :color :orange :line-thickness 2 
                            :transparency (the transparency) 
                            :shininess (the shininess) )))


  :objects
  ((base :type 'robot-base
Dave Cooper's avatar
Dave Cooper committed
208
         :display-controls (merge-display-controls (list :color :blue-sky))
209
         :height (* (the height) 0.4)
Dave Cooper's avatar
Dave Cooper committed
210
211
         :width (* (the width) 0.2)
         :length (* (the length) 0.2)
212
213
214
215
216
217
218
219
220
221
222
         :center (translate (the :center) :down (* (the :height) 0.3)))
   (body :type 'robot-body
         :height (* (the :height) 0.6)
         :center (translate (the :center) :up (* (the :height) 0.2))
         :orientation (alignment :right
                                 (rotate-vector-d 
                                  (the (:face-normal-vector :right))
                                  (the :body-angle)
                                  (the (:face-normal-vector :top))))
         :pass-down (head-angle torso-type
                     arm-angle-right arm-angle-left 
223
224
225
226
                     pincer-distance-left pincer-distance-right))


   ))
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290


(define-object robot-body (base-object)
  :input-slots
  ((torso-type 'box)
   head-angle arm-angle-left arm-angle-right
   pincer-distance-left pincer-distance-right
   (shoulder-height (* (the :torso :height) 0.1)))


  :objects
  ((torso :type (the torso-type)
          :height (* (the :height) 0.85)
          :width (* (the :width) 0.7)
          :radius (half (the-child width))
          :center (translate (the :center) 
                             :down (- (half (the :height)) 
                                      (half (the-child :height)))))
   
   (arms :type 'robot-arm :sequence (:size 2)
         :side (ecase (the-child :index) (0 :left) (1 :right))
         :display-controls (merge-display-controls 
                            (list :transparency 0 
                                  :color (ecase (the-child index)
                                           (0 :green-spring-medium)
                                           (1 :red))))
         :width (half (- (the :width) (the :torso :width)))
         :length (/ (the :length) 3)
         :height (- (the :torso :height) (twice (the :shoulder-height)))
         
         :center (translate-along-vector 
                  (the-child :shoulder-point)
                  (the-child (:face-normal-vector :bottom)) 
                  (half (the-child :height)))
         :orientation 
         (alignment :bottom
                    (rotate-vector-d (the (:face-normal-vector :bottom))
                                     (the-child :angle)
                                     (the (:face-normal-vector :left)))
                    :right (the (:face-normal-vector :right)))
         :shoulder-point 
         (translate (the :torso (:edge-center :top (the-child :side)))
                    (the-child :side) (half (the-child :width)) :down
                    (the :shoulder-height))
         :angle (ecase (the-child :side) (:left (the :arm-angle-left))
                       (:right (the :arm-angle-right)))
         :pincer-distance (ecase (the-child :side) 
                            (:left (the :pincer-distance-left))
                            (:right (the :pincer-distance-right))))
   
   
   (head :type 'box 
         :height (- (the :height) (the :torso :height))
         :width (* (the :width) 0.25) :length (half (the :length))
         :center (translate (the :center) :up
                            (- (half (the :height)) (half (the-child :height))))
         
         
         :display-controls (merge-display-controls (list :color :black :transparency 0))
         :orientation (alignment :right
                                 (rotate-vector-d 
                                  (the (:face-normal-vector :right))
                                  (the :head-angle)
                                  (the (:face-normal-vector :top)))))
291
292
293



294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
   
   ))


(define-object robot-arm (base-object)

  :input-slots
  (side
   shoulder-point
   angle
   pincer-distance
   
 )

  :objects
  ((arm :type 'box)
   

   (thumb :type 'box
          :width (the :hand :width)
          :height (the :hand :height)
          :length (the :hand :length)
          :center (translate (the :hand :center) 
                             (the :side) (the :pincer-distance)))
   (hand :type 'box
         :display-controls (merge-display-controls (list :color :black :transparency 0))
         :center (translate (the :center) :down
                            (+ (half (the :height)) 
                               (half (the-child :height)))
                            (the :side)
                            (- (- (half (the :width)) 
                                  (half (the-child :width)))))
         :height (* (the :height) 0.15)
         :width (* (the :width) 0.2)
         :length (half (the :length)))))
  

(define-object robot-base (base-object)

  
  :objects
  ((leg :type 'box
        :height (* 0.9 (the :height))
        :center (translate (the :center) :up
                           (- (half (the :height)) 
                              (half (the-child :height)))))
   (foot :type 'box
         :height (* 0.1 (the :height))
         :width (twice (twice (the :width)))
         :length (twice (twice (twice (the :length))))
         :center (translate (the :center) :down
                            (- (half (the :height)) 
                               (half (the-child :height)))))))

#+nil
(publish :path "/demos/roboti"
         :function 
         #'(lambda(req ent)
             (gwl-make-object req ent "robot:assembly"  :skin 'gwl:infinite)))



(publish :path "/demos/robot"
         :function 
         #'(lambda(req ent)
             (gwl-make-object req ent "robot:assembly")))