Commit 0ad502e0 authored by Bruno Laurencich's avatar Bruno Laurencich

add -x and --scan flags

parent 6a584016
......@@ -45,7 +45,7 @@
</Configuration>
<Armature>
<Mux Name="main" id="0">
0x77
0x73
<Branch Name="left" id="1">
CH_1
<K_Ceptor Name="Unico" id="2">
......
......@@ -373,6 +373,8 @@ namespace Chordata {
int hardware_concurrency;
bool wait;
bool raw;
bool calib;
bool scan;
int kc_ver;
int empirical_add;
......@@ -454,6 +456,12 @@ namespace Chordata {
static const char *wait = "Disable confirmation to start the program. By default Notochord will wait for a confirmation from the user.";
static const char *raw = "Transmit the raw lectures fron the K-Ceptors";
static const char *scan = "Scan the i2c port to create the Armature, instead of reading the configuration file";
static const char *calib = "Sensor calibration procedure. Notochord will perform a --scan, and calibrate the found K-Ceptor. It is adviced to plug just one KC to the Hub with this flag!!";
static const char *kc_ver = "The revision of the K-Ceptor hardware used.";
static const char *xml_g = "\nCONFIGURATION FILES:";
......
......@@ -174,7 +174,7 @@ void KC::bang(){
if ( setup_result == who_am_i){
setup = true;
comm::try_info("K_Ceptor {:.<12}: setup OK.", getLabel());
if (Chordata::getConf().raw){
if (Chordata::getConf().calib){
using lock = std::lock_guard<std::mutex>;
imu->calibrate(true);
std::copy(std::begin(imu->gBiasRaw), std::end(imu->gBiasRaw), std::begin(gyro_offsets));
......@@ -263,11 +263,12 @@ void KC::bang(){
imu->readAccel();
imu->readMag();
if (Chordata::getConf().calib){
Chordata::mag_lectures.push_back({imu->mx, imu->my, imu->mz});
}
//TODO: put this in another function, and choose btw them on startup
if (Chordata::getConf().raw){
Chordata::mag_lectures.push_back({imu->mx, imu->my, imu->mz});
if (Chordata::getConf().calib || Chordata::getConf().raw){
comm::transmit(fmt::format("{},{:d},{:d},{:d},{:d},{:d},{:d},{:d},{:d},{:d}",
osc_addr, imu->gx, imu->gy, imu->gz, imu->ax, imu->ay, imu->az, imu->mx, imu->my, imu->mz));
return;
......
......@@ -126,6 +126,11 @@ Configuration_Data Chordata::parse_cmd_line(int argc, const char **argv){
args::Flag version(parser, "version", msgs::version, {'V', "version"});
args::Flag wait(parser, "no_wait", msgs::wait, {'y', "yes"});
args::Flag raw(parser, "raw_lectures", msgs::wait, {'r', "raw"});
args::Flag scan(parser, "scan Armature", msgs::scan, {"scan"});
args::Flag calib(parser, "Calibrate", msgs::calib, {'x', "calibrate", "calib"});
args::ValueFlag<int> kc_ver(parser, "K_Ceptor revision", msgs::kc_ver, {'k', "kceptor"});
args::ValueFlag<int> empirical_add(parser, "Empirical ADD", "temporary parameter", {'E', "empirical_add"});
......@@ -181,6 +186,8 @@ Configuration_Data Chordata::parse_cmd_line(int argc, const char **argv){
conf.wait = (wait)? false : true;
conf.raw = (raw)? true : false;
conf.calib = (calib)? true : false;
conf.scan = (scan)? true : false;
conf.empirical_add = (empirical_add)? get(empirical_add) : 0;
if (kc_ver){
......@@ -462,7 +469,7 @@ Armature_Parser::armature_ptr Armature_Parser::getArmature(I2C_io *_i2c){
#define LSM9DS1_AG_ADDR 0x6B
Link* Armature_Parser::scanKCeptors(Link* first, std::string branch){
void Armature_Parser::scanKCeptors(Link* first, std::string branch){
Link* current = first;
for (int trans_val = 0; trans_val < 16; ++trans_val){
try{
......@@ -480,6 +487,8 @@ Link* Armature_Parser::scanKCeptors(Link* first, std::string branch){
if (!first)
first = current;
if (Chordata::getConf().calib) return;
}
} catch (const Chordata::IO_Error& e) {
......@@ -517,8 +526,10 @@ Armature_Parser::armature_ptr Armature_Parser::scanArmature(I2C_io *_i2c){
comm::try_info("Scan: [Base Mux] Hub, GATE: {}", branch_label);
scanKCeptors(the_branch, branch_label);
if (the_branch->getChild())
if (the_branch->getChild()){
scheluder->addNode( the_branch );
if (Chordata::getConf().calib) break;
}
}
} else { //No Hub, just scan for KCs
......
......@@ -153,7 +153,7 @@ namespace Chordata{
armature_ptr getArmature(I2C_io *_i2c);
armature_ptr scanArmature(I2C_io *_i2c);
Link* scanKCeptors(Link* first, std::string branch = "");
void scanKCeptors(Link* first, std::string branch = "");
Link * parseNode(tinyxml2::XMLElement*, Link * , int depth = 0);
......
......@@ -79,6 +79,8 @@ Chordata::Configuration_Data::Configuration_Data(): //from Chordata_def.h
hardware_concurrency(std::thread::hardware_concurrency()),
wait(true),
raw(false),
calib(false),
scan(false),
kc_ver(_KC_REV),
state({.beta_timer_init = 0, .imu_setup_complete = false})
{
......
......@@ -251,15 +251,12 @@ bool Notochord::createArmature(){
if (!i2c)
return false;
armature = aParser->getArmature(i2c);
return true;
}
bool Notochord::scanArmature(){
if (!i2c)
return false;
if (config.calib || config.scan){
armature = aParser->scanArmature(i2c);
} else {
armature = aParser->getArmature(i2c);
}
armature = aParser->scanArmature(i2c);
return true;
}
......@@ -311,13 +308,16 @@ bool Notochord::run(){
Chordata::getConf().comm.send_rate);
try{
std::thread t;
if (config.raw){ //if the raw flag is set, wait for an user imput to stop the timer
std::cout << "**Calibration mode**\n Enter the xor value of the node\n"_CHORDATA_DEF_PROMPT << std::endl;
std::cin >> user_xor_val;
std::cout << "Enter the label of the node\n"_CHORDATA_DEF_PROMPT << std::endl;
std::cin >> user_label;
if (config.raw && !config.calib){
std::cout << "**Raw data mode**\nThe lectures from the K-ceptors will be transmitted without any processing\n\n"\
"Using this flag for calibration is deprecated! use --calibrate instead\n\n"\
"Press a key to continue..." << std::endl;
std::cin.ignore();
}
if (config.calib){ //if the raw flag is set, wait for an user imput to stop the timer
std::cout << "Initilizing callibration procedure,\n1. Put the KCEPTOR facing up in a flat surface." << std::endl;
std::cout << "2.Press a key to begin calibration..\n" _CHORDATA_DEF_PROMPT << std::endl;
......@@ -485,7 +485,7 @@ int main(int argc, char const *argv[])
print_banner(notochord);
comm::info("Notochord start @ {}", comm::timekeeper.initialTime());
comm::info("Verbosity level {}", notochord.getConf().comm.log_level);
comm::info("Verbosity level {}", (int) notochord.getConf().comm.log_level);
auto gpio = GPIO();
gpio.reset_translators();
......@@ -494,8 +494,7 @@ int main(int argc, char const *argv[])
return 1;
status = notochord.scanArmature();
// status = notochord.createArmature();
status = notochord.createArmature();
if (!status)
throw Chordata::Error("Can't create armature, i2c manager not set.");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment