Subversion Repositories programming

Rev

Rev 329 | Rev 331 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 329 Rev 330
Line 132... Line 132...
132
 
132
 
133
            /* Decide if we should stop at the floor we're at */
133
            /* Decide if we should stop at the floor we're at */
134
            if (should_stop_at_current_floor ())
134
            if (should_stop_at_current_floor ())
135
            {
135
            {
136
                debug_puts ("stop at a floor -- while going up");
136
                debug_puts ("stop at a floor -- while going up");
137
                stop_at_floors[(int)current_floor] = false;
137
                stop_at_floors[(int)(current_floor+0.5)] = false;
138
            }
138
            }
139
 
139
 
140
            /* Decide to sit idle if we have no more floors to stop at */
140
            /* Decide to sit idle if we have no more floors to stop at */
141
            if (!has_floors_to_stop_at ())
141
            if (!has_floors_to_stop_at ())
142
            {
142
            {
Line 168... Line 168...
168
 
168
 
169
            /* Decide if we should stop at the floor we're at */
169
            /* Decide if we should stop at the floor we're at */
170
            if (should_stop_at_current_floor ())
170
            if (should_stop_at_current_floor ())
171
            {
171
            {
172
                debug_puts ("stop at floor -- while going down");
172
                debug_puts ("stop at floor -- while going down");
173
                stop_at_floors[(int)current_floor] = false;
173
                stop_at_floors[(int)(current_floor)] = false;
174
            }
174
            }
175
 
175
 
176
            /* Decide to sit idle if we have no more floors to stop at */
176
            /* Decide to sit idle if we have no more floors to stop at */
177
            if (!has_floors_to_stop_at ())
177
            if (!has_floors_to_stop_at ())
178
            {
178
            {
Line 231... Line 231...
231
    this->pause = false;
231
    this->pause = false;
232
}
232
}
233
 
233
 
234
bool Elevator::near_a_floor ()
234
bool Elevator::near_a_floor ()
235
{
235
{
236
    const float range = ELEVATOR_TIME_MOVE_AMOUNT / 2.0;
236
    int i;
237
 
237
 
238
    /* This seems somewhat counter-intuitive, but it's really not.
-
 
239
     * If we are near a floor, then one of the two of these will fail.
-
 
240
     *
-
 
241
     * Example:
-
 
242
     * current_floor = 3.001;
238
    for (i=1; i<=num_floors; i++)
243
     * first part is: 3 == 3   (true)
-
 
244
     * second part is: 3 == 2  (false)
-
 
245
     *
-
 
246
     * Therefore we return true
239
        if (near_floor (i))
247
     */
-
 
248
    if ((int)current_floor == (int)(current_floor + range) &&
-
 
249
        (int)current_floor == (int)(current_floor - range))
-
 
250
    {
-
 
251
        return false;
240
            return true;
252
    }
-
 
253
 
241
 
254
    return true;
242
    return false;
255
}
243
}
256
 
244
 
257
bool Elevator::near_floor (int floor)
245
bool Elevator::near_floor (int floor)
258
{
246
{
-
 
247
    const float thresh  = ELEVATOR_TIME_MOVE_AMOUNT / 2.0;
-
 
248
    const float greater = floor + thresh;
-
 
249
    const float lower   = floor - thresh;
-
 
250
 
259
    if (near_a_floor () && floor == (int)current_floor)
251
    if (current_floor > lower && current_floor < greater)
260
        return true;
252
        return true;
261
 
253
 
262
    return false;
254
    return false;
263
}
255
}
264
 
256