Skip to content

Commit 93076a1

Browse files
vcrocheremekBarisbenvonhjustincmfong
authored
Rewrite state machine (#62)
Merge of the rewrite_StateMachine development branch including the following changes: - A rewrite of the state machine system and associated upgrade of all demo apps. See #51 . - Some changes on the main app timing (CAN and RT thread timing management and overtime error) - Slight simplification of the CMakeFile: no more ROS1 cross-compilation option and allow out-of-folder apps - Support for Fourier ArmMotus EMU version - Some documentation rewrite Co-authored-by: Emek Barış Küçüktabak <32764586+emekBaris@users.noreply.github.com> Co-authored-by: Ben <75413535+benvonh@users.noreply.github.com> Co-authored-by: justinfong-unimelb <49131879+justinfong-unimelb@users.noreply.github.com>
1 parent 34ccc40 commit 93076a1

91 files changed

Lines changed: 1427 additions & 2092 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

CMakeLists.txt

Lines changed: 72 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,6 @@ project(CORC C CXX)
33

44
#To cross-compile for Arm (BeagleBone) use the armhf toolchain:
55
# cmake -DCMAKE_TOOLCHAIN_FILE=../armhf.cmake ..
6-
#To cross-compile with ROS support prepare a sysroot and pass it to cmake:
7-
# cmake -DCMAKE_SYSROOT=/path/to/sysroot/ -DCMAKE_TOOLCHAIN_FILE=../armhf.cmake ..
8-
# See doc for more details.
96
################################## USER FLAGS ##################################
107

118
## Select the application by setting the state machine to use
@@ -14,12 +11,16 @@ project(CORC C CXX)
1411

1512
set (STATE_MACHINE_NAME "ExoTestMachine")
1613
#set (STATE_MACHINE_NAME "M1DemoMachine")
17-
#set (STATE_MACHINE_NAME "M1DemoMachineROS") # uncomment other cfg files under generate_dynamic_reconfigure_options
14+
#set (STATE_MACHINE_NAME "M1DemoMachineROS")
1815
#set (STATE_MACHINE_NAME "M2DemoMachine")
1916
#set (STATE_MACHINE_NAME "M3DemoMachine")
20-
#set (STATE_MACHINE_NAME "X2DemoMachine") # uncomment other cfg files under generate_dynamic_reconfigure_options
17+
#set (STATE_MACHINE_NAME "X2DemoMachine")
2118
#set (STATE_MACHINE_NAME "LoggingDevice")
2219

20+
#Use this if your state machine code folder is not in CORC 'src/apps/' folder.
21+
#Can be a relative or absolute path.
22+
#set (STATE_MACHINE_PATH "../")
23+
2324
# Comment to use actual hardware, uncomment for a nor robot (virtual) app
2425
set(NO_ROBOT ON)
2526

@@ -30,6 +31,12 @@ set(USE_ROS OFF)
3031
set(CORC_LOGGING_LEVEL INFO)
3132

3233
################################################################################
34+
#Default path if not set
35+
if(NOT STATE_MACHINE_PATH)
36+
set (STATE_MACHINE_PATH "src/apps")
37+
endif()
38+
39+
#ROS internal flags
3340
if(USE_ROS)
3441
add_definitions(-DUSEROS)
3542
endif()
@@ -49,8 +56,8 @@ add_definitions(-DFP_STARTTPDO=0x3E1)
4956

5057
#######################
5158

52-
## Compile as C++11
53-
set(CMAKE_CXX_STANDARD 11)
59+
## Compile as C++14
60+
set(CMAKE_CXX_STANDARD 14)
5461
set(CMAKE_CXX_STANDARD_REQUIRED ON)
5562
if(USE_ROS)
5663
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wno-int-in-bool-context" )
@@ -69,7 +76,7 @@ set(THREADS_PREFER_PTHREAD_FLAG TRUE)
6976
if(NOT CMAKE_BUILD_TYPE)
7077
set(CMAKE_BUILD_TYPE Release)
7178
endif()
72-
set(CMAKE_CXX_FLAGS_DEBUG "-g")
79+
set(CMAKE_CXX_FLAGS_DEBUG "-g -O0")
7380
set(CMAKE_CXX_FLAGS_RELEASE "-O3")
7481

7582
## Current state machine (APP) to be build
@@ -84,8 +91,8 @@ if(NO_ROBOT)
8491
endif()
8592

8693
## Get all source and header files (only the target app folder is included)
87-
file(GLOB_RECURSE SOURCES "src/core/*.cpp" "src/core/*.c" "src/hardware/*.cpp" "src/hardware/*.c" "src/apps/${STATE_MACHINE_NAME}/*.c" "src/apps/${STATE_MACHINE_NAME}/*.cpp" "lib/FLNL/src/*.cpp")
88-
file(GLOB_RECURSE HEADERS "src/core/*.h" "src/hardware/*.h" "src/apps/${STATE_MACHINE_NAME}/*.h" )
94+
file(GLOB_RECURSE SOURCES "src/core/*.cpp" "src/core/*.c" "src/hardware/*.cpp" "src/hardware/*.c" "${STATE_MACHINE_PATH}/${STATE_MACHINE_NAME}/*.c" "${STATE_MACHINE_PATH}/${STATE_MACHINE_NAME}/*.cpp" "lib/FLNL/src/*.cpp")
95+
file(GLOB_RECURSE HEADERS "src/core/*.h" "src/hardware/*.h" "${STATE_MACHINE_PATH}/${STATE_MACHINE_NAME}/*.h" )
8996

9097
## Set every folder containing .h file as include directory
9198
set (INCLUDE_DIRS "")
@@ -110,95 +117,64 @@ else()
110117
add_definitions(-DBASE_DIRECTORY=${CMAKE_SOURCE_DIR})
111118
endif()
112119

113-
## Add ROS dependencies
120+
## Add ROS 1 dependencies
114121
if(USE_ROS)
115-
#ROS local compile: use catkin
116-
if(NOT CMAKE_CROSSCOMPILING)
117-
message("--catkin--")
118-
# Required ROS packages
122+
#ROS 1 local compile: use catkin
123+
message("--catkin--")
124+
# Required ROS packages
125+
find_package(catkin REQUIRED COMPONENTS
126+
roscpp
127+
rospy
128+
std_msgs
129+
std_srvs
130+
sensor_msgs
131+
geometry_msgs
132+
dynamic_reconfigure
133+
message_generation
134+
)
135+
if(SIM)
119136
find_package(catkin REQUIRED COMPONENTS
120-
roscpp
121-
rospy
122-
std_msgs
123-
std_srvs
124-
sensor_msgs
125-
geometry_msgs
126-
dynamic_reconfigure
127-
message_generation
128-
)
129-
if(SIM)
130-
find_package(catkin REQUIRED COMPONENTS
131-
controller_manager_msgs
132-
cob_gazebo_ros_control
133-
x2_description
134-
)
135-
endif()
136-
137-
generate_dynamic_reconfigure_options(
138-
config/m1_dynamic_params.cfg
139-
# config/x2_dynamic_params.cfg
140-
)
141-
142-
add_message_files(
143-
FILES
144-
X2Array.msg
145-
X2Acceleration.msg
146-
X2AccelerationMerge.msg
147-
)
148-
149-
generate_messages(
150-
DEPENDENCIES
151-
std_msgs
137+
controller_manager_msgs
138+
cob_gazebo_ros_control
139+
x2_description
152140
)
153-
154-
155-
156-
catkin_package(
157-
# INCLUDE_DIRS include
158-
# LIBRARIES x2
159-
CATKIN_DEPENDS
160-
roscpp
161-
rospy
162-
std_msgs
163-
std_srvs
164-
sensor_msgs
165-
geometry_msgs
166-
dynamic_reconfigure
167-
message_runtime
168-
# DEPENDS system_lib
169-
)
170-
171-
#include CATKIN
172-
include_directories(${catkin_INCLUDE_DIRS})
173-
set(ROS_LIBRARIES ${catkin_LIBRARIES})
174-
#Cross-compile with ROS (w/o catkin)
175-
else()
176-
# Required ROS packages
177-
find_package(roscpp REQUIRED CONFIG ONLY_CMAKE_FIND_ROOT_PATH)
178-
find_package(std_msgs REQUIRED CONFIG ONLY_CMAKE_FIND_ROOT_PATH)
179-
find_package(sensor_msgs REQUIRED CONFIG ONLY_CMAKE_FIND_ROOT_PATH)
180-
find_package(geometry_msgs REQUIRED CONFIG ONLY_CMAKE_FIND_ROOT_PATH)
181-
# If cross-compiling force search in sysroot
182-
if(IS_DIRECTORY ${CMAKE_SYSROOT})
183-
message("-- Using sysroot folder: ${CMAKE_SYSROOT}")
184-
#Reset include dirs towards sysroot only
185-
foreach(inc_dir ${roscpp_INCLUDE_DIRS} ${std_msgs_INCLUDE_DIRS})
186-
string(REGEX REPLACE "^/usr/" "${CMAKE_SYSROOT}usr/" inc_dir_cross ${inc_dir})
187-
include_directories(${inc_dir_cross})
188-
endforeach()
189-
#Reset libraries towards sysroot only
190-
foreach(lib_path ${roscpp_LIBRARIES} ${std_msgs_LIBRARIES})
191-
string(REPLACE "/" ";" lib_path_list ${lib_path}) #Breakdown path in list
192-
list(REVERSE lib_path_list)
193-
list(GET lib_path_list 0 lib) #Get last element (library name)
194-
find_library(new_path ${lib} PATHS ${CMAKE_SYSROOT}) #Force to look for it in actual sysroot path
195-
list(APPEND ROS_LIBRARIES ${new_path}) #Add it
196-
unset(new_path CACHE) #Clear variable to allow new search
197-
endforeach()
198-
else()
199-
message(FATAL_ERROR "No sysroot (CMAKE_SYSROOT) defined or not an accessible path")
200-
endif()
201141
endif()
142+
143+
generate_dynamic_reconfigure_options(
144+
config/m1_dynamic_params.cfg
145+
config/x2_dynamic_params.cfg
146+
)
147+
148+
add_message_files(
149+
FILES
150+
X2Array.msg
151+
X2Acceleration.msg
152+
X2AccelerationMerge.msg
153+
)
154+
155+
generate_messages(
156+
DEPENDENCIES
157+
std_msgs
158+
)
159+
160+
catkin_package(
161+
# INCLUDE_DIRS include
162+
# LIBRARIES x2
163+
CATKIN_DEPENDS
164+
roscpp
165+
rospy
166+
std_msgs
167+
std_srvs
168+
sensor_msgs
169+
geometry_msgs
170+
dynamic_reconfigure
171+
message_runtime
172+
# DEPENDS system_lib
173+
)
174+
175+
#include CATKIN
176+
include_directories(${catkin_INCLUDE_DIRS})
177+
set(ROS_LIBRARIES ${catkin_LIBRARIES})
202178
endif()
203179

204180

@@ -231,4 +207,4 @@ if(USE_ROS)
231207
endif()
232208

233209

234-
message("-----------------------------------------------\nBuilding application ${APP_NAME}\n-----------------------------------------------")
210+
message("-----------------------------------------------\nBuilding application ${APP_NAME}\n-----------------------------------------------")

README.md

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22

33
CORC is a free and open source robotic development software stack, written in C++.
44

5-
The project was initiated at the University of Melbourne in partnership with Fourier Intelligence, however has welcomed (and continues to welcome) collaborators from all institutions. The project was initially developed to run on an ExoMotus X2 Exoskeleton powered by a Beaglebone Black, however, the software is designed to be extensible to any embedded Linux and CANopen enabled Robotic platform. The repository currently also includes code which has been run on the ArmMotus M1 and M3 rehabilitation devices, and using desktop or laptop Ubuntu installations.
5+
The project was initiated at the University of Melbourne in partnership with Fourier Intelligence, however has welcomed (and continues to welcome) collaborators from all institutions. The project was initially developed to run on an ExoMotus X2 Exoskeleton powered by a Beaglebone Black, however, the software is designed to be extensible to any embedded Linux and CANopen enabled Robotic platform. The repository currently also includes code which has been run on the ArmMotus M1, M2 and M3 (EMU) rehabilitation devices, and using desktop or laptop Ubuntu installations.
66

77
## The CANOpen Robot Controller project includes:
88

99
- An extensible framework to represent multibody rigid robotic systems.
10-
- An event driven state machine to develop custom applications (see [here](doc/3.Software/StateMachine.md)).
10+
- An event driven state machine to develop custom applications (see [here](doc/3.Software/CustomApplication.md)).
1111
- An implementation of [CANopen Socket](https://github.com/CANopenNode/CANopenSocket) to provide an interface between CAN enabled embedded Linux system and CANopen-based motor drivers/sensors.
1212
- Documentation (this page and associated ones and code Doxygen).
13-
- Functional application examples.
13+
- Functional application examples.
1414

1515
### Project Overview
1616

@@ -34,7 +34,7 @@ CORC relies on [spdlog](https://github.com/gabime/spdlog) for both general loggi
3434
See [here](doc/3.Software/Logging.md) for more info on using the logging system.
3535

3636
### ROS Support
37-
See [here](doc/1.GettingStarted/Simulation.md) for instructions on how to build and run a CORC app with ROS support.
37+
See [here](doc/1.GettingStarted/AdvancedSimulationAndHardwareTesting.md) for instructions on how to build and run a CORC app with ROS support.
3838

3939
### Network communication
4040
See [here](doc/3.Software/NetworkCommunication.md) for instructions on using libFLNL for communication.
@@ -47,10 +47,8 @@ To generate the Doxygen documentation of the code you can simply run `doxygen Do
4747

4848
## Developer Information
4949

50-
- Detailed documentation: https://exoembedded.readthedocs.io/en/latest/
51-
- Source code documentation: https://capstonealex.github.io/exo/index.html
52-
- Project Repository: https://github.com/capstonealex/exo
5350
- CANopen Socket: https://github.com/CANopenNode/CANopenSocket
51+
- CANopen CiA 402 (motor drive standard) ressources: https://www.can-cia.org/can-knowledge/canopen/cia402/ and https://doc.synapticon.com/software/40/object_dict/all_objects/index.html#all-objects
5452

5553

5654
## Contributors

config/M3_params.yaml

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,13 @@
2626
EMU_MELB:
2727
dqMax: 360 # Max joint speed (deg.s-1) Set to 1 rot/s
2828
tauMax: 42 # Max joint torque (Nm) Set to max motor torque w/ 1:22 reduction (yes, this is the actual value!)
29+
iPeakDrives: [45.0, 45.0, 45.0] #Drive peak current (I peak)
30+
motorCstt: [1., 1., 1.] #Motors constants
31+
qSigns: [1, 1, 1] # Joints direction
2932

3033
linkLengths: [0.056, 0.135, 0.5, 0.475] # Link lengths used for kinematic models (in m), excluding tool
3134
linkMasses: [0., 0.450, 0.400, 0.100, .0] # Link masses used for gravity compensation (in kg), excluding tool
32-
35+
3336
qLimits: [-45, 45, -15, 70, 0, 95] # Joints limits (in deg) {q1_min, q1_max, q2_min, q2_max, q3_min, q3_max}
3437
qCalibration: [-38, 70, 95] # Calibration configuration (in deg): posture in which the robot is when using the calibration procedure
3538

@@ -44,20 +47,24 @@ EMU_MELB:
4447

4548
EMU_FOURIER:
4649
dqMax: 360 # Max joint speed (deg.s-1) Set to 1 rot/s
47-
tauMax: 42 # Max joint torque (Nm) Set to max motor torque w/ 1:22 reduction (yes, this is the actual value!)
50+
tauMax: 80 # Max joint torque (Nm) Set to max motor torque w/ 1:22 reduction (yes, this is the actual value!)
51+
iPeakDrives: [45.0, 23.0, 23.0] #Drive peak current (I peak): Values look wrong but work on real system in combination w/ below motor constants.
52+
motorCstt: [0.132, 0.132, 0.132] #Motors constants
4853
qSigns: [-1, 1, -1] # Joints direction
4954

50-
linkLengths: [0.056, 0.135, 0.5, 0.615] # Link lengths used for kinematic models (in m), excluding tool
51-
linkMasses: [0, 0.450, 0.400, 0.100, .270] # Link masses used for gravity compensation (in kg), excluding tool
55+
linkLengths: [0.0, 0.135, 0.5, 0.615] # Link lengths used for kinematic models (in m), excluding tool
56+
massCoeff: [-1.30, -1.06] # Mass coefficient (identified) used for gravity compensation (in kg), excluding tool. Model is tau[1]=M[0] * sin(q[1])*g and tau[2]=M[1] * cos(q[2])*g ;
57+
qSpringK: [0, 2.42, 4.19] #Joint spring compensation: tau=Ko+K*q
58+
qSpringKo: [0, 0.47, 0]
5259

53-
qLimits: [-43, 43, -15, 70, 0, 95] # Joints limits (in deg) {q1_min, q1_max, q2_min, q2_max, q3_min, q3_max}
60+
qLimits: [-42, 42, -15, 70, 0, 95] # Joints limits (in deg) {q1_min, q1_max, q2_min, q2_max, q3_min, q3_max}
5461
qCalibration: [+44, 76, 90] # Calibration configuration (in deg): posture in which the robot is when using the calibration procedure
5562

56-
frictionVis: [0.2, 0.2, 0.2] # Joint viscous friction compensation coefficients
57-
frictionCoul: [0., 0., 0.] # Joint Coulomb (static) friction compensation coefficients
63+
frictionVis: [0.33, 0.76, 0.69] # Joint viscous friction compensation coefficients
64+
frictionCoul: [0.35, 0.19, 0.24] # Joint Coulomb (static) friction compensation coefficients
5865

5966
#End-effector description
6067
tool:
6168
name: "Fourier Handle"
6269
length: 0.0 #Tool length from attachment
63-
mass: 0.345 #Tool mass in kg
70+
mass: 0.1 #Tool mass in kg

doc/1.GettingStarted/GettingStarted.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ CORC is flexible in that it can run on any computer with a Controller Area Netwo
1010

1111
Examples of use of a dedicated embedded computer are when the robotic device is mobile (such as an assistive exoskeleton) or when separation between the robot controller and the user interface is desired (such as on deployment-ready rehabilitation devices). Alternatively, you may choose to use a desktop computer if you wish to run more powerful control algorithms on your device, or if your development is more experimental in nature. With appropriate choice of software packages, it is also possible to transition deployment from a desktop computer to an embedded computer.
1212

13+
> Note that cross-compiling a ROS app is theoretically possible but not described in this documentation (contibutions are welcome!).
14+
1315
## Choice of Development Environment
1416
Independent of the deployment environment, a choice may also be made regarding the development environment. If the deployment environment is Linux-based, this can be the same device as your deployment computer (although, development will typically require more computational power than deployment). Alternatively, you may develop on a different computer to the deployment computer. In this case, you have the choice of using either Windows or Linux based environments*, and you will need to cross compile for your deployment environment (i.e. compile on a system which is not used to run the executable). This requires an appropriate toolchain to be installed.
1517

0 commit comments

Comments
 (0)