Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The amc2c binary moves a motor using CAN communication #426

Merged
merged 19 commits into from
Oct 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
636 changes: 164 additions & 472 deletions emBODY/eBcode/arch-arm/board/amc2c/application/proj/amc2c-appl-can.uvoptx

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ namespace embot::app::board::amc2c::info {

constexpr embot::prot::can::applicationInfo applInfo
{
embot::prot::can::versionOfAPPLICATION {100, 100, 0},
embot::prot::can::versionOfAPPLICATION {2, 0, 4},
embot::prot::can::versionOfCANPROTOCOL {2, 0}
};

constexpr embot::app::eth::Date date
{
2023, embot::app::eth::Month::Apr, embot::app::eth::Day::fourteen, 16, 54
2023, embot::app::eth::Month::Oct, embot::app::eth::Day::sixteen, 15, 51
};

constexpr embot::hw::FLASHpartitionID codePartition
Expand All @@ -46,10 +46,19 @@ namespace embot::app::board::amc2c::info {
{
embot::hw::CAN::two
};

constexpr uint8_t canaddress {3};

// marco.accame: i use the macro INFO32 just because ... i want to init eEmoduleExtendedInfo_t::userdefined with the same string
// and i dont know how to fit it inside otherwise

// 0123456789abcde0123456789abcde
#define INFO32 "hi, i am an amc2c on CAN2:3"

static const char *info32
constexpr const char *info32
{ // 0123456789abcde0123456789abcde
"hi, i am an amc2c can"
//"hi, i am an amc2c CAN2:3"
INFO32
};

} // embot::app::board::amc2c::info {
Expand All @@ -74,7 +83,7 @@ namespace embot::app::board::amc2c::info {
if(!initted)
{
force_placement_of_moduleinfo();
embot::app::board::amc2c::theCANagentCORE::getInstance().initialise({applInfo, canBus, info32});
embot::app::board::amc2c::theCANagentCORE::getInstance().initialise({applInfo, canBus, canaddress, info32});
initted = true;
}
return &embot::app::board::amc2c::theCANagentCORE::getInstance();
Expand Down Expand Up @@ -139,22 +148,23 @@ constexpr eEmoduleExtendedInfo_t s_cm4app_info_extended __attribute__((section(E
.size = 0,
.addr = 0
},
.communication = ee_commtype_none,
.communication = ee_commtype_can2,
.name = "eOther01"
},
.protocols =
{
.udpprotversion = { .major = 0, .minor = 0},
.can1protversion = { .major = 0, .minor = 0},
.can2protversion = { .major = 0, .minor = 0},
.can2protversion = { .major = 2, .minor = 0},
.gtwprotversion = { .major = 0, .minor = 0}
},
.extra = {"EXT"}
},
.compilationdatetime = __DATE__ " " __TIME__,
.userdefined = {0}
.userdefined = {INFO32}
};


#include <cstring>

eEmoduleExtendedInfo_t ss {};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,10 @@ bool embot::app::board::amc2c::theCANagentCORE::Impl::initialise(const Config &c

std::memmove(_storedinfo.info32, _config.boardinfo, sizeof(_storedinfo.info32));

_storedinfo.canaddress = _config.canaddress;

_board = static_cast<embot::prot::can::Board>(_storedinfo.boardtype);
// _address = _storedinfo.canaddress;

_applicationinfo.version.major = _storedinfo.applicationVmajor;
_applicationinfo.version.minor = _storedinfo.applicationVminor;
_applicationinfo.version.build = _storedinfo.applicationVbuild;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,11 @@ namespace embot::app::board::amc2c {
{
embot::prot::can::applicationInfo applicationinfo {{0,0,1}, {2,0}};
embot::hw::CAN canbus {embot::hw::CAN::one};
uint8_t canaddress {3};
const char *boardinfo {"hello, i am an amc2c"};
constexpr Config() = default;
constexpr Config(const embot::prot::can::applicationInfo& ai, embot::hw::CAN b, const char *bi)
: applicationinfo(ai), canbus(b), boardinfo(bi) {}
constexpr Config(const embot::prot::can::applicationInfo& ai, embot::hw::CAN b, uint8_t ca, const char *bi)
: applicationinfo(ai), canbus(b), canaddress(ca), boardinfo(bi) {}
};

bool initialise(const Config &config);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -520,23 +520,17 @@ dbgFOCvalues dbgFOC {};

void embot::app::board::amc2c::theMBD::Impl::onCurrents_FOC_innerloop(void *owner, const embot::hw::motor::Currents * const currents)
{
embot::hw::testpoint::on(tp2);

//embot::hw::testpoint::on(tp2);
Impl * impl = reinterpret_cast<Impl*>(owner);
if((nullptr == impl) || (nullptr == currents))
{
return;
}

impl->measureFOC->start();
// impl->measureFOC->start();

// 1. copy currents straight away, so that we can use them
embot::hw::motor::Currents currs = *currents;

#if defined(TEST_DURATION_FOC)
embot::hw::sys::delay(25);
#else

// remember to manage impl->EXTFAULTisPRESSED ............

Expand Down Expand Up @@ -568,78 +562,24 @@ void embot::app::board::amc2c::theMBD::Impl::onCurrents_FOC_innerloop(void *owne
AMC_BLDC_U.SensorsData_p.motorsensors.Iabc[2] = 0.001f*currs.w;

// -----------------------------------------------------------------------------
// FOC Step Function (~26.6 KHz)
// FOC Step Function (~16.6 KHz)
// -----------------------------------------------------------------------------

AMC_BLDC_step_FOC();
AMC_BLDC_step1();

// -----------------------------------------------------------------------------

AMC_BLDC_U.SensorsData_p.jointpositions.position = static_cast<real32_T>(position) * 0.0054931640625f; // iCubDegree -> deg
//constexpr float coneversion2pwmvalue (163.83F);
constexpr float coneversion2pwmvalue (12.19F);

// Set the voltages
int32_T Vabc0 = static_cast<int32_T>(AMC_BLDC_Y.ControlOutputs_p.Vabc[0] * coneversion2pwmvalue);
int32_T Vabc1 = static_cast<int32_T>(AMC_BLDC_Y.ControlOutputs_p.Vabc[1] * coneversion2pwmvalue);
int32_T Vabc2 = static_cast<int32_T>(AMC_BLDC_Y.ControlOutputs_p.Vabc[2] * coneversion2pwmvalue);

#if defined(TEST_FOC_logvalues)

dbgFOC.currents = currs;
dbgFOC.hall = hall;
dbgFOC.electricalangle = electricalAngle;
dbgFOC.position = position;
dbgFOC.jointangle = static_cast<float>(position) * 0.0054931640625f;
dbgFOC.pwms = {Vabc0, Vabc1, Vabc2};

#endif
// TODO: Remove, used only for debug
// 0% PWM value on phase Vabc2 = 0,0,0
// 10% PWM value on phase Vabc2 = 0,0,122
// 20% PWM value on phase Vabc2 = 0,0,244
// 30% PWM value on phase Vabc2 = 0,0,366

embot::hw::motor::setpwm(embot::hw::MOTOR::one, 0, 0, 122);


//#define DEBUG_PARAMS
#ifdef DEBUG_PARAMS

static char msg2[64];
static uint32_t counter;
if(counter % 10 == 0)
embot::hw::motor::PWMperc pwmperc
{
sprintf(msg2, "%d,%d,%d,%.3f,%.3f,%.3f,%.3f,%.3f,%.3f,%.3f,%.3f", \
Vabc0, \
Vabc1, \
Vabc2, \
AMC_BLDC_U.SensorsData_p.motorsensors.Iabc[0], \
AMC_BLDC_U.SensorsData_p.motorsensors.Iabc[1], \
AMC_BLDC_U.SensorsData_p.motorsensors.Iabc[2], \
AMC_BLDC_U.SensorsData_p.motorsensors.angle, \
AMC_BLDC_Y.EstimatedData_p.jointvelocities.velocity, \
AMC_BLDC_B.Targets_n.motorcurrent.current, \
AMC_BLDC_Y.ControlOutputs_p.Iq_fbk.current, \
AMC_BLDC_Y.ControlOutputs_p.Vq);

// sprintf(msg2, "%d,%d,%d,%.3f,%.3f,%.3f", \
// Vabc0, \
// Vabc1, \
// Vabc2, \
// AMC_BLDC_U.SensorsData_p.motorsensors.Iabc[0], \
// AMC_BLDC_U.SensorsData_p.motorsensors.Iabc[1], \
// AMC_BLDC_U.SensorsData_p.motorsensors.Iabc[2]);
embot::core::print(msg2);
counter = 0;
}
counter++;
#endif
AMC_BLDC_Y.ControlOutputs_p.Vabc[0], AMC_BLDC_Y.ControlOutputs_p.Vabc[1], AMC_BLDC_Y.ControlOutputs_p.Vabc[2]
};
embot::hw::motor::setPWM(embot::hw::MOTOR::one, pwmperc);


#endif // #if defined(TEST_DURATION_FOC)

impl->measureFOC->stop();
embot::hw::testpoint::off(tp2);
// impl->measureFOC->stop();
}

#ifdef PRINT_HISTO_DEBUG
Expand Down
Loading