OpenROV 2.8 / add function or sensor


#1

Hello.
I am using a openrov v2.8 and 30.0.3 software image.
I want to add some functions(simple serial.println) in cockpit.(just for a test)
I added .c and .cpp file in cloud9 and modified Aconfig.h and so on.
But, it was not applied in the cockpit.
I think some code has error or mistakes.
So, I want some sample code about modify and adding to study. Also, I need a guide to modify or adding some functions at v2.8. I want to know method about adding some modules.

I attatched some modified file.

—ArduSlave.h—

#pragma once
#include “CPin.h”
#include “AConfig.h”
_ #include “CModule.h” _

class ArduSlave : public CModule
{
public:
_ void Initialize();_
_ void Update( CCommand& commandIn );_
};

----ArduSlave.cpp-----
#include “AConfig.h”
_ #if(HAS_ArduSlave)_
_ #include “NDataManager.h”_
_ #include “CPin.h”_
_ #include “ArduSlave.h”_
_ #include <Arduino.h>_
_ #include “NConfigManager.h”_
_ _
_ namespace {}_
_ _
_ _
_ void ArduSlave::Initialize(){_
_ Serial.begin(9600);_
_ }_
_ _
_ void ArduSlave::Update( CCommand& commandIn ){_
_ _
_ Serial.print(F(“ArduSlave_TEST:”));_
_ Serial.println(’;’);_
_ }_
_ _
_ #endif _

------AConfig.h-------
#pragma once

/* This section is for modules and their configuration. IF you have not setup you pins with the
* standard configuration of the OpenROV kits, you should probably clone the cape or controlboard
* and change the pin definitions there. Things not wired to specific pins but on the I2C bus will
* have the address defined in this file.
*/

#include “BoardConfig.h”

// Kit:
// The boards are auto configure in the on-beaglebone build process in the BoardConfig.h which gets
// created. If running directly in an IDE, the BoardConfig.h wont exist and the #defines below will be
// used instead.

// ---------------------------------------------------------
// Standard Modules
// ---------------------------------------------------------

// Choose a cape or controller board
#define HAS_STD_CAPE (0)
#define HAS_OROV_CONTROLLERBOARD_25 (1)

#if !(HAS_OROV_CONTROLLERBOARD_25) && !(HAS_STD_CAPE)
# error “You must select either standard cape or controllerboard25 in the AConfig.h file as they have predefined pin values required by other libraries.”
#endif

#define HAS_STD_LIGHTS (1)
#define HAS_STD_CALIBRATIONLASERS (1)
#define HAS_STD_CAMERAMOUNT (1)
#define HAS_STD_AUTOPILOT (1)
#define HAS_EXP_AUTOPILOT (0)
#define HAS_ALT_SERVO (1)
#define DEADMANSWITCH_ON (1)

// Thrusters configurations
#define THRUSTER_CONFIG_NONE (0)
#define THRUSTER_CONFIG_2X1 (1)

// Selected Thruster Configuration
#define THRUSTER_CONFIGURATION THRUSTER_CONFIG_2X1

// ---------------------------------------------------------
// After Market Modules
// ---------------------------------------------------------

// Pololu MINIMUV
#define HAS_POLOLU_MINIMUV (0)

// MS5803_XXBA Depth Sensor
#define HAS_MS5803_XXBA (1)
#define MS5803_XXBA_I2C_ADDRESS 0x76

// MPU9150 IMU
#define HAS_MPU9150 (1)
#define HAS_BNO055 (1)
#define MPU9150_EEPROM_START 2
#define HAS_ALT_SERVO (1)
#define ALTS_MIDPOINT 1500
#define ALTS_MINPOINT 1000
#define ALTS_MAXPOINT 2000

// BNO055 IMU
#define HAS_BNO055 (1)
#define HAS_ArduSlave (1)
#define ARDUSLAVE_I2CADDRESS 0x99

-----NConfigManager.h----
#pragma once

// Includes
#include <Arduino.h>
#include “CCommand.h”

// If you have modules that add capabilities that should be advertised to the OpenROV Cockpit
// software add them here. Check the bits on the server side for capabilities and gracefully
// degrade (remove UI elements) if the capabilities do not exist.
#define LIGHTS_CAPABLE 1
#define CALIBRATION_LASERS_CAPABLE 2
#define CAMERA_MOUNT_1_AXIS_CAPABLE 3
#define COMPASS_CAPABLE 4
#define ORIENTATION_CAPABLE 5
#define DEPTH_CAPABLE 6
#define ALT_SERVO_CAPABLE 7
#define ArduSlave_CAPABLE 8

namespace NConfigManager
{
_ // Variables_
_ extern uint32_t m_throttleSmoothingIncrement; // How aggressively the throttle changes_
_ extern uint32_t m_deadZoneMin;_
_ extern uint32_t m_deadZoneMax;_
_ extern uint32_t m_capabilityBitmask;_
_ extern uint32_t m_waterType;_

_ // Methods_
_ extern void Initialize();_
_ extern void HandleMessages( CCommand& commandIn );_
}

-------ModuleDefinitions.h-----
#pragma once
#include “AConfig.h”

// ---------------------------------------
// Conditional module definitions
// -------------------------------
// Once these objects are instantiated, they will register themselves as modules in the module manager.
// They can also be accessed individually as namespace members.
// ---------------------------------------

#if( HAS_OROV_CONTROLLERBOARD_25 )
#include "CControllerBoard.h"
CControllerBoard m_controllerBoard;
#endif

#if(HAS_STD_CAPE)
#include "CCape.h"
CCape m_cape;
#endif

#if(HAS_STD_LIGHTS)
#include "CLights.h"
CLights m_lights;
#endif

#if(HAS_STD_CALIBRATIONLASERS)
#include "CCalibrationLaser.h"
CalibrationLaser m_calibrationLaser;
#endif

#if(THRUSTER_CONFIGURATION != THRUSTER_CONFIG_NONE )
#include "CThrusters.h"
CThrusters m_thrusters;
#endif

#if(HAS_STD_AUTOPILOT)
#include "CAutopilot.h"
CAutopilot m_autopilot;
#endif

#if(HAS_STD_CAMERAMOUNT)
#include "CCameraMount.h"
CCameraMount m_cameraMount;
#endif

#if(HAS_POLOLU_MINIMUV)
#define COMPASS_ENABLED 1
#define GYRO_ENABLED 1
#define ACCELEROMETER_ENABLED 1
#include "CMinIMU9.h"
CMinIMU9 m_miniMUV;
#endif

#if( HAS_MPU9150 )
#define COMPASS_ENABLED 1
#define GYRO_ENABLED 1
#define ACCELEROMETER_ENABLED 1
#include "CMPU9150.h"
CMPU9150 m_mpu9150;
#endif

#if(HAS_ALT_SERVO)
#include "CAltServo.h"
CAltServo altservo1;
#endif

#if(HAS_MS5803_XXBA)
#define DEPTH_ENABLED 1
#include "CMS5803_XXBA.h"
CMS5803_14BA m_depthSensor;
#endif

#if(DEADMANSWITCH_ON)
#include "CDeadManSwitch.h"
CDeadManSwitch m_deadManSwitch;
#endif

#if(HAS_BNO055)
#define COMPASS_ENABLED 1
#define GYRO_ENABLED 1
#define ACCELEROMETER_ENABLED 1
#include "CBNO055.h"
CBNO055 m_boschIMU;
#endif

#if(HAS_ARDUSLAVE)
#include “ArduSlave.h”
_ArduSlave m_sensores; _
#endif


#2

A couple of points, as we were discussing in the dev chat…

  1. You have defined and implemented your class (ArduSlave), but I don’t see where you are actually using the class. To use the functions you’ve defined for your class, you need to instantiate it and then call its method(s). Your “client code” should do that. For example, in some other file…

ArduSlave myArduSlave;
myArduSlave.Initialize();
myArduSlave.Update();

  1. In your Initialize() method/function, you are calling Serial.begin(9600) on the Arduino. This starts the Arduino’s UART (serial) interface at 9600 baud rate. But how are you listening for the Arduino? Where is the other end of your UART interface? A UART has transmit (Tx), receive (Rx), power and GND terminals/pins. This implies that serial communication is a two-way process, and it is. So if you’re asking the Arduino to send text in your ArduSlave::Update() function, then what device is receiving that data from the Arduino?

If your Beaglebone Black is listening to the Arduino because you have the two devices connected, then how are you monitoring the Arduino device (/dev/ttyUSB0 or /dev/ttyACM0 maybe?) in the BBB? But if your Aduino is connected to your computer directly, then are you opening the serial console inside the Arduino IDE to watch for data coming from it? Are you using a different serial terminal, like PuTTY?

In order to help figure out why you’re not seeing data from the Arduino, I think we need a lot more information.

TB


#3

Actually, looking at the code on the Github site, I think your ArduSlave::Initialize() method should be called in the setup() function in the OpenROV2x.ino sketch, as shown here.

Then you could probably just call your ArduSlave::Update() function from inside the loop() function–or call it once inside setup() just to see that the code is working. But you still need to listen to the Arduino’s serial port though. But if you can see that test output from the OpenROV2x.ino setup() function, then your code should also cause a message to print across the same serial port interface.

So getting this to work might be pretty simple for you. As it turns out, I don’t think you’ll need to instantiate an object of your ArduSlave class at all–just call the methods using the fully-qualified name (class::method()) as I’ve mentioned in the first two paragraphs here.

TB


#4

I changed like bellow.
Help me please.

------ArduSlave.h-----
#pragma once

// Includes
#include “CModule.h”
#include “CPin.h”
#include “SysConfig.h”

class ArduSlave : public CModule
{
public:
_ void Initialize();_
_ void Update( CCommand& commandIn );_
};

-------ArduSlave.cpp------

#include “SysConfig.h”
#if(HAS_ArduSlave)
#include “NDataManager.h”
#include “CPin.h”
#include “ArduSlave.h”

#include “NConfigManager.h”

namespace {}

void ArduSlave::Initialize(){
/* Serial.begin(9600); */
_ }_

void ArduSlave::Update( CCommand& commandIn ){

Serial.print(F(“ArduSlave_TEST:”));
Serial.println(’;’);
}

_#endif _

-----OpenROV2x.ino-------
// Includes
#include <EEPROM.h>

#include “NArduinoManager.h”
#include “NVehicleManager.h”
#include “NDataManager.h”
#include “NCommManager.h”
#include “NModuleManager.h”

void setup()
{
_ // Initialize main subsystems_
_ NArduinoManager::Initialize();_
_ NCommManager::Initialize();_
_ NVehicleManager::Initialize();_
_ NModuleManager::Initialize();_
_ NDataManager::Initialize();_

_ ArduSlave::Initialize();_
_ ArduSlave::Update( CCommand& commandIn );_
_ // Set timer 5 divisor to 8 for PWM frequency of 3921.16Hz (D44, D45, D46)_
_ TCCR5B = ( TCCR5B & B11111000 ) | B00000010;_

_ // Boot complete_
_ Serial.println( F( “boot:1;” ) );_
}

void loop()
{
_ // Reset the watchdog timer_
_ wdt_reset();_

_ // Attempt to read a current command off of the command line_
_ NCommManager::GetCurrentCommand();_

_ // Handle any config change requests_
_ NVehicleManager::HandleMessages( NCommManager::m_currentCommand );_

_ // Handle update loops for each module_
_ NModuleManager::HandleModuleUpdates( NCommManager::m_currentCommand );_

_ // Handle update loops that send data back to the beaglebone_
_ NDataManager::HandleOutputLoops();_
_ _
_ _
_ _
}

-------SysModules.h-----
#pragma once
#include “SysConfig.h”

#include “Plugins.h”
#include “PinDefinitions.h”

// ---------------------------------------
// Conditional module definitions
// -------------------------------
// Once these objects are instantiated, they will register themselves as modules in the module manager.
// They can also be accessed individually as namespace members.
// ---------------------------------------

#if( HAS_OROV_CONTROLLERBOARD_25 )
#include "CControllerBoard.h"
CControllerBoard m_controllerBoard;
#endif

#if(HAS_STD_LIGHTS)
#include "CLights.h"
CLights m_lights( PIN_STANDARD_LIGHTS );
#endif

#if(HAS_EXT_LIGHTS )
#include "CExternalLights.h"
CExternalLights m_elights( PIN_PWM_3 );
#endif

#if(HAS_STD_CALIBRATIONLASERS)
#include "CCalibrationLaser.h"
CCalibrationLaser m_calibrationLaser( PIN_LASERS );
#endif

#if(THRUSTER_CONFIGURATION != THRUSTER_CONFIG_NONE )
#include "CThrusters.h"
CThrusters m_thrusters;
#endif

#if(HAS_STD_AUTOPILOT)
#include "CAutopilot.h"
CAutopilot m_autopilot;
#endif

#if(HAS_CAMERASERVO)
#include "CCameraServo.h"
CCameraServo m_cameraServo;
#endif

#if(HAS_ALT_SERVO)
#include "CAltServo.h"
CAltServo altservo1;
#endif

#if(DEADMANSWITCH_ON)
#include "CDeadManSwitch.h"
CDeadManSwitch m_deadManSwitch;
#endif

// IMU1
#if( HAS_MPU9150 )
#include "CMPU9150.h"
CMPU9150 m_mpu9150( mpu9150::EAddress::ADDRESS_B );
#endif

#if(HAS_MS5803_14BA)
#include "CMS5803_14BA.h"
CMS5803_14BA m_ms5803( &I2C0, ms5803_14ba::EAddress::ADDRESS_A );
#endif

// IMU2
#if(HAS_BNO055)
#include "CBNO055.h"
CBNO055 m_bno055( &I2C0, bno055::EAddress::ADDRESS_A );
#endif

#if(HAS_MS5837_30BA)
#include "CMS5837_30BA.h"
CMS5837_30BA m_ms5837( &I2C0, ms5837_30ba::EAddress::ADDRESS_A );
#endif

#if(HAS_ArduSlave)
#include "ArduSlave.h"
ArduSlave m_arduslave;
#endif

-----SysConfig.h-----
#pragma once

#include “PinDefinitions.h”
#include “CompileOptions.h”

// TODO: The MCU ARCH and Board Type should eventually be passed in solely from the build script.

// ---------------------------------------------------------
// MCU Architecture Selection
// ---------------------------------------------------------

#ifndef ARDUINO_ARCH_AVR
_ #error “This sketch is only supported on for ARDUINO_ARCH_AVR!”_
#endif

// Configuration
#define HAS_OROV_CONTROLLERBOARD_25 (1)
#define HAS_STD_LIGHTS (1)
#define HAS_STD_CALIBRATIONLASERS (1)
#define HAS_CAMERASERVO (1)
#define HAS_STD_AUTOPILOT (1)
#define DEADMANSWITCH_ON (0)

// Thrusters configurations (These appear depricated and replaced by the THRUSTER_CONFIGURATION below)
#define THRUSTER_CONFIG_NONE (0)
#define THRUSTER_CONFIG_2X1 (1)
#define THRUSTER_CONFIG_2Xv2 (2)
#define THRUSTER_CONFIG_v2X1Xv2 (3)

// Selected Thruster Configuration
#define THRUSTER_CONFIGURATION THRUSTER_CONFIG_2X1
//#define THRUSTER_CONFIGURATION THRUSTER_CONFIG_2Xv2
//#define THRUSTER_CONFIGURATION THRUSTER_CONFIG_v2X1Xv2

// ---------------------------------------------------------
// After Market Modules
// ---------------------------------------------------------

// External Lights
#define HAS_EXT_LIGHTS (1)

// AltServo
#define HAS_ALT_SERVO (0)

// MS5803_14BA Depth Sensor
#define HAS_MS5803_14BA (1)

// MS5837_30BA Depth Sensor
#define HAS_MS5837_30BA (1)

// MPU9150
#define HAS_MPU9150 (1)

// BNO055 IMU
#define HAS_BNO055 (1)

#define HAS_ArduSlave (1)


#5

I linked the pastebin.
https://pastebin.com/U4ATmq4J


#6

I fixed it up for you. Note the TODO I’ve labeled there, in the OpenROV2x.ino file (line 55). Your code addition(s) will likely break compilation unless/until you verify the proper thing to pass into your Update() function.

https://pastebin.com/4aauw7Cu

TB


#7

Thank you very much for all theses answers.

Best regards

Herve