2nd try
Revision 3:29602f4ade5c, committed 2021-02-25
- Comitter:
- altb2
- Date:
- Thu Feb 25 20:28:16 2021 +0000
- Parent:
- 1:dd5d116ace8f
- Commit message:
- First commit of Mirror actuato, still under construction, pins should be ok, next: check path planner;
Changed in this revision
diff -r dd5d116ace8f -r 29602f4ade5c DiffCounter.cpp --- a/DiffCounter.cpp Thu Mar 07 09:16:03 2019 +0000 +++ b/DiffCounter.cpp Thu Feb 25 20:28:16 2021 +0000 @@ -16,7 +16,7 @@ a = -(2.0*(double)T - (double)Ts)/(2.0*(double)T + (double)Ts); incPast = 0; vel = 0.0; - inc2rad = 2.0*pi/(4.0*6400.0); // incr encoder with 6400inc/rev + inc2rad = 2.0*pi/(4000.0); // incr encoder with 6400inc/rev } DiffCounter::~DiffCounter() {}
diff -r dd5d116ace8f -r 29602f4ade5c EncoderCounterIndex.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/EncoderCounterIndex.cpp Thu Feb 25 20:28:16 2021 +0000 @@ -0,0 +1,39 @@ +/* + * EncoderCounterIndex.cpp + * Copyright (c) 2018, ZHAW + * All rights reserved. + * + * Created on: 13.08.2018 + * Author: Marcel Honegger + */ + +#include <stdint.h> +#include "EncoderCounter.h" +#include "EncoderCounterIndex.h" + +using namespace std; + +/** + * Creates an object with an interrupt service routine to catch + * the current encoder position when an index pulse is received. + */ +EncoderCounterIndex::EncoderCounterIndex(EncoderCounter& encoderCounter, InterruptIn& channelIndex) : encoderCounter(encoderCounter), channelIndex(channelIndex) { + + // attach interrupt + + channelIndex.rise(callback(this, &EncoderCounterIndex::rise)); +} + +EncoderCounterIndex::~EncoderCounterIndex() {} + +int32_t EncoderCounterIndex::getPositionAtIndexPulse() { + + return positionAtIndexPulse; +} + +void EncoderCounterIndex::rise() { + + positionAtIndexPulse = encoderCounter; +} + +
diff -r dd5d116ace8f -r 29602f4ade5c EncoderCounterIndex.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/EncoderCounterIndex.h Thu Feb 25 20:28:16 2021 +0000 @@ -0,0 +1,42 @@ +/* + * EncoderCounterIndex.h + * Copyright (c) 2018, ZHAW + * All rights reserved. + * + * Created on: 13.08.2018 + * Author: Marcel Honegger + */ + +#ifndef ENCODER_COUNTER_INDEX_H_ +#define ENCODER_COUNTER_INDEX_H_ + +#include <cstdlib> +#include <stdint.h> +#include <mbed.h> + +class EncoderCounter; + +/** + * The <code>EncoderCounterIndex</code> class implements an interrupt service routine + * to catch the current encoder position when an index pulse is received. + */ +class EncoderCounterIndex { + + public: + + EncoderCounterIndex(EncoderCounter& encoderCounter, InterruptIn& channelIndex); + virtual ~EncoderCounterIndex(); + int32_t getPositionAtIndexPulse(); + + private: + + EncoderCounter& encoderCounter; + InterruptIn& channelIndex; + int32_t positionAtIndexPulse; + + void rise(); +}; + +#endif /* ENCODER_COUNTER_INDEX_H_ */ + +
diff -r dd5d116ace8f -r 29602f4ade5c ThreadFlag.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ThreadFlag.cpp Thu Feb 25 20:28:16 2021 +0000 @@ -0,0 +1,57 @@ +/* + * ThreadFlag.cpp + * Copyright (c) 2019, ZHAW + * All rights reserved. + * + * Created on: 29.11.2019 + * Author: Marcel Honegger + */ + +#include "ThreadFlag.h" + +using namespace std; + +uint32_t ThreadFlag::threadFlags = 0; + +/** + * Creates a signal object and assignes a unique flag. + */ +ThreadFlag::ThreadFlag() { + + mutex.lock(); + + uint32_t n = 0; + while ((((1 << n) & threadFlags) > 0) && (n < 30)) n++; + threadFlag = (1 << n); + + mutex.unlock(); +} + +/** + * Deletes the signal object and releases the assigned flag. + */ +ThreadFlag::~ThreadFlag() { + + mutex.lock(); + + threadFlags &= ~threadFlag; + + mutex.unlock(); +} + +/** + * Gets the assigned thread flag. + */ +uint32_t ThreadFlag::read() { + + return threadFlag; +} + +/** + * The empty operator is a shorthand notation of the <code>read()</code> method. + */ +ThreadFlag::operator uint32_t() { + + return read(); +} +
diff -r dd5d116ace8f -r 29602f4ade5c ThreadFlag.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ThreadFlag.h Thu Feb 25 20:28:16 2021 +0000 @@ -0,0 +1,37 @@ +/* + * ThreadFlag.h + * Copyright (c) 2019, ZHAW + * All rights reserved. + * + * Created on: 29.11.2019 + * Author: Marcel Honegger + */ + +#ifndef THREAD_FLAG_H_ +#define THREAD_FLAG_H_ + +#include <cstdlib> +#include <stdint.h> +#include <mbed.h> + +/** + * This class manages the handling of unique thread flags to trigger rtos threads. + */ +class ThreadFlag { + + public: + + ThreadFlag(); + virtual ~ThreadFlag(); + virtual uint32_t read(); + operator uint32_t(); + + private: + + static uint32_t threadFlags; // variable that holds all assigned thread flags + uint32_t threadFlag; // thread flag of this object + Mutex mutex; // mutex to lock critical sections +}; + +#endif /* THREAD_FLAG_H_ */ +
diff -r dd5d116ace8f -r 29602f4ade5c Unwrapper_2pi.h --- a/Unwrapper_2pi.h Thu Mar 07 09:16:03 2019 +0000 +++ b/Unwrapper_2pi.h Thu Feb 25 20:28:16 2021 +0000 @@ -1,5 +1,6 @@ -/* -*/ +#ifndef UNWRAPPER_2PI_H_ +#define UNWRAPPER_2PI_H_ + using namespace std; @@ -24,3 +25,4 @@ float last_value; }; +#endif