Skip to content

Commit

Permalink
Merge branch 'master' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
jakubmatyszczak committed Dec 14, 2022
2 parents 5cb9253 + 15a5320 commit 565de45
Show file tree
Hide file tree
Showing 30 changed files with 1,176 additions and 334 deletions.
40 changes: 29 additions & 11 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,34 +1,34 @@
cmake_minimum_required(VERSION 3.5)

set(MDTOOL_VERSION 1.1-0)
set(MDTOOL_VERSION 1.2.1)

if(NOT DEFINED ARCH)
set(ARCH "native")
execute_process(COMMAND dpkg --print-architecture OUTPUT_VARIABLE ARCH)
string(REGEX REPLACE "\n$" "" ARCH "${ARCH}")
endif()

if( "${ARCH}" STREQUAL "armhf")
if("${ARCH}" STREQUAL "armhf")
message("[MDTOOL] Compiling for armhf")
set(CMAKE_CXX_COMPILER /usr/bin/arm-linux-gnueabihf-g++)
set(CMAKE_C_COMPILER /usr/bin/arm-linux-gnueabihf-gcc)
elseif ( "${ARCH}" STREQUAL "aarm64")
message("[MDTOOL] Compiling for aarm64")
elseif("${ARCH}" STREQUAL "arm64")
message("[MDTOOL] Compiling for arm64")
set(CMAKE_CXX_COMPILER /usr/bin/aarch64-linux-gnu-g++)
set(CMAKE_C_COMPILER /usr/bin/aarch64-linux-gnu-gcc)
else ()
else()
message("[MDTOOL] Compiling for native architecture")
set(CMAKE_CXX_COMPILER /usr/bin/g++)
set(CMAKE_C_COMPILER /usr/bin/gcc)
endif()

project(mdtool-${ARCH})
project(mdtool-${ARCH} VERSION ${MDTOOL_VERSION})

set (CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD 11)
add_compile_options(-Wall -Wextra -Wpedantic)

file(GLOB SRC "src/*.cpp")

enable_testing()

set(CMAKE_POSITION_INDEPENDENT_CODE ON)
set(CANDLE_BUILD_STATIC ON)
set(CANDLE_OMIT_EXAMPLES ON)
Expand All @@ -39,5 +39,23 @@ target_link_libraries(${PROJECT_NAME} candle)
target_include_directories(${PROJECT_NAME} PUBLIC ${CMAKE_SOURCE_DIR}/include ${CMAKE_SOURCE_DIR}/candle/include ${CMAKE_SOURCE_DIR}/3rd_party/mINI/src)
set_target_properties(${PROJECT_NAME} PROPERTIES OUTPUT_NAME "mdtool")

install(TARGETS ${PROJECT_NAME}
DESTINATION ${CMAKE_SOURCE_DIR}/package/mdtool_${MDTOOL_VERSION}_${ARCH}/usr/local/bin)
if(MAKE_TESTS)
add_subdirectory(test)
endif()

set(CPACK_GENERATOR "DEB")
set(CPACK_PROJECT_NAME "mdtool")
set(CPACK_PACKAGE_NAME ${PROJECT_NAME})
set(CPACK_PROJECT_VERSION ${PROJECT_VERSION})
set(CPACK_DEBIAN_PACKAGE_MAINTAINER "MAB Robotics <contact@mabrobotics.pl>")
set(CPACK_PACKAGE_VENDOR "MAB Robotics")
set(CPACK_PACKAGE_DESCRIPTION "Console tool for configuring and setting up MD80 via CANdle")
set(CPACK_DEBIAN_PACKAGE_ARCHITECTURE ${ARCH})
set(CPACK_DEBIAN_PACKAGE_CONTROL_EXTRA "${PROJECT_SOURCE_DIR}/template_package/postinst")

include(CPack)

install(TARGETS ${PROJECT_NAME}
DESTINATION /usr/local/bin)
install(DIRECTORY "${PROJECT_SOURCE_DIR}/template_package/etc"
DESTINATION /)
10 changes: 8 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# MDtool
MDtool is a console application for configuring and performing basic diagnostics on MD80-based drives via CANdle. For more information please refer to [MD80 x CANdle Manual](https://www.mabrobotics.pl/servos).
MDtool is a console application for configuring and performing basic diagnostics on MD80-based drives via CANdle. For more information please refer to [MD80 x CANdle Manual](https://www.mabrobotics.pl/servos/#comp-l6v4io99).

# Installing
The easiest way to install the MDtool is to select the appropriate *.deb package from the MDtool GitHub repo 'Releases' page. To install after the download simply call:
The easiest way to install the MDtool is to select the appropriate *.deb package from the MDtool GitHub repo 'Releases' page. Prior to install please uninstall all older versions and delete the ~/.config/mdtool directory (otherwise it will not be updated with new default motor configs). To install after the download simply call:
```sudo apt install ./mdtool_xx-x_xx.deb```

# Building
Expand All @@ -14,3 +14,9 @@ cd build
cmake ..
make
```
for native architecture, or

```
./release.sh
```
if you want to build for all architectures at once
26 changes: 23 additions & 3 deletions include/mainWorker.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,30 @@

#include "bus.hpp"
#include "candle.hpp"
#include "mini/ini.h"

const std::string version = "1.2.1";

class MainWorker
{
public:
MainWorker(std::vector<std::string>& args);

private:
const std::string path = "/.config/MDtool.ini";
std::string pathFull = "";
const std::string mdtoolHomeConfigDirName = ".config";
const std::string mdtoolDirName = "mdtool";
const std::string mdtoolMotorCfgDirName = "mdtool_motors";
const std::string mdtoolIniFileName = "mdtool.ini";

const std::string mdtoolConfigPath = "/etc/";

std::string mdtoolBaseDir;
std::string mdtoolIniFilePath;

mab::Candle* candle;

std::string busString;

mab::CANdleBaudrate_E CurrentBaudrate;
bool printVerbose = false;

Expand All @@ -22,14 +34,22 @@ class MainWorker
void configSave(std::vector<std::string>& args);
void configZero(std::vector<std::string>& args);
void configCurrent(std::vector<std::string>& args);
void configBandwidth(std::vector<std::string>& args);

void setupCalibration(std::vector<std::string>& args);
void setupDiagnostic(std::vector<std::string>& args);
void setupMotor(std::vector<std::string>& args);
void setupInfo(std::vector<std::string>& args);

void testMove(std::vector<std::string>& args);
void testLatency(std::vector<std::string>& args);
void blink(std::vector<std::string>& args);
void encoder(std::vector<std::string>& args);
void bus(std::vector<std::string>& args);

void changeDefaultConfig(std::string bus);
void changeDefaultConfig(std::string bus, std::string device);
mab::CANdleBaudrate_E checkSpeedForId(uint16_t id);

template <class T>
bool getField(mINI::INIStructure& cfg, mINI::INIStructure& ini, std::string category, std::string field, T& value);
};
18 changes: 18 additions & 0 deletions include/ui.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <vector>

#include "candle.hpp"
#include "mainWorker.hpp"

namespace ui
{
Expand All @@ -15,11 +16,28 @@ void printUnknownCmd(std::string arg);
void printHelp();
void printHelpConfig();
void printHelpSetup();
void printHelpTest();
void printLatencyTestResult(uint8_t actuatorCount, float average, float stdev, std::string bus);

bool getCalibrationConfirmation();
void printPosition(int id, float pos);
void printPositionAndVelocity(int id, float pos, float velocity);
void printDriveInfo(int id, float pos, float vel, float torque, float temperature, unsigned short error, mab::CANdleBaudrate_E baud);
void printScanOutput(mab::Candle* candle);
void printFoundDrives(std::vector<uint16_t> ids);
void printUnableToFindCfgFile(std::string path);
void printDriveInfoExtended(mab::Md80& drive);
void printErrorDetails(unsigned short error);
void printParameterOutOfBounds(std::string category, std::string field);
void printFailedToSetupMotor();

template <class T>
bool checkParamLimit(T value, T min, T max)
{
if (value > max)
return false;
if (value < min)
return false;
return true;
}
} // namespace ui
4 changes: 0 additions & 4 deletions package/createDebPackage.sh

This file was deleted.

6 changes: 0 additions & 6 deletions package/mdtool_1.1-0_aarm64/DEBIAN/control

This file was deleted.

This file was deleted.

6 changes: 0 additions & 6 deletions package/mdtool_1.1-0_amd64/DEBIAN/control

This file was deleted.

This file was deleted.

6 changes: 0 additions & 6 deletions package/mdtool_1.1-0_armhf/DEBIAN/control

This file was deleted.

This file was deleted.

25 changes: 25 additions & 0 deletions release.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/usr/bin/env bash
TARGETS="amd64 arm64 armhf"
rm -rf build
mkdir -p build
cd build

apt install gcc-arm-linux-gnueabi g++-arm-linux-gnueabi
apt install gcc-arm-linux-gnueabihf g++-arm-linux-gnueabihf
apt install g++-aarch64-linux-gnu

mkdir packages

for TARGET in ${TARGETS}
do
# create one build dir per target architecture
mkdir -p ${TARGET}
cd ${TARGET}
cmake -DARCH=${TARGET} ../..
make -j
cpack -G DEB
cp *.deb ../packages
cd -
done


24 changes: 11 additions & 13 deletions src/main.cpp
Original file line number Diff line number Diff line change
@@ -1,22 +1,20 @@
#include "mainWorker.hpp"
#include "ui.hpp"

const std::string version = "v1.1";

int main(int argc, char** argv)
{
std::cout << "[MDTOOL] MDtool version: " << version << std::endl;
std::vector<std::string> args;
for (int i = 0; i < argc; i++)
args.emplace_back(argv[i]);
std::cout << "[MDTOOL] MDtool version: v" << version << std::endl;
std::vector<std::string> args;
for (int i = 0; i < argc; i++)
args.emplace_back(argv[i]);

if (args.size() < 2)
{
ui::printTooFewArgs();
return 2;
}
if (args.size() < 2)
{
ui::printTooFewArgs();
return 2;
}

MainWorker program(args);
MainWorker program(args);

return EXIT_SUCCESS;
return EXIT_SUCCESS;
}

0 comments on commit 565de45

Please sign in to comment.