Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
AccCar.cpp
00001 //#include "AccCar.h" 00002 //#include "signal_wrapper.h" 00003 // 00004 //// Update is running at 1000ms (1 second cycles) 00005 //#define TICK 1000 00006 // 00007 //// Acc monitors 17 meters ahead 00008 //#define MONITOR_DIST 17 00009 // 00010 //// Acc maintains a safety gap of 2 meters 00011 //#define SAFETY_GAP 2 00012 // 00013 // 00014 //extern int car_position; 00015 // 00016 //AccCar::AccCar(int id) { 00017 // this->id = id; 00018 // 00019 // // Include any other necessary initialization 00020 // // ... 00021 // // ... 00022 // 00023 // thread = NULL; // Initialize thread to null, since the starting of the simulation is done in reset(-) 00024 //} 00025 // 00026 //int AccCar::acc_is_simulating() 00027 //{ 00028 // return acc_simulation; 00029 //} 00030 // 00031 //void AccCar::update_pos() 00032 //{ 00033 // // where should we be? in case we have already been adjusting our speed 00034 // int assigned_position = this->position+this->assigned_speed; 00035 // 00036 // int desired_speed; 00037 // int desired_position; 00038 // 00039 // if( assigned_position >= ( car_position - SAFETY_GAP ) ) 00040 // { 00041 // // no we can not find the max speed we can go 00042 // // find the speed we can safely go this will ALWAYS be SAFETY_GAP or more in the negative direction 00043 // int speed_diff = car_position - (assigned_position + SAFETY_GAP); 00044 // assert(speed_diff <= SAFETY_GAP); 00045 // // set desired speed 00046 // desired_speed = speed_diff + this->assigned_speed; 00047 // // adjust our speed to not collide 00048 // desired_position = desired_speed + this->position; 00049 // 00050 // //printf(" adjusted max speed to not collide %d -> %d \r\n",desired_position,desired_speed); 00051 // } 00052 // // last condition saying we can go assigned speed 00053 // else if( assigned_position <= (car_position - SAFETY_GAP ) ) 00054 // { 00055 // desired_position = this->assigned_speed + this->position; 00056 // desired_speed = this->assigned_speed; 00057 // //printf("max speed!!! %d -> %d \r\n",desired_position,desired_speed); 00058 // } 00059 // // crash, we should not enter 00060 // else 00061 // { 00062 // assert(0); 00063 // } 00064 // 00065 // this->position = desired_position; 00066 // this->speed = desired_speed; 00067 //} 00068 // 00069 //void AccCar::update() { 00070 // while (true) { 00071 // 00072 // // wait for the signal from the main thread to update 00073 // uint32_t flags = wait_for_signal( ACC_SIGNAL ); 00074 // if( flags == ACC_SIGNAL ) 00075 // { 00076 // update_pos(); 00077 // } 00078 // else 00079 // { 00080 // assert(0); 00081 // } 00082 // 00083 // if(this->position >= ROADLENGTH) 00084 // { 00085 // // notify to end simulation and terminate yourself 00086 // acc_simulation = 0; 00087 // send_signal( ACC_UPDATE_MAIN_SIGNAL ); 00088 // assert( thread->terminate() == MBED_SUCCESS ); 00089 // } 00090 // 00091 // // return to car thread he will notify main 00092 // send_signal( ACC_UPDATE_MAIN_SIGNAL ); 00093 // } 00094 //} 00095 // 00096 //void AccCar::reset(int speed) { 00097 // // handle any necessary coordination with main thread 00098 // 00099 // // reset any other attributes that may be necessary 00100 // // ... 00101 // // ... 00102 // 00103 // if (thread != NULL) { // Clear out the existing thread, if it exists, since we don't know how long it has waited for 00104 // delete thread; 00105 // } 00106 // 00107 // thread = new Thread(); // Create a new thread for the car 00108 // thread->start( callback(this, &AccCar::update) ); // Start the thread with the car's update method 00109 // 00110 // acc_simulation = 1; 00111 // this->position = 0; 00112 // this->speed = speed; 00113 // this->assigned_speed = speed; 00114 //}
Generated on Thu Jul 14 2022 17:18:57 by
1.7.2