Ive been trying to send data through the FreeflyAPI, through the mimic to my camera gimbal. They have given some really good exsample code but im still struggling to get even a joystick to work. I was hoping to get some help. As far as I can tell everything should be okay, however Im not naming a type correctly.
I hope its just a formatting issue.
#include <SoftwareSerial.h>
#include <FreeflyAPI.h>
#include <QX_App_Config.h>
#include <QX_Parsing_Functions.h>
#include <QX_Protocol.h>
#include <QX_Protocol_App.h>
#include <simple_buffer.h>
#include "arduino.h"
// goals for this project:
// Joystick Control of the Movi
// Be able to control the rate that the joystick turns the movi
// Be able to pull focus, irus, and zoom
// Be able to use wheels to control the movi
// Be able to stop / start camera
// Be able to kill gimbal
float joystick_x, joystick_y;
SoftwareSerial ArduinoToMoviCommunication(10,14); //RX and TX on digital output pins
void setup() {
// put your setup code here, to run once:
FreeflyAPI.begin();
Serial.begin(115200); // Main serial port for status
Serial1.begin(111111); // Aux serial port for control
ArduinoToMoviCommunication.begin(111111);
FreeflyAPI.control.pan.type = RATE;
FreeflyAPI.control.tilt.type = RATE;
}
void loop() {
// put your main code here, to run repeatedly:
delay(20);
float joystick_x = mapfloat((float)analogRead(A0), 0.0f, 675.0f, -1.0f, 1.0f);
float joystick_y = mapfloat((float)analogRead(A1), 0.0f, 675.0f, -1.0f, 1.0f);
FreeflyAPI.control.pan.type = RATE;
FreeflyAPI.control.tilt.type = RATE;
FreeflyAPI.control.roll.type = RATE;
FreeflyAPI.control.focus.type = DEFER;
FreeflyAPI.control.iris.type = DEFER;
FreeflyAPI.control.zoom.type = DEFER;
FreeflyAPI.control.pan.value = joystick_x;
FreeflyAPI.control.tilt.value = joystick_y;
FreeflyAPI.control.roll.value = 0;
FreeflyAPI.control.focus.value = 0;
FreeflyAPI.control.iris.value = 0;
FreeflyAPI.control.zoom.value = 0;
}
float mapfloat(float x, float in_min, float in_max, float out_min, float out_max)
{
return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
}
FreeflyAPI.send();
/* In a loop send each byte of the message
* that the Freefly API created through
* the Serial port
*/
while(true){
//Create temporary value to hold the message
uint8_t message;
/* Remove single byte from the message API created
* and exit this loop if there is no more messages
* left to be sent this round.
*/
if (BufRemove(1, &message) == 0) break;
//Now physically send one byte of message on Serial port
ArduinoToMoviCommunication.write(message);
}
}