Code for the COVR project DROPSAW project test rig (previously used for the Heros testing).
Dependencies: SPTE_10Bar_5V mbed AS5048 SDFileSystem MODSERIAL LCM101_DROPSAW LinearActuator
bench.cpp
- Committer:
- cnckiwi31
- Date:
- 2018-10-12
- Revision:
- 4:1cdce6c6c94e
- Parent:
- 0:3855d4588f76
- Child:
- 5:63063a9fa51c
File content as of revision 4:1cdce6c6c94e:
#include "bench.h" /** * Create an object representing the testbench; the 4 AS5048 sensors * with the offsets specified by the constants kOffsetsDegrees[4] * @param mosi: mosi pin for sensor chain * @param miso: miso pin for sensor chain * @param sck: clock pin for sensor chain * @param cs: chip select pin for sensor chain * @param p_lcm101: analog input pin for load cell * @param p_spte0: analog input pin for pressure sensor 0 * @param p_spte1: analog input pin for pressure sensor 1 */ Bench::Bench(PinName mosi, PinName miso, PinName sck, PinName cs, PinName p_lcm101, PinName p_spte0, PinName p_spte1) : as5048_(mosi, miso, sck, cs, sensors::kNumJoints), lcm101_(p_lcm101, sensors::kLcm101Offset, sensors::kLcm101Factor), spte0(p_spte0, sensors::kSPTE0Offset, sensors::kSPTE0Factor), spte1(p_spte1, sensors::kSPTE1Offset, sensors::kSPTE1Factor) { for (int i=0; i<sensors::kNumJoints; ++i) { as5048_.setOffsetDegrees(i,sensors::kOffsetsDegrees[i]); as5048_.setDirection(i,sensors::kDirections[i]); } } /** * Update routine for the testbench. * - Updates the angle buffer of the sensor array * - ... that's it for now (add filtering?) * Note that angles lag one Update() behind, due to the way the SPI * protocol works. */ void Bench::Update() { as5048_.UpdateAngleBuffer(); } float Bench::getDegrees(int i_joint) { float ang = as5048_.getAngleDegrees(i_joint); if (ang>kCutOffDegrees) { return ang-As5048::kDegPerRev; } return ang; } /** * Obtain the joint angle in degrees. * These are the angles at the time of two Update() calls back * @param joint: the joint for which the angle is requested * @return: joint angle */ float Bench::getDegrees(Joint joint) { return getDegrees(joint); } float Bench::getRadians(int i_joint) { float ang = as5048_.getAngleRadians(i_joint); if (ang>kCutOffRadians) { return ang-As5048::kRadPerRev; } return ang; } /** * Obtain the joint angle in radians. * These are the angles at the time of two Update() calls back * @param joint: the joint for which the angle is requested * @return: joint angle */ float Bench::getRadians(Joint joint) { return getRadians(joint); } const char* Bench::getJointName(int i_joint) { return sensors::kJointNames[i_joint]; } const char* Bench::getJointName(Joint joint) { return getJointName(joint); } As5048* Bench::get_as5048() { return &as5048_; } float Bench::getForce() { return lcm101_.getForce(); } void Bench::nullForce() { return lcm101_.nullForce(); } float Bench::getPressure0() { return spte0.getPressure(); } void Bench::nullPressure0() { return spte0.nullPressure(); } float Bench::getPressure1() { return spte1.getPressure(); } void Bench::nullPressure1() { return spte1.nullPressure(); }