Skip to content

Commit

Permalink
Can battery (#63)
Browse files Browse the repository at this point in the history
* first step

* new can battery type

* added canbattery

* missing

* fix

* fix

fix

* change board name and service name

* fix size problems

* fix

* fix

* minor fix

* fix for review

* fix for review

* fix for review

* fix version as PR request

* fix as PR comments
  • Loading branch information
Luca Tricerri authored Jul 29, 2022
1 parent e9d8baf commit bbb55d4
Show file tree
Hide file tree
Showing 17 changed files with 313 additions and 40 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
cmake_minimum_required(VERSION 3.12)

project(icub_firmware_shared
VERSION 1.25.1)
VERSION 1.26.0)

find_package(YCM 0.11.0 REQUIRED)

Expand Down
3 changes: 2 additions & 1 deletion can/canProtocolLib/iCubCanProto_classes.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,12 @@ extern "C" {
#define ICUBCANPROTO_CLASS_PERIODIC_ANALOGSENSOR 0x03
#define ICUBCANPROTO_CLASS_PERIODIC_SKIN 0x04
#define ICUBCANPROTO_CLASS_PERIODIC_INERTIALSENSOR 0x05
#define ICUBCANPROTO_CLASS_PERIODIC_BATTERY 0x06
#define ICUBCANPROTO_CLASS_BOOTLOADER 0x07
// marco.accame: is this macro ICUBCANPROTO_CLASS_MAXNUM used?
// if, so, after the addition of new class ICUBCANPROTO_CLASS_PERIODIC_INERTIALSENSOR, it should become 0x06
// (the ICUBCANPROTO_CLASS_BOOTLOADER is not strangely not counted).
#define ICUBCANPROTO_CLASS_MAXNUM 0x05
#define ICUBCANPROTO_CLASS_MAXNUM 0x07


// - declaration of public user-defined types -------------------------------------------------------------------------
Expand Down
2 changes: 2 additions & 0 deletions can/canProtocolLib/iCubCanProto_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ extern "C" {
#define ICUBCANPROTO_BOARDTYPE__MTB4W 16
#define ICUBCANPROTO_BOARDTYPE__PMC 17
#define ICUBCANPROTO_BOARDTYPE__AMCBLDC 18
#define ICUBCANPROTO_BOARDTYPE__BMS 19
#define ICUBCANPROTO_BOARDTYPE__UNKNOWN 255

// skin types
Expand Down Expand Up @@ -111,6 +112,7 @@ typedef enum
icubCanProto_boardType__mtb4w = ICUBCANPROTO_BOARDTYPE__MTB4W,
icubCanProto_boardType__pmc = ICUBCANPROTO_BOARDTYPE__PMC,
icubCanProto_boardType__amcbldc = ICUBCANPROTO_BOARDTYPE__AMCBLDC,
icubCanProto_boardType__bms = ICUBCANPROTO_BOARDTYPE__BMS,
icubCanProto_boardType__unknown = ICUBCANPROTO_BOARDTYPE__UNKNOWN
} icubCanProto_boardType_t;

Expand Down
33 changes: 32 additions & 1 deletion eth/embobj/plus/comm-v2/icub/EoAnalogSensors.c
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@ static const char * s_eoas_sensors_strings[] =
"eoas_temperature",
"eoas_psc_angle",
"eoas_pos_angle",
"eoas_ft"
"eoas_ft",
"eoas_battery"
}; EO_VERIFYsizeof(s_eoas_sensors_strings, eoas_sensors_numberof*sizeof(const char *));


Expand Down Expand Up @@ -426,13 +427,29 @@ extern const eObrd_info_t * eoas_temperature_setof_boardinfos_find(const eOas_te
//

static const eObrd_cantype_t s_eoas_ft_supportedboards_types[] = { eobrd_cantype_strain, eobrd_cantype_strain2 };
static const eObrd_cantype_t s_eoas_bms_supportedboards_types[] = { eobrd_cantype_bms };


extern uint8_t eoas_battery_supportedboards_numberof(void)
{
return sizeof(s_eoas_bms_supportedboards_types)/sizeof(eObrd_cantype_t);
}

extern uint8_t eoas_ft_supportedboards_numberof(void)
{
return sizeof(s_eoas_ft_supportedboards_types)/sizeof(eObrd_cantype_t);
}

extern eObrd_cantype_t eoas_battery_supportedboards_gettype(uint8_t pos)
{
if(pos >= eoas_battery_supportedboards_numberof())
{
return eobrd_cantype_none;
}

return s_eoas_bms_supportedboards_types[pos];
}

extern eObrd_cantype_t eoas_ft_supportedboards_gettype(uint8_t pos)
{
if(pos >= eoas_ft_supportedboards_numberof())
Expand All @@ -456,6 +473,20 @@ extern eObool_t eoas_ft_isboardvalid(eObrd_cantype_t boardtype)
return eobool_false;
}

extern eObool_t eoas_battery_isboardvalid(eObrd_cantype_t boardtype)
{
for(uint8_t n=0; n<eoas_battery_supportedboards_numberof(); n++)
{
if(boardtype == s_eoas_bms_supportedboards_types[n])
{
return eobool_true;
}
}

return eobool_false;
}


// --------------------------------------------------------------------------------------------------------------------
// - definition of extern hidden functions
// --------------------------------------------------------------------------------------------------------------------
Expand Down
70 changes: 64 additions & 6 deletions eth/embobj/plus/comm-v2/icub/EoAnalogSensors.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,13 @@ typedef enum
eoas_psc_angle = 16,
eoas_pos_angle = 17,
eoas_ft = 18,
eoas_battery = 19,
// add in here eoas_xxxnameetc
eoas_unknown = 254,
eoas_none = 255
} eOas_sensor_t;

enum { eoas_sensors_numberof = 19 };
enum { eoas_sensors_numberof = 20 };


/** @typedef typedef enum eOas_entity_t;
Expand All @@ -99,10 +100,11 @@ typedef enum
eoas_entity_inertial3 = 4,
eoas_entity_psc = 5,
eoas_entity_pos = 6,
eoas_entity_ft = 7
eoas_entity_ft = 7,
eoas_entity_battery = 8
} eOas_entity_t;

enum { eoas_entities_numberof = 8 };
enum { eoas_entities_numberof = 9 };


// -- all the possible enum
Expand Down Expand Up @@ -679,9 +681,7 @@ typedef struct // size is: 4+32+4 = 40


enum { eOas_ft_sensors_maxnumber = 4 };



enum { eOas_battery_sensors_maxnumber = 1 };

typedef struct
{
Expand All @@ -697,6 +697,19 @@ typedef struct
eOas_ft_sensordescriptor_t data[eOas_ft_sensors_maxnumber];
} eOas_ft_arrayof_sensors_t; EO_VERIFYsizeof(eOas_ft_arrayof_sensors_t, 36)

typedef struct
{
eObrd_info_t boardinfo;//6
eObrd_canlocation_t canloc;//8
uint8_t ffu;
} eOas_battery_sensordescriptor_t; EO_VERIFYsizeof(eOas_battery_sensordescriptor_t, 8)

typedef struct
{
eOarray_head_t head;//4
eOas_battery_sensordescriptor_t data[eOas_battery_sensors_maxnumber];
} eOas_battery_arrayof_sensors_t; EO_VERIFYsizeof(eOas_battery_arrayof_sensors_t, 12)


typedef enum { eoas_ft_mode_raw = 0, eoas_ft_mode_calibrated = 1 } eOas_ft_mode_t;

Expand Down Expand Up @@ -746,6 +759,48 @@ typedef struct
} eOas_ft_t; EO_VERIFYsizeof(eOas_ft_t, 64)



typedef struct
{
uint8_t period; // if 0 -> DONT TX, else TX
uint8_t filler[3];
} eOas_battery_config_t; EO_VERIFYsizeof(eOas_battery_config_t, 4)


typedef struct
{
uint8_t enable; /**< use 0 or 1*/
uint8_t filler[3];
} eOas_battery_commands_t; EO_VERIFYsizeof(eOas_battery_commands_t, 4)


typedef struct
{
eOabstime_t age; // timeoflife in usec. better using this because yarp may ask the board to have its time
int16_t temperature; // in steps of 0.1 celsius degree (pos and neg).
int8_t status;
uint8_t filler;
float32_t voltage;
float32_t current;
float32_t charge;

} eOas_battery_timedvalue_t; EO_VERIFYsizeof(eOas_battery_timedvalue_t, 24)
//char (*luca)[sizeof( eOas_battery_timedvalue_t )] = 1;

typedef struct
{ // 40 + 12 + 4 = 56
eOas_battery_timedvalue_t timedvalue;
} eOas_battery_status_t; EO_VERIFYsizeof(eOas_battery_status_t, 24)


typedef struct
{
// size is: 4 + 4 + 56 = 64
eOas_battery_config_t config;
eOas_battery_commands_t cmmnds;
eOas_battery_status_t status;
} eOas_battery_t; EO_VERIFYsizeof(eOas_battery_t, 32)

// - declaration of extern public variables, ... but better using use _get/_set instead -------------------------------
// empty-section

Expand Down Expand Up @@ -777,6 +832,9 @@ extern eObrd_cantype_t eoas_temperature_supportedboards_gettype(uint8_t pos);
extern uint8_t eoas_ft_supportedboards_numberof(void);
extern eObrd_cantype_t eoas_ft_supportedboards_gettype(uint8_t pos);
extern eObool_t eoas_ft_isboardvalid(eObrd_cantype_t boardtype);
extern uint8_t eoas_battery_supportedboards_numberof(void);
extern eObrd_cantype_t eoas_battery_supportedboards_gettype(uint8_t pos);
extern eObool_t eoas_battery_isboardvalid(eObrd_cantype_t boardtype);


/** @}
Expand Down
4 changes: 3 additions & 1 deletion eth/embobj/plus/comm-v2/icub/EoBoards.c
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@ static const uint64_t s_eoboards_is_can_mask = (0x1LL << eobrd_mc4) |
(0x1LL << eobrd_psc) |
(0x1LL << eobrd_mtb4w) |
(0x1LL << eobrd_pmc) |
(0x1LL << eobrd_amcbldc);
(0x1LL << eobrd_amcbldc)|
(0x1LL << eobrd_bms);


static const eOmap_str_str_u08_t s_eoboards_map_of_boards[] =
Expand Down Expand Up @@ -121,6 +122,7 @@ static const eOmap_str_str_u08_t s_eoboards_map_of_boards[] =
{"mtb4w", "eobrd_mtb4w", eobrd_mtb4w},
{"pmc", "eobrd_pmc", eobrd_pmc},
{"amcbldc", "eobrd_amcbldc", eobrd_amcbldc},
{"bms", "eobrd_bms", eobrd_bms},

{"none", "eobrd_none", eobrd_none},
{"unknown", "eobrd_unknown", eobrd_unknown}
Expand Down
4 changes: 3 additions & 1 deletion eth/embobj/plus/comm-v2/icub/EoBoards.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ typedef enum
eobrd_cantype_mtb4w = ICUBCANPROTO_BOARDTYPE__MTB4W, // 16 (mtb4 for waseda university)
eobrd_cantype_pmc = ICUBCANPROTO_BOARDTYPE__PMC, // 17 (pmc = piezo motor control)
eobrd_cantype_amcbldc = ICUBCANPROTO_BOARDTYPE__AMCBLDC, // 18 (amcbldc)
eobrd_cantype_bms = ICUBCANPROTO_BOARDTYPE__BMS, // 19 (bms)
eobrd_cantype_none = 254,
eobrd_cantype_unknown = ICUBCANPROTO_BOARDTYPE__UNKNOWN // 255
} eObrd_cantype_t;
Expand Down Expand Up @@ -128,12 +129,13 @@ typedef enum
eobrd_mtb4w = eobrd_cantype_mtb4w,
eobrd_pmc = eobrd_cantype_pmc,
eobrd_amcbldc = eobrd_cantype_amcbldc,
eobrd_bms = eobrd_cantype_bms,

eobrd_none = 254,
eobrd_unknown = 255 // = ICUBCANPROTO_BOARDTYPE__UNKNOWN
} eObrd_type_t;

enum { eobrd_type_numberof = 23 };
enum { eobrd_type_numberof = 24 };


typedef struct
Expand Down
8 changes: 7 additions & 1 deletion eth/embobj/plus/comm-v2/icub/EoError.c
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,13 @@ const eoerror_valuestring_t eoerror_valuestrings_CFG[] =
{eoerror_value_CFG_ft_not_verified_yet, "CFG: theFTservice is not verified yet"},
{eoerror_value_CFG_ft_using_onboard_config, "CFG: theFTservice is using onboard config"},
{eoerror_value_CFG_ft_failed_notsupported, "CFG: theFTservice is not supported"},
{eoerror_value_CFG_ft_failed_fullscales, "CFG: theFTservice cannot get fullscales"}
{eoerror_value_CFG_ft_failed_fullscales, "CFG: theFTservice cannot get fullscales"},

{eoerror_value_CFG_bat_ok, "CFG: theBATservice is OK"},
{eoerror_value_CFG_bat_failed_candiscovery, "CFG: theBATservice failed CAN discovery"},
{eoerror_value_CFG_bat_not_verified_yet, "CFG: theBATservice is not verified yet"},
{eoerror_value_CFG_bat_using_onboard_config, "CFG: theBATservice is using onboard config"},
{eoerror_value_CFG_bat_failed_notsupported, "CFG: theBATservice is not supported"},

}; EO_VERIFYsizeof(eoerror_valuestrings_CFG, eoerror_value_CFG_numberof*sizeof(const eoerror_valuestring_t))

Expand Down
11 changes: 8 additions & 3 deletions eth/embobj/plus/comm-v2/icub/EoError.h
Original file line number Diff line number Diff line change
Expand Up @@ -398,11 +398,16 @@ typedef enum
eoerror_value_CFG_ft_not_verified_yet = 92,
eoerror_value_CFG_ft_using_onboard_config = 93,
eoerror_value_CFG_ft_failed_notsupported = 94,
eoerror_value_CFG_ft_failed_fullscales = 95

eoerror_value_CFG_ft_failed_fullscales = 95,

eoerror_value_CFG_bat_ok = 96,
eoerror_value_CFG_bat_failed_candiscovery = 97,
eoerror_value_CFG_bat_not_verified_yet = 98,
eoerror_value_CFG_bat_using_onboard_config = 99,
eoerror_value_CFG_bat_failed_notsupported = 100,
} eOerror_value_CFG_t;

enum { eoerror_value_CFG_numberof = 96 };
enum { eoerror_value_CFG_numberof = 101 };


/** @typedef typedef enum eOerror_value_ETHMON_t
Expand Down
3 changes: 2 additions & 1 deletion eth/embobj/plus/comm-v2/icub/EoManagement.c
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@ static const char * s_mn_servicetype_strings[] =
"eomn_serv_AS_pos",
"eomn_serv_MC_mc4plusfaps",
"eomn_serv_MC_mc4pluspmc",
"eomn_serv_AS_ft"
"eomn_serv_AS_ft",
"eomn_serv_AS_battery"
}; EO_VERIFYsizeof(s_mn_servicetype_strings, eomn_serv_types_numberof*sizeof(const char *))

static const char * s_mn_servicetype_string_unknown = "eomn_serv_UNKNOWN";
Expand Down
19 changes: 12 additions & 7 deletions eth/embobj/plus/comm-v2/icub/EoManagement.h
Original file line number Diff line number Diff line change
Expand Up @@ -437,12 +437,13 @@ typedef enum
eomn_serv_category_psc = 7,
eomn_serv_category_pos = 8,
eomn_serv_category_ft = 9,
eomn_serv_category_battery = 10,
eomn_serv_category_all = 128,
eomn_serv_category_unknown = 254,
eomn_serv_category_none = 255
} eOmn_serv_category_t;

enum { eomn_serv_categories_numberof = 10 };
enum { eomn_serv_categories_numberof = 11 };

typedef enum
{
Expand All @@ -464,11 +465,12 @@ typedef enum
eomn_serv_MC_mc4plusfaps = 15,
eomn_serv_MC_mc4pluspmc = 16,
eomn_serv_AS_ft = 17,
eomn_serv_AS_battery = 18,
eomn_serv_UNKNOWN = 254,
eomn_serv_NONE = 255
} eOmn_serv_type_t;

enum { eomn_serv_types_numberof = 18 };
enum { eomn_serv_types_numberof = 19 };

typedef enum
{
Expand Down Expand Up @@ -544,6 +546,11 @@ typedef struct
eOas_ft_arrayof_sensors_t arrayofsensors;
} eOmn_serv_config_data_as_ft_t; EO_VERIFYsizeof(eOmn_serv_config_data_as_ft_t, 40)

typedef struct
{
eObrd_canmonitor_cfg_t canmonitorconfig;
eOas_battery_arrayof_sensors_t arrayofsensors;
} eOmn_serv_config_data_as_battery_t; EO_VERIFYsizeof(eOmn_serv_config_data_as_battery_t, 16)

typedef union
{ // max(6, 6, 44, 108, 156, 8, 6, 40)
Expand All @@ -555,10 +562,10 @@ typedef union
eOmn_serv_config_data_as_psc_t psc;
eOmn_serv_config_data_as_pos_t pos;
eOmn_serv_config_data_as_ft_t ft;
eOmn_serv_config_data_as_battery_t battery;
} eOmn_serv_config_data_as_t; EO_VERIFYsizeof(eOmn_serv_config_data_as_t, 156)



enum { eomn_serv_skin_maxpatches = 4 };

typedef struct
Expand Down Expand Up @@ -664,7 +671,6 @@ typedef union
} eOmn_serv_config_data_t; EO_VERIFYsizeof(eOmn_serv_config_data_t, 328)



typedef struct
{ // 1+3+324=328
uint8_t type; // use eOmn_serv_type_t to identify what kind of service it is
Expand All @@ -673,7 +679,6 @@ typedef struct
eOmn_serv_config_data_t data;
} eOmn_serv_configuration_t; EO_VERIFYsizeof(eOmn_serv_configuration_t, 332)


enum { eOmn_serv_capacity_arrayof_id32 = 41 };
typedef struct
{
Expand Down Expand Up @@ -754,7 +759,7 @@ typedef struct
typedef struct
{ // 32 + 32
uint8_t stateofservice[eomn_serv_categories_numberof]; // use eOmn_serv_state_t
uint8_t filler[6];
uint8_t filler[5];
eOmn_service_command_result_t commandresult;
} eOmn_service_status_t; EO_VERIFYsizeof(eOmn_service_status_t, 48)

Expand All @@ -767,7 +772,7 @@ typedef struct
eOmn_service_status_t status;
eOmn_service_cmmnds_t cmmnds;
} eOmn_service_t; EO_VERIFYsizeof(eOmn_service_t, 384)

//char (*luca)[sizeof( eOmn_service_t )] = 1;

// - declaration of extern public variables, ... but better using use _get/_set instead -------------------------------
// empty-section
Expand Down
Loading

0 comments on commit bbb55d4

Please sign in to comment.