Skip to content

Commit 0f3933e

Browse files
committed
better way to change communication method and hardware type
1 parent 03173ed commit 0f3933e

File tree

3 files changed

+38
-21
lines changed

3 files changed

+38
-21
lines changed

RCMv2/RCMv2.ino

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,17 @@
55
/**
66
uncomment one of the following lines depending on which hardware you have
77
*/
8-
// leave all lines commented if you have a standard RCM board
9-
// #define RCM_HARDWARE_VERSION 10 // RCM BYTE V1
8+
#define RCM_HARDWARE_VERSION RCM_ORIGINAL // versions 1 to 3 of the original RCM hardware // https://github.com/RCMgames/RCM_hardware_documentation_and_user_guide
9+
// #define RCM_HARDWARE_VERSION RCM_BYTE_V2 // version 2.1 of the RCM BYTE // https://github.com/RCMgames/RCM-Hardware-BYTE
10+
// #define RCM_HARDWARE_VERSION RCM_NIBBLE_V1 // version 1 of the RCM Nibble //
11+
// retired hardware
12+
// #define RCM_HARDWARE_VERSION RCM_BYTE_V1 // version 1 of the RCM BYTE // https://github.com/RCMgames/RCM-Hardware-BYTE/tree/v1---archive
1013

1114
/**
12-
to use ROS mode switch the platformio project environment to one of the environments that says ROS in the name
15+
uncomment one of the following lines depending on which communication method you want to use
1316
*/
17+
#define RCM_COMM_METHOD RCM_COMM_EWD // use the normal communication method for RCM robots
18+
// #define RCM_COMM_METHOD RCM_COMM_ROS // use the ROS communication method
1419

1520
#include "rcm.h" //defines pins
1621

@@ -46,7 +51,7 @@ void Always()
4651
delay(1);
4752
}
4853

49-
#ifndef RCM_ROS
54+
#if RCM_COMM_METHOD == RCM_COMM_EWD
5055
void WifiDataToParse()
5156
{
5257
enabled = EWD::recvBl();
@@ -70,7 +75,7 @@ void configWifi()
7075
// EWD::APPassword = "rcmPassword";
7176
// EWD::APPort = 25210;
7277
}
73-
#else ////////////// ignore everything below this line unless you're using ROS mode/////////////////////////////////////////////
78+
#elif RCM_COMM_METHOD == RCM_COMM_ROS ////////////// ignore everything below this line unless you're using ROS mode/////////////////////////////////////////////
7479
void ROSWifiSettings()
7580
{
7681
// SSID, password, IP, port (on a computer run: sudo docker run -it --rm --net=host microros/micro-ros-agent:iron udp4 --port 8888 )

RCMv2/rcm.h

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,15 @@
44
#include <Arduino.h>
55
#include <JMotor.h> //https://github.com/joshua-8/JMotor
66

7-
#ifndef RCM_HARDWARE_VERSION
7+
#define RCM_ORIGINAL 1
8+
#define RCM_BYTE_V1 2
9+
#define RCM_BYTE_V2 3
10+
#define RCM_NIBBLE_V1 4
11+
12+
#define RCM_COMM_EWD 1
13+
#define RCM_COMM_ROS 2
14+
15+
#if RCM_HARDWARE_VERSION == RCM_ORIGINAL
816
#define port1Pin 32
917
#define port2Pin 33
1018
#define port3Pin 25
@@ -38,7 +46,7 @@ void setupMotors() { }
3846
#define EWDmaxWifiRecvBufSize 41
3947
#endif
4048

41-
#elif RCM_HARDWARE_VERSION == 10 // rcmByte_1
49+
#elif RCM_HARDWARE_VERSION == RCM_BYTE_V1
4250

4351
#include <FastLED.h>
4452
#include <TMC7300.h>
@@ -127,12 +135,14 @@ void setupMotors()
127135
digitalWrite(motorsEnablePin, HIGH);
128136
}
129137

138+
#else
139+
void setupMotors() { }
130140
#endif // RCM_HARDWARE_VERSION
131141

132142
boolean enabled = false;
133143
boolean wasEnabled = false;
134144

135-
#ifndef RCM_ROS
145+
#if RCM_COMM_METHOD == RCM_COMM_EWD
136146

137147
#ifndef EWDmaxWifiSendBufSize
138148
#define EWDmaxWifiSendBufSize 200
@@ -142,7 +152,9 @@ boolean wasEnabled = false;
142152
#endif
143153

144154
#include <ESP32_easy_wifi_data.h> //https://github.com/joshua-8/ESP32_easy_wifi_data >=v1.0.0
145-
#else
155+
156+
#elif RCM_COMM_METHOD == RCM_COMM_ROS
157+
146158
#include <micro_ros_arduino.h>
147159
#include <rcl/error_handling.h>
148160
#include <rcl/rcl.h>

RCMv2/rcmutil.h

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ extern void WifiDataToParse();
1717
extern void WifiDataToSend();
1818
extern void setupMotors();
1919

20-
#ifndef RCM_HARDWARE_VERSION
20+
#if RCM_HARDWARE_VERSION == RCM_ORIGINAL
2121

2222
void setupRSL()
2323
{
@@ -40,7 +40,7 @@ void disabledRSL()
4040
digitalWrite(ONBOARD_LED, HIGH); // on, disabled
4141
}
4242

43-
#elif RCM_HARDWARE_VERSION == 10
43+
#elif RCM_HARDWARE_VERSION == RCM_BYTE_V1
4444

4545
void setupRSL()
4646
{
@@ -98,27 +98,27 @@ void setup()
9898
setupMotors();
9999
PowerOn();
100100
Disable();
101-
#ifndef RCM_ROS
101+
#if RCM_COMM_METHOD == RCM_COMM_EWD
102102
configWifi();
103103
EWD::setupWifi(WifiDataToParse, WifiDataToSend);
104-
#else
104+
#elif RCM_COMM_METHOD == RCM_COMM_ROS
105105
setupROS();
106106
#endif
107107
}
108108

109109
boolean connectedToWifi()
110110
{
111-
#ifndef RCM_ROS
111+
#if RCM_COMM_METHOD == RCM_COMM_EWD
112112
return EWD::wifiConnected;
113-
#else
113+
#elif RCM_COMM_METHOD == RCM_COMM_ROS
114114
return !ROSCheckFail;
115115
#endif
116116
}
117117
boolean connectionTimedOut()
118118
{
119-
#ifndef RCM_ROS
119+
#if RCM_COMM_METHOD == RCM_COMM_EWD
120120
return EWD::timedOut();
121-
#else
121+
#elif RCM_COMM_METHOD == RCM_COMM_ROS
122122
return (millis() - lastEnableSentMillis) > rosWifiTimeout;
123123
#endif
124124
}
@@ -127,17 +127,17 @@ extern void ROSrun();
127127

128128
void loop()
129129
{
130-
#ifndef RCM_ROS
130+
#if RCM_COMM_METHOD == RCM_COMM_EWD
131131
EWD::runWifiCommunication();
132-
#else
132+
#elif RCM_COMM_METHOD == RCM_COMM_ROS
133133
ROSrun();
134134
#endif
135135
if (!connectedToWifi() || connectionTimedOut()) {
136136
enabled = false;
137137
}
138138
Always();
139139
if (enabled && !wasEnabled) {
140-
#if RCM_HARDWARE_VERSION == 10
140+
#if RCM_HARDWARE_VERSION == RCM_BYTE_V1
141141
#ifndef RCM_BYTE_DO_NOT_USE_SAFE_DISABLE
142142
digitalWrite(motorsEnablePin, HIGH);
143143
#endif
@@ -148,7 +148,7 @@ void loop()
148148
if (!enabled && wasEnabled) {
149149
Disable();
150150

151-
#if RCM_HARDWARE_VERSION == 10
151+
#if RCM_HARDWARE_VERSION == RCM_BYTE_V1
152152
#ifndef RCM_BYTE_DO_NOT_USE_SAFE_DISABLE
153153
digitalWrite(motorsEnablePin, LOW);
154154
#endif

0 commit comments

Comments
 (0)