Changeset 224 in flair-src for trunk/lib/FlairSensorActuator/src/SimuBldc.cpp
- Timestamp:
- 03/06/18 12:12:58 (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/lib/FlairSensorActuator/src/SimuBldc.cpp
r214 r224 50 50 } 51 51 52 SimuBldc::SimuBldc(const Object *parent, string name, uint8_t motors_count,53 uint32_t modelId,uint32_t deviceId)54 : Bldc(parent, name, motors_count) {55 shmem =56 new SharedMem(this, ShMemName(modelId, deviceId), motors_count * sizeof(float)+sizeof(Time));57 58 buf=(char*)malloc(motors_count * sizeof(float)+sizeof(Time));59 if(buf==NULL) {60 Err("error creating buffer\n");61 return;62 }63 64 // reset values65 float *values=(float*)buf;66 for (int i = 0; i < motors_count; i++) values[i] = 0;67 Time time=GetTime();68 memcpy(buf+motors_count * sizeof(float),&time,sizeof(Time));69 70 shmem->Write(buf, motors_count * sizeof(float)+sizeof(Time));71 72 SetIsReady(true);73 }74 75 52 SimuBldc::~SimuBldc() { 76 53 if(buf!=NULL) free(buf); … … 99 76 } 100 77 101 void SimuBldc::GetSpeeds(float *value,Time* time) const {102 float *values=(float*)buf;103 shmem->Read(buf, MotorsCount() * sizeof(float)+sizeof(Time));104 memcpy(time,buf+MotorsCount() * sizeof(float),sizeof(Time));105 106 for (int i = 0; i < MotorsCount(); i++) {107 value[i] = values[i];108 }109 }110 111 78 } // end namespace sensor 112 79 } // end namespace flair
Note:
See TracChangeset
for help on using the changeset viewer.