Skip to content

Commit

Permalink
better way to change communication method and hardware type
Browse files Browse the repository at this point in the history
  • Loading branch information
joshua-8 committed Apr 4, 2024
1 parent 03173ed commit 0f3933e
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 21 deletions.
15 changes: 10 additions & 5 deletions RCMv2/RCMv2.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -46,7 +51,7 @@ void Always()
delay(1);
}

#ifndef RCM_ROS
#if RCM_COMM_METHOD == RCM_COMM_EWD
void WifiDataToParse()
{
enabled = EWD::recvBl();
Expand All @@ -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 )
Expand Down
20 changes: 16 additions & 4 deletions RCMv2/rcm.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,15 @@
#include <Arduino.h>
#include <JMotor.h> //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
Expand Down Expand Up @@ -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 <FastLED.h>
#include <TMC7300.h>
Expand Down Expand Up @@ -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
Expand All @@ -142,7 +152,9 @@ boolean wasEnabled = false;
#endif

#include <ESP32_easy_wifi_data.h> //https://github.com/joshua-8/ESP32_easy_wifi_data >=v1.0.0
#else

#elif RCM_COMM_METHOD == RCM_COMM_ROS

#include <micro_ros_arduino.h>
#include <rcl/error_handling.h>
#include <rcl/rcl.h>
Expand Down
24 changes: 12 additions & 12 deletions RCMv2/rcmutil.h
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand All @@ -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()
{
Expand Down Expand Up @@ -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
}
Expand All @@ -127,17 +127,17 @@ 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()) {
enabled = false;
}
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
Expand All @@ -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
Expand Down

0 comments on commit 0f3933e

Please sign in to comment.