Skip to content

Commit 41f31ff

Browse files
authored
Minor changes related to ForceSensor (#43)
* default calibration value is added * no controller mode and can parameter for sim is added * X2 Force sensor node id is fixed. Default calibration Offset value of 1500 is added. a new function to send SDO message for internal calibration is added. * small comment change * small change for pull request
1 parent d79c8cf commit 41f31ff

4 files changed

Lines changed: 34 additions & 4 deletions

File tree

config/x2_dynamic_params.cfg

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ gen.add("m_admittance", double_t, 2, "Admittance Mass", 5, 1, 20)
1212
gen.add("b_admittance", double_t, 3, "Admittance damper", 3, 0, 20)
1313

1414
interaction_enum = gen.enum([
15+
gen.const("no_control", int_t, 0, "controller 0"),
1516
gen.const("zero_torque", int_t, 1, "controller 1"),
1617
gen.const("zero_velocity", int_t, 2, "controller 2"),
1718
gen.const("ff_model_compensation", int_t, 3, "controller 3"),
@@ -21,6 +22,6 @@ interaction_enum = gen.enum([
2122
gen.const("chirp_torque", int_t, 7, "controller 7"),],
2223
"Test Parameters Mode")
2324

24-
gen.add("controller_mode", int_t, 0, "Controller Mode", 2, 1, 7, edit_method=interaction_enum)
25+
gen.add("controller_mode", int_t, 0, "Controller Mode", 0, 0, 7, edit_method=interaction_enum)
2526

2627
exit(gen.generate(PACKAGE, "CORC", "dynamic_params"))

src/hardware/IO/FourierForceSensor.cpp

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ FourierForceSensor::FourierForceSensor(int sensor_can_node_ID, double scale_fact
44
sensorNodeID(sensor_can_node_ID),
55
scaleFactor(scale_factor),
66
calibrated(false),
7-
calibrationTime(calib_time) {
7+
calibrationTime(calib_time),
8+
calibrationOffset(1500){
89
}
910

1011
bool FourierForceSensor::configureMasterPDOs() {
@@ -22,7 +23,7 @@ void FourierForceSensor::updateInput() {
2223
}
2324

2425
bool FourierForceSensor::calibrate(double calib_time) {
25-
spdlog::debug("[FourierForceSensor::calibrate]: Force Sensor {} Zeroing", sensorNodeID);
26+
spdlog::debug("[FourierForceSensor::calibrate]: Force Sensor with nodeID {} Zeroing", sensorNodeID);
2627

2728
if(calib_time>0) {
2829
calibrationTime = calib_time;
@@ -59,3 +60,24 @@ double FourierForceSensor::sensorValueToNewton(int sensorValue) {
5960
return (sensorValue - calibrationOffset) * scaleFactor;
6061
}
6162

63+
bool FourierForceSensor::sendInternalCalibrateSDOMessage() {
64+
65+
spdlog::debug("[FourierForceSensor::sendInternalCalibrateSDOMessage]: Force Sensor with nodeID {} Internal calibration", sensorNodeID);
66+
67+
std::stringstream sstream;
68+
char *returnMessage;
69+
70+
sstream << "[1] " << sensorNodeID << " read 0x7050 255 i8";
71+
std::string strCommand = sstream.str();
72+
char *SDO_Message = (char *)(strCommand.c_str());
73+
cancomm_socketFree(SDO_Message, &returnMessage);
74+
std::string retMsg = returnMessage;
75+
spdlog::debug(retMsg);
76+
if (retMsg.find("ERROR") != std::string::npos) {
77+
spdlog::error("[X2ForceSensor::calibrate]: Force Sensor {} error occured during zeroing", sensorNodeID);
78+
return false;
79+
}
80+
81+
sleep(1.5); // this is required because after calibration command, sensor values do not get update around 1.2 seconds
82+
}
83+

src/hardware/IO/FourierForceSensor.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,13 @@ class FourierForceSensor : public InputDevice {
5757
*/
5858
double getForce();
5959

60+
/**
61+
* send SDO command to shift the measurement to a value around 1500.
62+
*
63+
* \return bool success of internal calibration
64+
*/
65+
bool sendInternalCalibrateSDOMessage();
66+
6067
protected:
6168
virtual double sensorValueToNewton(int sensorValue);
6269

src/hardware/platforms/X2/X2Robot.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -477,7 +477,7 @@ bool X2Robot::initialiseInputs() {
477477
inputs.push_back(keyboard = new Keyboard());
478478

479479
for (int id = 0; id < X2_NUM_FORCE_SENSORS; id++) {
480-
forceSensors.push_back(new FourierForceSensor(id, x2Parameters.forceSensorScaleFactor[id]));
480+
forceSensors.push_back(new FourierForceSensor(id + 17, x2Parameters.forceSensorScaleFactor[id]));
481481
inputs.push_back(forceSensors[id]);
482482
}
483483

0 commit comments

Comments
 (0)