diff --git a/RCMv2/RCMv2.ino b/RCMv2/RCMv2.ino index 932843d..023572a 100644 --- a/RCMv2/RCMv2.ino +++ b/RCMv2/RCMv2.ino @@ -5,12 +5,17 @@ /** uncomment one of the following lines depending on which hardware you have */ -// leave all lines commented if you have a standard RCM board -// #define RCM_HARDWARE_VERSION 10 // RCM BYTE V1 +#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 +// #define RCM_HARDWARE_VERSION RCM_BYTE_V2 // version 2.1 of the RCM BYTE // https://github.com/RCMgames/RCM-Hardware-BYTE +// #define RCM_HARDWARE_VERSION RCM_NIBBLE_V1 // version 1 of the RCM Nibble // +// retired hardware +// #define RCM_HARDWARE_VERSION RCM_BYTE_V1 // version 1 of the RCM BYTE // https://github.com/RCMgames/RCM-Hardware-BYTE/tree/v1---archive /** - to use ROS mode switch the platformio project environment to one of the environments that says ROS in the name +uncomment one of the following lines depending on which communication method you want to use */ +#define RCM_COMM_METHOD RCM_COMM_EWD // use the normal communication method for RCM robots +// #define RCM_COMM_METHOD RCM_COMM_ROS // use the ROS communication method #include "rcm.h" //defines pins @@ -46,7 +51,7 @@ void Always() delay(1); } -#ifndef RCM_ROS +#if RCM_COMM_METHOD == RCM_COMM_EWD void WifiDataToParse() { enabled = EWD::recvBl(); @@ -70,7 +75,7 @@ void configWifi() // EWD::APPassword = "rcmPassword"; // EWD::APPort = 25210; } -#else ////////////// ignore everything below this line unless you're using ROS mode///////////////////////////////////////////// +#elif RCM_COMM_METHOD == RCM_COMM_ROS ////////////// ignore everything below this line unless you're using ROS mode///////////////////////////////////////////// void ROSWifiSettings() { // SSID, password, IP, port (on a computer run: sudo docker run -it --rm --net=host microros/micro-ros-agent:iron udp4 --port 8888 ) diff --git a/RCMv2/rcm.h b/RCMv2/rcm.h index c38aec7..3608d74 100644 --- a/RCMv2/rcm.h +++ b/RCMv2/rcm.h @@ -4,7 +4,15 @@ #include #include //https://github.com/joshua-8/JMotor -#ifndef RCM_HARDWARE_VERSION +#define RCM_ORIGINAL 1 +#define RCM_BYTE_V1 2 +#define RCM_BYTE_V2 3 +#define RCM_NIBBLE_V1 4 + +#define RCM_COMM_EWD 1 +#define RCM_COMM_ROS 2 + +#if RCM_HARDWARE_VERSION == RCM_ORIGINAL #define port1Pin 32 #define port2Pin 33 #define port3Pin 25 @@ -38,7 +46,7 @@ void setupMotors() { } #define EWDmaxWifiRecvBufSize 41 #endif -#elif RCM_HARDWARE_VERSION == 10 // rcmByte_1 +#elif RCM_HARDWARE_VERSION == RCM_BYTE_V1 #include #include @@ -127,12 +135,14 @@ void setupMotors() digitalWrite(motorsEnablePin, HIGH); } +#else +void setupMotors() { } #endif // RCM_HARDWARE_VERSION boolean enabled = false; boolean wasEnabled = false; -#ifndef RCM_ROS +#if RCM_COMM_METHOD == RCM_COMM_EWD #ifndef EWDmaxWifiSendBufSize #define EWDmaxWifiSendBufSize 200 @@ -142,7 +152,9 @@ boolean wasEnabled = false; #endif #include //https://github.com/joshua-8/ESP32_easy_wifi_data >=v1.0.0 -#else + +#elif RCM_COMM_METHOD == RCM_COMM_ROS + #include #include #include diff --git a/RCMv2/rcmutil.h b/RCMv2/rcmutil.h index 22495b1..aa7f1c6 100644 --- a/RCMv2/rcmutil.h +++ b/RCMv2/rcmutil.h @@ -17,7 +17,7 @@ extern void WifiDataToParse(); extern void WifiDataToSend(); extern void setupMotors(); -#ifndef RCM_HARDWARE_VERSION +#if RCM_HARDWARE_VERSION == RCM_ORIGINAL void setupRSL() { @@ -40,7 +40,7 @@ void disabledRSL() digitalWrite(ONBOARD_LED, HIGH); // on, disabled } -#elif RCM_HARDWARE_VERSION == 10 +#elif RCM_HARDWARE_VERSION == RCM_BYTE_V1 void setupRSL() { @@ -98,27 +98,27 @@ void setup() setupMotors(); PowerOn(); Disable(); -#ifndef RCM_ROS +#if RCM_COMM_METHOD == RCM_COMM_EWD configWifi(); EWD::setupWifi(WifiDataToParse, WifiDataToSend); -#else +#elif RCM_COMM_METHOD == RCM_COMM_ROS setupROS(); #endif } boolean connectedToWifi() { -#ifndef RCM_ROS +#if RCM_COMM_METHOD == RCM_COMM_EWD return EWD::wifiConnected; -#else +#elif RCM_COMM_METHOD == RCM_COMM_ROS return !ROSCheckFail; #endif } boolean connectionTimedOut() { -#ifndef RCM_ROS +#if RCM_COMM_METHOD == RCM_COMM_EWD return EWD::timedOut(); -#else +#elif RCM_COMM_METHOD == RCM_COMM_ROS return (millis() - lastEnableSentMillis) > rosWifiTimeout; #endif } @@ -127,9 +127,9 @@ extern void ROSrun(); void loop() { -#ifndef RCM_ROS +#if RCM_COMM_METHOD == RCM_COMM_EWD EWD::runWifiCommunication(); -#else +#elif RCM_COMM_METHOD == RCM_COMM_ROS ROSrun(); #endif if (!connectedToWifi() || connectionTimedOut()) { @@ -137,7 +137,7 @@ void loop() } Always(); if (enabled && !wasEnabled) { -#if RCM_HARDWARE_VERSION == 10 +#if RCM_HARDWARE_VERSION == RCM_BYTE_V1 #ifndef RCM_BYTE_DO_NOT_USE_SAFE_DISABLE digitalWrite(motorsEnablePin, HIGH); #endif @@ -148,7 +148,7 @@ void loop() if (!enabled && wasEnabled) { Disable(); -#if RCM_HARDWARE_VERSION == 10 +#if RCM_HARDWARE_VERSION == RCM_BYTE_V1 #ifndef RCM_BYTE_DO_NOT_USE_SAFE_DISABLE digitalWrite(motorsEnablePin, LOW); #endif