Skip to content

Commit ad325be

Browse files
M1 digital input and output function works. (#64)
* M1 digital input and output function works. * Update m1_real.launch Changed can1 to can0 for consistency with the Getting Started Guide. Co-authored-by: Justin <[email protected]>
1 parent 4c9659a commit ad325be

File tree

6 files changed

+35
-42
lines changed

6 files changed

+35
-42
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,5 @@ CANopenSocket/canopend/X2_log.txt
99
/build/*
1010
bbbxc
1111
EXO_APP_2020
12-
cmake-build-debug/
12+
cmake-build-debug/
13+
.idea/

CMakeLists.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ project(CORC C CXX)
1414

1515
set (STATE_MACHINE_NAME "ExoTestMachine")
1616
#set (STATE_MACHINE_NAME "M1DemoMachine")
17-
#set (STATE_MACHINE_NAME "M1DemoMachineROS")
17+
#set (STATE_MACHINE_NAME "M1DemoMachineROS") # uncomment other cfg files under generate_dynamic_reconfigure_options
1818
#set (STATE_MACHINE_NAME "M2DemoMachine")
1919
#set (STATE_MACHINE_NAME "M3DemoMachine")
20-
#set (STATE_MACHINE_NAME "X2DemoMachine")
20+
#set (STATE_MACHINE_NAME "X2DemoMachine") # uncomment other cfg files under generate_dynamic_reconfigure_options
2121
#set (STATE_MACHINE_NAME "LoggingDevice")
2222

2323
# Comment to use actual hardware, uncomment for a nor robot (virtual) app
@@ -136,7 +136,7 @@ if(USE_ROS)
136136

137137
generate_dynamic_reconfigure_options(
138138
config/m1_dynamic_params.cfg
139-
config/x2_dynamic_params.cfg
139+
# config/x2_dynamic_params.cfg
140140
)
141141

142142
add_message_files(

launch/m1_real.launch

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
<?xml version="1.0"?>
22
<launch>
33

4-
<arg name="robot_name_1" default="m1_x"/>
4+
<arg name="robot_name_1" default="m1_y"/>
55
<arg name="name_spaces" default="[$(arg robot_name_1)]"/>
66

77
<!-- CORC M1_X -->
8-
<node name="$(arg robot_name_1)" pkg="CORC" type="MultiM1Machine_APP" output="screen" args="-can can0"/>
8+
<node name="$(arg robot_name_1)" pkg="CORC" type="M1DemoMachineROS_APP" output="screen" args="-can can0"/>
9+
910

1011
<!-- rqt -->
1112
<node name="rqt" pkg="CORC" type="rqt.sh">

src/apps/M1DemoMachineROS/states/MultiControllerState.cpp

Lines changed: 21 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -179,54 +179,40 @@ void MultiControllerState::during(void) {
179179
}
180180
}
181181
else if (controller_mode_ == 11){ // SEND HIGH
182-
// std::cout<<"SET HIGH"<<std::endl;
183182
double time = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::steady_clock::now() - time0).count()/1000.0;
184183

185-
if(robot_->getRobotName() == "m1_y"){
186-
//std::cout<<"ROBOT Y"<<std::endl;
187-
if(time > 2.0){
188-
if (digitalInValue_ == 1) {
189-
digitalOutValue_ = 0;
190-
robot_->setDigitalOut(digitalOutValue_);
191-
}
192-
}
193-
else if(time > 1.0){
194-
if (digitalInValue_ == 0) {
195-
digitalOutValue_ = 1;
196-
robot_->setDigitalOut(digitalOutValue_);
197-
}
184+
if(time > 1.0){
185+
if (digitalOutValue_ == 0) {
186+
digitalOutValue_ = 1;
187+
robot_->setDigitalOut(digitalOutValue_);
198188
}
199189
}
200190
}
201191
else if (controller_mode_ == 12){ // SEND LOW
202-
// std::cout<<"SET LOW"<<std::endl;
203192
double time = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::steady_clock::now() - time0).count()/1000.0;
204193

205-
if(robot_->getRobotName() == "m1_y"){
206-
//std::cout<<"ROBOT Y"<<std::endl;
207-
if(time > 1.0){
208-
if (digitalInValue_ == 1) {
209-
digitalOutValue_ = 0;
210-
robot_->setDigitalOut(digitalOutValue_);
211-
}
194+
if(time > 1.0){
195+
if (digitalOutValue_ == 1) {
196+
digitalOutValue_ = 0;
197+
robot_->setDigitalOut(digitalOutValue_);
212198
}
213199
}
214200
}
215201
else if (controller_mode_ == 13){ // SEND HIGH-LOW once
216-
217202
double time = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::steady_clock::now() - time0).count()/1000.0;
218-
if(robot_->getRobotName() == "m1_y"){
219-
//std::cout<<"ROBOT Y"<<std::endl;
220-
if (time > 1.0) {
221-
//std::cout<<"Trigger Sent"<<std::endl;
222-
digitalOutValue_ = (digitalOutValue_ == 1) ? 0 : 1;
203+
204+
if(time > 2.0){
205+
if (digitalOutValue_ == 1) {
206+
digitalOutValue_ = 0;
207+
robot_->setDigitalOut(digitalOutValue_);
208+
}
209+
}
210+
else if(time > 1.0){
211+
if (digitalOutValue_ == 0) {
212+
digitalOutValue_ = 1;
223213
robot_->setDigitalOut(digitalOutValue_);
224-
time0 = std::chrono::steady_clock::now();
225214
}
226215
}
227-
}
228-
if(robot_->getRobotName() == "m1_y"){
229-
digitalInValue_ = robot_->getDigitalIn();
230216
}
231217
}
232218

@@ -267,6 +253,9 @@ void MultiControllerState::dynReconfCallback(CORC::dynamic_paramsConfig &config,
267253
if(controller_mode_ == 11) robot_->setDigitalOut(0);
268254
if(controller_mode_ == 12) time0 = std::chrono::steady_clock::now();
269255
if(controller_mode_ == 12) robot_->setDigitalOut(1);
256+
if(controller_mode_ == 13) time0 = std::chrono::steady_clock::now();
257+
if(controller_mode_ == 13) robot_->setDigitalOut(0);
258+
270259
}
271260

272261
return;

src/core/robot/Drive.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -295,8 +295,8 @@ class Drive {
295295
{TARGET_POS, 4},
296296
{TARGET_VEL, 4},
297297
{TARGET_TOR, 2},
298-
{DIGITAL_IN, 4},
299-
{DIGITAL_OUT, 4}};
298+
{DIGITAL_IN, 2},
299+
{DIGITAL_OUT, 2}};
300300

301301
/**
302302
* \brief Map between the Commonly-used OD entries and their addresses and sub-index - used to generate PDO Configurations
@@ -343,8 +343,8 @@ class Drive {
343343
INTEGER32 targetPos=0;
344344
INTEGER32 targetVel=0;
345345
INTEGER16 targetTor=0;
346-
UNSIGNED32 digitalIn=0;
347-
UNSIGNED32 digitalOut=0;
346+
UNSIGNED16 digitalIn=0;
347+
UNSIGNED16 digitalOut=0;
348348
/**
349349
* \brief Current error state of the drive
350350
*

src/hardware/platforms/M1/RobotM1.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ RobotM1::RobotM1(string robot_name, string yaml_config_file): Robot(robot_name
3535
posControlMotorProfile.profileDeceleration = 500.*65535*10000/4000000;
3636

3737
//Check if YAML file exists and contain robot parameters
38+
robotName_ = robot_name;
3839
initialiseFromYAML(yaml_config_file);
3940

4041
initialiseJoints();
@@ -144,6 +145,7 @@ bool RobotM1::setDigitalOut(int digital_out) {
144145
}
145146

146147
int RobotM1::getDigitalIn() {
148+
147149
return ((JointM1 *)joints[0])->getDigitalIn();
148150
}
149151

0 commit comments

Comments
 (0)