Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
78 commits
Select commit Hold shift + click to select a range
bc3cf70
Initial commit
mindThomas Dec 13, 2018
43389b7
Initial commit with UART driver tested and working
mindThomas Dec 16, 2018
723f8ec
SPI and I2C drivers tested against MPU9250 and confirmed working.
mindThomas Dec 17, 2018
56043e9
PWM, Encoder, High resolution timer and IO driver implemented and tested
mindThomas Dec 18, 2018
9b214aa
Quadrature knob library implemented and tested
mindThomas Dec 18, 2018
448f076
USB CDC functionality moved into library and has tested.
mindThomas Dec 18, 2018
2987d07
USB CDC library updated to include functions for writing and receivin…
mindThomas Dec 18, 2018
18253e4
LSPC library included and Socket port for using USB CDC has been deve…
mindThomas Dec 19, 2018
ef9863f
ADC library implemented in polling configuration
mindThomas Dec 19, 2018
1beb391
MPU-9250 library added with support for both SPI and I2C
mindThomas Dec 19, 2018
f54eb2e
ESCON library implemented but not tested on hardware
mindThomas Dec 20, 2018
20a3650
ESCON library tested on real hardware and confirmed working
mindThomas Dec 21, 2018
dc31fdf
Controller code merged and put into classes - not tested yet
mindThomas Dec 21, 2018
1fa4548
Prepared application classes
mindThomas Dec 21, 2018
2fbf487
Estimator code merged into project and library placeholders has been …
mindThomas Dec 21, 2018
f758eec
Added LCD library but not tested yet
mindThomas Dec 26, 2018
1bc794e
Updated sliding mode controller to include angular velocity reference
mindThomas Dec 26, 2018
3af284e
Added comments to controller libraries
mindThomas Dec 26, 2018
6af0ab2
Estimator libraries finished but not tested yet
mindThomas Dec 26, 2018
a641d4b
Attitude controller application implemented (but not tested)
mindThomas Dec 27, 2018
988c1d9
Included ARM Math and DSP support to use the SIMD instructions suppor…
mindThomas Dec 30, 2018
ba6d095
Fixed several compiler warnings
mindThomas Jan 3, 2019
494da02
Tested and verified LSPC communication with PC
mindThomas Jan 5, 2019
8500db6
Debugging library updated to support printf and linked with LSPC (USB)
mindThomas Jan 5, 2019
53a9cbc
Modified maximum LSPC package length to 250 bytes to be within bounds
mindThomas Jan 7, 2019
af03f24
Implemented unit tests for Sliding mode, LQR and QEKF
mindThomas Jan 9, 2019
c361ca3
Updated copyright headers
mindThomas Jan 9, 2019
4e2c2c9
Updated copyright headers
mindThomas Jan 9, 2019
ef1e21c
Updated copyright headers
mindThomas Jan 9, 2019
529a15d
"Enter Bootloader" function tested
mindThomas Jan 9, 2019
c00c50b
Enabled optimization and measured execution time for Attitude controller
mindThomas Jan 10, 2019
dba80de
Implemented EEPROM library and linked with Parameters library to load
mindThomas Jan 10, 2019
eb639f4
IMU, qEKF and Madgwick Tested and confirmed working on hardware
mindThomas Jan 11, 2019
f96ffb1
Included publish and subscribe for several messages
mindThomas Jan 13, 2019
6b8cfab
Removed submodule KugleFirmware/Libraries/Devices/LSPC/LSPC
mindThomas Jan 13, 2019
f52130a
ADC library corrected to work with DMA
mindThomas Jan 14, 2019
e55abb1
Parameter Get, Set, Store and Dump has been tested+verified with ROS
mindThomas Jan 14, 2019
c32a840
Updated message types to update ROS driver
mindThomas Jan 15, 2019
73eecd4
Added STM32 pinout overview
mindThomas Jan 28, 2019
5e6b510
Updated parameters to match Kugle V1
mindThomas Feb 11, 2019
67a0dc2
Initial tests on robot
mindThomas Feb 12, 2019
8e3d3c2
Initial balance on Kugle V1
mindThomas Feb 15, 2019
b8eb738
Sliding mode controller working on Kugle V1
mindThomas Feb 16, 2019
050b45f
Added driver for Xsens MTI200 IMU
mindThomas Feb 18, 2019
d09d55d
Enabled IMU selection (MPU9250 or Xsens) through parameter
mindThomas Feb 19, 2019
5f84a17
Implemented front panel button handling for Power (start/stop control…
mindThomas Feb 20, 2019
317f37d
Modified UART driver and Xsens parser to fix problem with intermitten…
mindThomas Feb 21, 2019
f4fdb77
Fixed QEKF Covariance function
mindThomas Feb 21, 2019
629b9fb
Updated Xsens IMU to 460800 baud and 400 Hz sampling
mindThomas Feb 22, 2019
ef3d183
Implemented seperated IMU calibration procedure
mindThomas Feb 26, 2019
83f8adb
Improved QEKF and Velocity estimator + Working velocity control for V1
mindThomas Feb 26, 2019
47e3731
Velocity controller working but wobbly - note no equivalent control used
mindThomas Feb 27, 2019
7e5c83b
Velocity controller working much better by using ball velocity
mindThomas Feb 27, 2019
6fc3c68
Velocity controller tuned for Joystick control (but is still wobbly)
mindThomas Feb 28, 2019
52e327c
Improved velocity controller performance by adding rate limiter
mindThomas Feb 28, 2019
39a5028
Wheel slip detection and automatic ramp down (to reduce oscillations)
mindThomas Mar 1, 2019
c65f83f
Quaternion and Velocity control is well working + heading init at start
mindThomas Mar 1, 2019
3a094f8
Improved wheel slip detection and velocity controller
mindThomas Mar 1, 2019
398e1ef
LQR controller corrected and well working (similar performance to SM)
mindThomas Mar 5, 2019
b6be587
Fixed error in 2D rotation function used by velocity controller
mindThomas Mar 5, 2019
3bb306d
Velocity estimator tested and working - but not fine tuned
mindThomas Mar 5, 2019
7c7a5ee
Stable branch with working Quaternion and Velocity controller
mindThomas Mar 7, 2019
422ba82
Adjusted sliding mode gains to work with corrected sliding mode
mindThomas Mar 7, 2019
e22a11b
Equivalent control only disabled around x and y axis
mindThomas Mar 7, 2019
a5368cc
Velocity controller working well with joystick + tested with dwa_planner
mindThomas Mar 8, 2019
afd48b6
Merge branch 'SlidingModeFix' into stable
mindThomas Mar 8, 2019
bda54ff
Merge branch 'stable'
mindThomas Mar 8, 2019
6790c38
Added parameters for Velocity sliding mode (see other branch)
mindThomas Mar 9, 2019
70417ef
Accelerometer+Encoder-based Velocity estimator implemented and tested
mindThomas Mar 9, 2019
2515cea
Switched to MIT License
mindThomas Mar 13, 2019
eb8834d
Merge branch 'master' into stable
mindThomas Mar 13, 2019
c648ce7
Made powermanagment
damgaardmr Mar 20, 2019
d51500e
comment out testBench
damgaardmr Mar 20, 2019
3e6b1dd
Changed LSPC powermanagment msg id
damgaardmr Mar 20, 2019
51fc12c
Auto stash before merge of "master" and "origin/master"
damgaardmr Mar 21, 2019
addf453
Deleted core file
damgaardmr Mar 21, 2019
5d20220
lol
damgaardmr Mar 21, 2019
6ad54da
lo
damgaardmr Mar 22, 2019
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
2 changes: 1 addition & 1 deletion KugleFirmware/KugleFirmware Debug.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ set ENABLE_LOW_POWER 1
set STOP_WATCHDOG 1

# STlink Debug clock frequency
set CLOCK_FREQ 4000
set CLOCK_FREQ 8000
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't commit this change. Debug frequency has been lowered purposely


# use hardware reset, connect under reset
# connect_assert_srst needed if low power mode application running (WFI...)
Expand Down
18 changes: 14 additions & 4 deletions KugleFirmware/KugleFirmware.xml
Original file line number Diff line number Diff line change
@@ -1,9 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do not commit this file change. Leave out these changes to the Eclipse configuration files.

<targetDefinitions xmlns="http://openstm32.org/stm32TargetDefinitions" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://openstm32.org/stm32TargetDefinitions stm32TargetDefinitions.xsd">
<board id="KugleFirmware">
<!DOCTYPE targetDefinitions [
<!ELEMENT targetDefinitions (board)>
<!ELEMENT board (name, dbgIF+, dbgDEV, mcuId)>
<!ELEMENT name (#PCDATA)>
<!ELEMENT dbgIF (#PCDATA)>
<!ELEMENT dbgDEV (#PCDATA)>
<!ELEMENT mcuId (#PCDATA)>
<!ATTLIST board id CDATA #REQUIRED>
]>

<targetDefinitions>
<board id="kuglefirmware">
<name>KugleFirmware</name>
<mcuId>STM32H743ZITx</mcuId> <!-- mcu-->
<dbgIF>SWD</dbgIF>
<dbgDEV>ST-LinkV2-1</dbgDEV>
<dbgDEV>ST-Link</dbgDEV>
<mcuId>stm32h743zitx</mcuId>
</board>
</targetDefinitions>
311 changes: 308 additions & 3 deletions KugleFirmware/Libraries/Devices/Battery/Battery.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,318 @@
*/

#include "Battery.h"
#include <bitset> // std::bitset
#include "Debug.h"

Battery::Battery()
Battery::Battery(SMBus::port_t SMBusHardwareResources)
{

location = 0;
smbus = new SMBus(SMBusHardwareResources, DeviceAddr);
present = smbus->devicePresent();
}

Battery::Battery(SMBus::port_t SMBusHardwareResources,uint8_t _location)
{
location = _location;
smbus = new SMBus(SMBusHardwareResources, DeviceAddr);
present = smbus->devicePresent();
}

Battery::~Battery()
{

if(smbus){
delete smbus;
}
}



// SMBus Commands
// -------------------------------------------------------------------------------------------
// Reading and writing from/to the battery.
//
/* This file contains the following functions:
SMBus_R(); Low level function used to read on the SMBus
SMBus_w(); Low level function used to write to the SMBus
getCurrent(); Returns the status of the bus and saves the current in a buffer
getCycleCount(); Returns the status of the bus and saves the number of Cycles in a buffer
getRunTimeToEmpty(); Returns the status of the bus and saves how much battery time there is left in a buffer
getTemperature(); Returns the status of the bus and saves the current Temperature in a buffer
getVoltage(); Returns the status of the bus and saves the Voltage in a buffer
SetChargeCurrentLimit(); Changes the Charge Current Limit
SetInputCurrentLimit(); Changes the Input Current limit

Look under the specific function for more information
*/
// -------------------------------------------------------------------------------------------

float Battery::getCurrent(void){
if(smbus->devicePresent()){
// Returns the current being supplied (or accepted) through the battery's terminals.
uint8_t const N_bytes = 2;
uint8_t responbuf_tmp[N_bytes];

smbus->Read(CmdAddr::read::Current,responbuf_tmp,N_bytes);

int16_t number = responbuf_tmp[0] | responbuf_tmp[1] << 8;
float current = ((float)number) / 1000;

return current;
}
else{
return 0;
}
}

float Battery::getTemperature(void){
if(smbus->devicePresent()){
// Returns the pack's internal temperature.
uint8_t N_bytes = 2;
uint8_t responbuf_tmp[2];

smbus->Read(CmdAddr::read::Temperature,responbuf_tmp,N_bytes);

int number = responbuf_tmp[0] | responbuf_tmp[1] << 8;
float temperature = ((float)number) / 10 - 273.15;

return temperature;
}
else{
return 0;
}
}

float Battery::getVoltage(void){
if(smbus->devicePresent()){
// Returns the battery's voltage (measured at the cell stack)
uint8_t N_bytes = 2;
uint8_t responbuf_tmp[2];

smbus->Read(CmdAddr::read::Voltage,responbuf_tmp,N_bytes);

int16_t number = responbuf_tmp[0] | responbuf_tmp[1] << 8;
float voltage = ((float)number) / 1000;

return voltage;
}
else{
return 0;
}
}

float Battery::getCharge(void) // Current charge in Ah (If unmeasured NaN)
{
if(smbus->devicePresent()){
// Returns the battery's charge
uint8_t N_bytes = 2;
uint8_t responbuf_tmp[2];

smbus->Read(CmdAddr::read::RemainingCapacity,responbuf_tmp,N_bytes);

uint16_t number = responbuf_tmp[0] | responbuf_tmp[1] << 8;
float charge = ((float)number) / 1000;

return charge;
}
else{
return 0;
}
}


float Battery::getCapacity(void) // Capacity in Ah (last full capacity) (If unmeasured NaN)
{
if(smbus->devicePresent()){
// Returns the battery's capacity
uint8_t N_bytes = 2;
uint8_t responbuf_tmp[2];

smbus->Read(CmdAddr::read::FullChargeCapacity,responbuf_tmp,N_bytes);

uint16_t number = responbuf_tmp[0] | responbuf_tmp[1] << 8;
float Capacity = ((float)number) / 1000;

return Capacity;
}
else{
return 0;
}
}

float Battery::getDesign_capacity(void) // Capacity in Ah (design capacity) (If unmeasured NaN)
{
if(smbus->devicePresent()){
// Returns the battery's Design Capacity
uint8_t N_bytes = 2;
uint8_t responbuf_tmp[2];

smbus->Read(CmdAddr::read::DesignCapacity,responbuf_tmp,N_bytes);

uint16_t number = responbuf_tmp[0] | responbuf_tmp[1] << 8;
float DesignCapacity = ((float)number) / 1000;

return DesignCapacity;
}
else{
return 0;
}
}

float Battery::getPercentage(void) // Charge percentage on 0 to 1 range (If unmeasured NaN)
{
if(smbus->devicePresent()){
// Returns the battery's charge percentage
uint8_t N_bytes = 2;
uint8_t responbuf_tmp[2];

smbus->Read(CmdAddr::read::RelativeStateOfCharge,responbuf_tmp,N_bytes);

uint16_t number = responbuf_tmp[0] | responbuf_tmp[1] << 8;
float chargePercentage = ((float)number) / 100;

return chargePercentage;
}
else{
return 0;
}
}

uint8_t Battery::getPowerSupplyStatus(void) // The charging status as reported. Values defined above
{
if(smbus->devicePresent()){
// Returns the battery's status
uint8_t N_bytes = 2;
uint8_t responbuf_tmp[2];

smbus->Read(CmdAddr::read::BatteryStatus,responbuf_tmp,N_bytes);

uint16_t number = responbuf_tmp[0] | responbuf_tmp[1] << 8;
std::bitset<16> tmp(number);

if (tmp.test(6)) return POWER_SUPPLY_STATUS_DISCHARGING; // Discharging??
else if (tmp.test(5)) return POWER_SUPPLY_STATUS_FULL; // fully charged?
else return POWER_SUPPLY_STATUS_UNKNOWN;
}
else{
return POWER_SUPPLY_STATUS_UNKNOWN;
}
}

uint8_t Battery::getPowerSupplyHealth(void) // The battery health metric. Values defined above
{
if(smbus->devicePresent()){
// Returns the battery's health
uint8_t N_bytes = 2;
uint8_t responbuf_tmp[2];

smbus->Read(CmdAddr::read::BatteryStatus,responbuf_tmp,N_bytes);

uint16_t number = responbuf_tmp[0] | responbuf_tmp[1] << 8;
std::bitset<16> tmp(number);

if (tmp.test(12)) return POWER_SUPPLY_HEALTH_OVERHEAT;
else if (tmp.test(15)) return POWER_SUPPLY_HEALTH_UNSPEC_FAILURE;
else if (tmp.test(14)) return POWER_SUPPLY_HEALTH_UNSPEC_FAILURE;
else if (tmp.test(11)) return POWER_SUPPLY_HEALTH_UNSPEC_FAILURE;
else if (tmp.test(9)) return POWER_SUPPLY_HEALTH_UNSPEC_FAILURE;
else if (tmp.test(8)) return POWER_SUPPLY_HEALTH_UNSPEC_FAILURE;
else return POWER_SUPPLY_HEALTH_GOOD;
}
else{
return POWER_SUPPLY_HEALTH_UNKNOWN;
}
}

uint8_t Battery::getPowerSupplyTechnology(void) // The battery chemistry. Values defined above
{
if(smbus->devicePresent()){
uint8_t N_bytes = 10;
uint8_t responbuf_tmp[N_bytes];

uint8_t bytesRead = smbus->blockRead(CmdAddr::read::DeviceChemistry,responbuf_tmp,N_bytes);

char responbuf_tmp2[bytesRead+1];

for (int i = 0; i<bytesRead;i++){
responbuf_tmp2[i] = toupper((char)responbuf_tmp[i]);
}
responbuf_tmp2[bytesRead] = {'\0'};

if (strcmp(responbuf_tmp2, "LION") == 0){return POWER_SUPPLY_TECHNOLOGY_LION;}
else if (strcmp(responbuf_tmp2, "NIMH") == 0){return POWER_SUPPLY_TECHNOLOGY_NIMH;}
else if (strcmp(responbuf_tmp2, "NICD") == 0){return POWER_SUPPLY_TECHNOLOGY_NICD;}
else if (strcmp(responbuf_tmp2, "LIP") == 0){return POWER_SUPPLY_TECHNOLOGY_LIPO;}
else{return POWER_SUPPLY_TECHNOLOGY_UNKNOWN;}
}
else{
return 0;
}
}

bool Battery::checkPresent(void) // True if the battery is present
{
return present;
}

uint8_t Battery::getLocation(void) // The location into which the battery is inserted. (slot number or plug)
{
return location;
}

uint32_t Battery::getSerialNumber(void)
{
if(smbus->devicePresent()){
// Returns the battery's serial number

/* Explanation
* SerialNumber(): This function is used to return a serial number. This number when combined with the ManufacturerName(),
* the DeviceName(), and the ManufactureDate() will uniquely identify the battery (unsigned int).
*
* Since we already know the manufacture and device name (just look at it) we return a combination of ManufactureDate() and SerialNumber()
* to uniqly identify the battery!
*/


uint8_t N_bytes = 2;
uint8_t responbuf_tmp[2];

smbus->Read(CmdAddr::read::ManufactureDate,responbuf_tmp,N_bytes);

uint16_t ManufactureDate = responbuf_tmp[0] | responbuf_tmp[1] << 8;

smbus->Read(CmdAddr::read::SerialNumber,responbuf_tmp,N_bytes);

uint16_t serialNumber = responbuf_tmp[0] | responbuf_tmp[1] << 8;

uint32_t uniqueIdentifier = ManufactureDate << 16 | serialNumber;
return uniqueIdentifier;
}
else{
return 0;
}
}

uint16_t Battery::getCycleCount(void){
if(smbus->devicePresent()){
// Returns the number of charge/discharge cycles the battery has experienced. A charge/discharge cycle is defined as: an amount of discharge approximately equal to the value of DesignCapacity.
uint8_t N_bytes = 2;
uint8_t responbuf_tmp[2];

smbus->Read(CmdAddr::read::CycleCount,responbuf_tmp,N_bytes);

uint16_t nCycle = responbuf_tmp[0] | responbuf_tmp[1] << 8;

return nCycle;
}
else{
return 0;
}
}

bool Battery::isBatteryGettingOld(void){
if (getCycleCount() > gettingOldCycleCount){
return true;
}
else{return false;}
}

Loading