Skip to content

Commit 4cb76be

Browse files
committed
Merge PR #11 (Add ROS Position Control via Topic Subscription)
* release new minor version: `v0.2.0` * resolves merge conflicts
2 parents 4b89e76 + 4bab4c8 commit 4cb76be

9 files changed

+93
-17
lines changed

arduino_control/control_as_client/a_declarations.ino

+7-4
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,22 @@
77
void setup_network();
88
void setup_ros();
99

10-
// Feedback Position
11-
void report_serial();
10+
// Conversions
1211
float posn_incr2inch();
1312
float posn_incr2meter();
13+
float temperature_count2degree();
1414

15-
// Feedback Sensors
15+
// Feedback
16+
void report_serial();
1617
bool get_fork_state();
1718
bool get_press_power_switch_state();
18-
float temperature_count2degree();
1919
bool get_temperature1_alarm1_state();
2020

2121
// External Indicators
2222
void set_remote_indicator();
2323

2424
// ROS & Network Interfaces
25+
void cb_joint_command(const std_msgs::Float64);
2526
void update_ros_robot_status();
2627
void update_ros_joint_states();
2728
void update_ros_fork_state();
@@ -34,6 +35,8 @@ void clearSerialBuffer();
3435
void moveDown();
3536
void moveUp();
3637
void halt();
38+
void set_flow_control_valve(bool state);
39+
bool tempFlowValveState = false;
3740

3841
// Controller
3942
void controller();

arduino_control/control_as_client/b_configure.ino

+7
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,13 @@ const float minStrokeSoft = 0.0;
4040
const float maxStrokeHard = 0.20294907837554; // not currently used by control
4141
const float minStrokeHard = 0.0; // not currently used by control
4242

43+
//Remote Interface
44+
bool ros_enabled = false;
45+
float last_ros_joint_command = 0; // Initialize goal to zero for safety
46+
47+
//Position control
48+
const float motionBuffer = 0.012;
49+
4350
//Target Position
4451
bool remoteMotionEnabled = false;
4552
bool directionOfMotion; // false = down, true = up

arduino_control/control_as_client/c_setup.ino

+6
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ std_msgs::Bool fork_state_msg;
1515
std_msgs::Bool press_power_switch_state_msg;
1616
std_msgs::Bool temperature1_alarm1_state_msg;
1717
sensor_msgs::Temperature temperature1_msg;
18+
std_msgs::Float64 joint_command;
1819
//industrial_msgs::RobotStatus robot_status_msg;
1920

2021
ros::Publisher pub_joint_states("joint_states", &joint_state_msg);
@@ -24,6 +25,7 @@ ros::Publisher pub_temperature1_alarm1_state("temperature1_alarm1_state", &tempe
2425
ros::Publisher pub_temperature1("temperature1", &temperature1_msg);
2526
//ros::Publisher pub_robot_status("robot_status", &robot_status_msg);
2627

28+
ros::Subscriber<std_msgs::Float64> sub_joint_command("joint_command", cb_joint_command);
2729

2830

2931
// -------------------
@@ -45,6 +47,10 @@ void setup() {
4547
Serial.println("Setup Configuration: Network enabled. Will now attempt to connect to network");
4648
Ethernet.begin(mac);
4749
setup_network();
50+
ros_enabled = true;
51+
}
52+
else {
53+
ros_enabled = false;
4854
}
4955

5056
// Setup ROS handles

arduino_control/control_as_client/control_as_client.ino

+2-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* Author: Adam Buynak
1414
*/
1515

16-
/* Software Version: v0.1.1 */
16+
/* Software Version: v0.2.0 */
1717

1818

1919
#include <Arduino.h>
@@ -33,6 +33,7 @@
3333
#include <std_msgs/Header.h>
3434
#include <sensor_msgs/JointState.h>
3535
#include <std_msgs/Bool.h>
36+
#include <std_msgs/Float64.h>
3637
#include <sensor_msgs/Temperature.h>
3738
//#include <industrial_msgs/RobotStatus.h>
3839

arduino_control/control_as_client/e_motion.ino

+9
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,15 @@ void moveUp() {
1515
}
1616

1717

18+
void set_flow_control_valve(bool state)
19+
{
20+
//Input 'state' sets the speed of the press
21+
//by opening/closing the flow control valve.
22+
//High for fast, LOW for slow
23+
P1.writeDiscrete(state,1,7); //Set the flow control valve to state
24+
}
25+
26+
1827
void halt() {
1928
P1.writeDiscrete(LOW,1,2); //Turn slot 1 channel 1 off
2029
P1.writeDiscrete(LOW,1,3); //Turn slot 1 channel 2 off

arduino_control/control_as_client/g_ros.ino

+26
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,32 @@ void setup_ros() {
1616
nh.advertise(pub_temperature1);
1717
// nh.advertise(pub_robot_status);/
1818

19+
nh.subscribe(sub_joint_command);
20+
}
21+
22+
void cb_joint_command(const std_msgs::Float64& msg) {
23+
24+
// Extract data from message
25+
last_ros_joint_command = msg.data;
26+
27+
// Lookup Current Position
28+
float current_posn = posn_incr2meter(P1.readAnalog(2, 1));
29+
30+
// Soft Stop Limits
31+
if (last_ros_joint_command > maxStrokeSoft) last_ros_joint_command = maxStrokeSoft;
32+
else if (last_ros_joint_command < minStrokeSoft) last_ros_joint_command = minStrokeSoft;
33+
34+
// Set the direction of motion
35+
if (current_posn < last_ros_joint_command) directionOfMotion = false; // down
36+
else directionOfMotion = true; // up
37+
38+
// Serial Feedback
39+
Serial.print("Set New Target Position: ");
40+
Serial.println(last_ros_joint_command, 3);
41+
42+
// Enable Motion
43+
remoteMotionEnabled = true;
44+
remoteTargetAchieved = false;
1945
}
2046

2147

arduino_control/control_as_client/h_controller.ino

+34-10
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ void controller(float current_posn) {
1515
bool override_lockout = (last_override + override_timeout) > millis();
1616

1717
if (mswitch_up || mswitch_dwn || override_lockout) {
18+
set_flow_control_valve(LOW);
1819
set_remote_indicator(false);
20+
remoteMotionEnabled = false;
1921
if ( mswitch_up == true && mswitch_dwn == false ) {
2022
last_override = millis();
2123
moveUp();
@@ -25,9 +27,8 @@ void controller(float current_posn) {
2527
moveDown();
2628
}
2729
else {
28-
remoteMotionEnabled = false;
29-
target_posn = current_posn; // Ensure fail's safe
3030
halt();
31+
target_posn = current_posn; // Ensure fail's safe
3132
}
3233
}
3334

@@ -37,7 +38,12 @@ void controller(float current_posn) {
3738
// Remote Input ~ Serial or ROS
3839
// -----------------------------
3940

40-
if (Serial.available() && override_lockout == false) {
41+
if (Serial.available() && override_lockout == true) {
42+
Serial.println("--- !! Remote Control Lockout. Please wait 5-seconds !! ---");
43+
clearSerialBuffer();
44+
}
45+
46+
else if (Serial.available() && ros_enabled == false && override_lockout == false) {
4147

4248
// Serial Client Input Position of unit: [mm]
4349
target_posn = Serial.parseFloat() * 0.001;
@@ -59,14 +65,16 @@ void controller(float current_posn) {
5965
remoteMotionEnabled = true;
6066
remoteTargetAchieved = false;
6167
}
62-
else if (Serial.available() && override_lockout == true) {
63-
Serial.println("--- !! Remote Control Lockout. Please wait 5-seconds !! ---");
64-
clearSerialBuffer();
68+
69+
else if (ros_enabled == true && override_lockout == false) {
70+
// Serial Client Input Position of unit: [meter]
71+
target_posn = last_ros_joint_command;
6572
}
6673

67-
//else if (_ADD_ROS_CHECK_) {
68-
// //ADD ROS CODE HERE
69-
//}
74+
if (Serial.available() && ros_enabled == true) {
75+
Serial.println("--- !! Serial Control Lockout. Only accepting ROS Control. !! ---");
76+
clearSerialBuffer();
77+
}
7078

7179

7280

@@ -80,13 +88,29 @@ void controller(float current_posn) {
8088
if (directionOfMotion == false && current_posn >= target_posn) remoteTargetAchieved = true; // overshoot moving down
8189
else if (directionOfMotion == true && current_posn <= target_posn) remoteTargetAchieved = true; // overshoot moving up
8290

83-
// Actuate if target not met
91+
// Actuate Control given Target Achieved
8492
if (remoteTargetAchieved == true) {
8593
halt();
94+
set_flow_control_valve(LOW); // default back to slow speed
8695
target_posn = current_posn; // fail safe
8796
}
8897
else if (directionOfMotion == false) moveDown();
8998
else if (directionOfMotion == true) moveUp();
9099

100+
// Set speed of press motion
101+
if(directionOfMotion == false && current_posn > target_posn - motionBuffer) // moving down
102+
{
103+
set_flow_control_valve(LOW);
104+
}
105+
else
106+
{
107+
set_flow_control_valve(HIGH);
108+
}
109+
110+
if(directionOfMotion == true && remoteTargetAchieved == false) // moving up
111+
{
112+
set_flow_control_valve(HIGH);
113+
}
114+
else if (directionOfMotion == true) set_flow_control_valve(LOW);
91115
}
92116
}

arduino_control/control_as_client/i_run.ino

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ void loop()
1919
report_serial(current_posn_incr, current_temp_incr);
2020

2121
// ROS Interface
22-
if (nh.connected()) {
22+
if (nh.connected() && ros_enabled) {
2323

2424
// Set ROS Indicator Light = ON
2525
set_remote_indicator(true);

launch/connect_arduino.launch

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
<launch>
22
<!-- Default Port: 11411 -->
3-
<node pkg="rosserial_server" type="socket_node" name="rosserial_server" output="screen" />
3+
<node pkg="rosserial_server" type="socket_node" name="control_interface" ns="coaliron" output="screen" />
44
</launch>

0 commit comments

Comments
 (0)