HeRoS: read out and log joint angles and force sensor data from the leg test bench. Now with additional features to read pressure sensors and set the null values of the pressure and force sensors

Dependents:   heros_leg_readout_torque_addition heros_leg_readout_torque_addition_V3

Fork of LCM101 by K K

Committer:
cnckiwi31
Date:
Mon Oct 26 08:27:12 2020 +0000
Revision:
4:f7af875abe50
Parent:
3:22f8cfcad8d6
Prepared for documentation with copyright boilerplate added

Who changed what in which revision?

UserRevisionLine numberNew contents of line
cnckiwi31 4:f7af875abe50 1 /* Copyright 2017 Martijn Grootens
cnckiwi31 4:f7af875abe50 2
cnckiwi31 4:f7af875abe50 3 Licensed under the Apache License, Version 2.0 (the "License");
cnckiwi31 4:f7af875abe50 4 you may not use this file except in compliance with the License.
cnckiwi31 4:f7af875abe50 5 You may obtain a copy of the License at
cnckiwi31 4:f7af875abe50 6
cnckiwi31 4:f7af875abe50 7 http://www.apache.org/licenses/LICENSE-2.0
cnckiwi31 4:f7af875abe50 8
cnckiwi31 4:f7af875abe50 9 Unless required by applicable law or agreed to in writing, software
cnckiwi31 4:f7af875abe50 10 distributed under the License is distributed on an "AS IS" BASIS,
cnckiwi31 4:f7af875abe50 11 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
cnckiwi31 4:f7af875abe50 12 See the License for the specific language governing permissions and
cnckiwi31 4:f7af875abe50 13 limitations under the License.
cnckiwi31 4:f7af875abe50 14 */
cnckiwi31 4:f7af875abe50 15
megrootens 0:116acb03eb85 16 #ifndef _LCM101_H_
megrootens 0:116acb03eb85 17 #define _LCM101_H_
megrootens 0:116acb03eb85 18
megrootens 0:116acb03eb85 19 #include "mbed.h"
megrootens 0:116acb03eb85 20
megrootens 0:116acb03eb85 21 /**
cnckiwi31 4:f7af875abe50 22 * Simple class to read out an Omega LCM101 S-beam force sensor connected to an analog
megrootens 0:116acb03eb85 23 * input.
megrootens 0:116acb03eb85 24 */
megrootens 0:116acb03eb85 25 class Lcm101 {
megrootens 0:116acb03eb85 26 public:
megrootens 0:116acb03eb85 27
cnckiwi31 4:f7af875abe50 28 /** constructor
cnckiwi31 4:f7af875abe50 29 * @param pin_a_in: PinName of analog input
cnckiwi31 4:f7af875abe50 30 * @param offset: linear scaling offset for analog value read from sensor(calibration data)
cnckiwi31 4:f7af875abe50 31 * @param factor: multiplication factor for analog value read from sensor(calibration data)
megrootens 0:116acb03eb85 32 */
megrootens 0:116acb03eb85 33 Lcm101(PinName pin_a_in, float offset, float factor) :
megrootens 0:116acb03eb85 34 analog_in_(pin_a_in),
megrootens 0:116acb03eb85 35 kOffset_(offset),
megrootens 0:116acb03eb85 36 kFactor_(factor)
megrootens 0:116acb03eb85 37 {
megrootens 0:116acb03eb85 38 }
megrootens 0:116acb03eb85 39
megrootens 0:116acb03eb85 40 /**
megrootens 0:116acb03eb85 41 * @return unscaled analog input value
megrootens 0:116acb03eb85 42 */
megrootens 0:116acb03eb85 43 float getForceRaw()
megrootens 0:116acb03eb85 44 {
megrootens 0:116acb03eb85 45 return analog_in_.read();
megrootens 0:116acb03eb85 46 }
megrootens 0:116acb03eb85 47
megrootens 0:116acb03eb85 48 /**
megrootens 0:116acb03eb85 49 * @return force value kOffset_ + kFactor_ * getForceRaw();
megrootens 0:116acb03eb85 50 */
megrootens 0:116acb03eb85 51 float getForce()
megrootens 0:116acb03eb85 52 {
megrootens 0:116acb03eb85 53 return kOffset_ + kFactor_ * getForceRaw();
Technical_Muffin 2:77cffacfd89e 54 //it appears that higher order polynomials show better accuracy, within the 40 kg range that is.
Technical_Muffin 2:77cffacfd89e 55 // Awaiting other instructions, a linear fit will be currently used however.
megrootens 0:116acb03eb85 56 }
megrootens 0:116acb03eb85 57
megrootens 0:116acb03eb85 58 /**
cnckiwi31 3:22f8cfcad8d6 59 * sets force scaling offset so that current output is force zero
cnckiwi31 3:22f8cfcad8d6 60 */
cnckiwi31 3:22f8cfcad8d6 61 void nullForce()
cnckiwi31 3:22f8cfcad8d6 62 {
cnckiwi31 3:22f8cfcad8d6 63 kOffset_ = kOffset_ - getForce();
cnckiwi31 3:22f8cfcad8d6 64 return;
cnckiwi31 3:22f8cfcad8d6 65 }
cnckiwi31 3:22f8cfcad8d6 66
cnckiwi31 3:22f8cfcad8d6 67 /**
cnckiwi31 4:f7af875abe50 68 * @return offset of analog value
megrootens 0:116acb03eb85 69 */
megrootens 0:116acb03eb85 70 float get_offset() { return kOffset_; }
megrootens 0:116acb03eb85 71
megrootens 0:116acb03eb85 72 /**
megrootens 0:116acb03eb85 73 * @return factor multiplication factor for analog value
megrootens 0:116acb03eb85 74 */
megrootens 0:116acb03eb85 75 float get_factor() { return kFactor_; }
megrootens 0:116acb03eb85 76
megrootens 0:116acb03eb85 77
megrootens 0:116acb03eb85 78 private:
megrootens 0:116acb03eb85 79 AnalogIn analog_in_;
megrootens 0:116acb03eb85 80
cnckiwi31 3:22f8cfcad8d6 81 float kOffset_;
megrootens 0:116acb03eb85 82 const float kFactor_;
megrootens 0:116acb03eb85 83 };
megrootens 0:116acb03eb85 84
megrootens 0:116acb03eb85 85 #endif