Controlling Multiwii with nrf24l01+
Controlling Multiwii with nrf24l01+
I'm building a quadcopter as a project for school, and my plan was to use a ps2 controller to control the quad. To do this, I have a separate arduino with a nrf24l01+ radio module. It reads the PS2 controller and transmits the analog values and button states.
I want to get the multiwii firmware to read the controller data from an nrf24l01+ receiver. I'll have to set up some code to read the radio module, but once I've done that, I need to translate and store the controller values somewhere.
Would I just have to write to the global variables in the RX file? Are they what the multiwii uses as it's inputs?
I want to get the multiwii firmware to read the controller data from an nrf24l01+ receiver. I'll have to set up some code to read the radio module, but once I've done that, I need to translate and store the controller values somewhere.
Would I just have to write to the global variables in the RX file? Are they what the multiwii uses as it's inputs?
Re: Controlling Multiwii with nrf24l01+
if you have real value : polupulat rcData[chan]
if you have transiant value : populate rcValue[chan] and then do populate rcData[chan] from ComputeRC()
this is a spi devices .. but if your plan is to translate to serial rc input .. you can extrapolate from SBUS RX Data
if you want to use spi .. extrapolate from
if you have transiant value : populate rcValue[chan] and then do populate rcData[chan] from ComputeRC()
this is a spi devices .. but if your plan is to translate to serial rc input .. you can extrapolate from SBUS RX Data
/**************************************************************************************/
/*************** DUMMY Serial Data ********************/
/**************************************************************************************/
void readDummySerial(){
while(SerialAvailable(1)){
rcValue[n++ ] = SerialRead(1);
if you want to use spi .. extrapolate from
//############ MAIN LOOP ##############
void Read_OpenLRS_RC() {
rcData[ROLL] = Servo_Buffer[0];
rcData[PITCH] = Servo_Buffer[1];
rcData[THROTTLE] = Servo_Buffer[2];
rcData[YAW] = Servo_Buffer[3];
rcData[AUX1] = Servo_Buffer[4];
rcData[AUX2] = Servo_Buffer[5];
rcData[AUX3] = Servo_Buffer[6];
rcData[AUX4] = Servo_Buffer[7];
Re: Controlling Multiwii with nrf24l01+
I'll be getting real values from the radio module, so I'll put those values in rcData.
Thanks a bunch, I was reading through the RX file but I never caught that there was something using SPI in there. I'll read through that code and see how I can read my SPI module instead. After that, I need to find where I can put the code to initialize the connection with the radio.
treym wrote:this is a spi devices .. but if your plan is to translate to serial rc input .. you can extrapolate from SBUS RX Data
Thanks a bunch, I was reading through the RX file but I never caught that there was something using SPI in there. I'll read through that code and see how I can read my SPI module instead. After that, I need to find where I can put the code to initialize the connection with the radio.
-
- Posts: 1
- Joined: Thu Dec 26, 2013 8:04 pm
Re: Controlling Multiwii with nrf24l01+
Hi,
i'm doing this as well, trying to put nrf24l01 working with multiwii. I have tried both nrf libraries for arduino, and i can put 2nrf comunicating, but when i put the code into the multiwii code, they dont work, i get a lot of errors from the nrf libraries themselves.
Has anyone done this make an RC from nrf+arduino?
I'm trying to control a multicopter from my xbox controller(via serial from processing + procontrol library), and i already succeded but when i put the code in the multiwii all crashes...
i'm doing this as well, trying to put nrf24l01 working with multiwii. I have tried both nrf libraries for arduino, and i can put 2nrf comunicating, but when i put the code into the multiwii code, they dont work, i get a lot of errors from the nrf libraries themselves.
Has anyone done this make an RC from nrf+arduino?
I'm trying to control a multicopter from my xbox controller(via serial from processing + procontrol library), and i already succeded but when i put the code in the multiwii all crashes...
Re: Controlling Multiwii with nrf24l01+
richardware wrote:Hi,
i'm doing this as well, trying to put nrf24l01 working with multiwii. I have tried both nrf libraries for arduino, and i can put 2nrf comunicating, but when i put the code into the multiwii code, they dont work, i get a lot of errors from the nrf libraries themselves.
Has anyone done this make an RC from nrf+arduino?
I'm trying to control a multicopter from my xbox controller(via serial from processing + procontrol library), and i already succeded but when i put the code in the multiwii all crashes...
I got it working for the quadcopter. Unfortunately, I'm in the middle of finals week and can't work on this right now. Once I'm done I'll post how I got it working.
Re: Controlling Multiwii with nrf24l01+
Sorry I'm so late, but here is how we got the NRF module working with multiwii 2.1.
We used the RF24 arduino library made by J. Coliz. The files for that are included in the multiwii source folder. This libary takes care of most of the hard work for communicating using these modules. All you need to do is include it, and adjust a few things to be able to communicate with the modules. You can learn more about how to do that by looking up RF24 examples.
We added a few features but you don't need these to get RF24 working. I had to heavily modify the multiwii source code to work with these radio modules. I did a fairly rough job of this. I ran into a few errors causing the code not to compile, so I often had to comment out/disable multiwii features that were interfering. I also had to place bits of my RF code in a manner that isn't compatible with the other RF modes, aka once you modify the source code it will only work with NRF24 modules. I also had to change the multiwii code for arming the motors.
In our main multiwii file we declare some variables and the radio class which will be used to communicate with the controller side.
There's also a function we call in the setup() block to initialize the radio:
In RX.ino there's a function called computeRC(). This function is called regularly, so we put our radio code in here to receive data from the controller.
In the code below, we first check if the radio has any data sent from the controller. It then reads the controller into an array we made called data[]. After receiving data, we transfer the controller values into the global rcValue array. Values you put in the rcValue array are between 1000 and 2000, representing the position of the analog stick.
For example, the line " rcValue[ROLLPIN] = data[Lx];" Transfers the horizontal position of the Left analog stick into the rcValue array, to control the roll of the quadcopter.
We included other code in there to handle button presses and control various functions of multiwii such as the arming. We also added failsafes like a timer that checks how long it's been since we last received data from the controller. This will set the quadcopter controls to a safer default value if we lose connection with the transmitter for too long.
That should be enough information for you to get started with the NRF24 modules. I will post a download for my modified multiwii source including the radio code, but be warned that you will probably not be able to run it. It should be used as a reference so you can set up the code for your own aircraft.
We used the RF24 arduino library made by J. Coliz. The files for that are included in the multiwii source folder. This libary takes care of most of the hard work for communicating using these modules. All you need to do is include it, and adjust a few things to be able to communicate with the modules. You can learn more about how to do that by looking up RF24 examples.
We added a few features but you don't need these to get RF24 working. I had to heavily modify the multiwii source code to work with these radio modules. I did a fairly rough job of this. I ran into a few errors causing the code not to compile, so I often had to comment out/disable multiwii features that were interfering. I also had to place bits of my RF code in a manner that isn't compatible with the other RF modes, aka once you modify the source code it will only work with NRF24 modules. I also had to change the multiwii code for arming the motors.
In our main multiwii file we declare some variables and the radio class which will be used to communicate with the controller side.
Code: Select all
enum JS {L3,R3,Rx,Ry,Lx,Ly,SEL,SRT};
RF24 radio(7,8);
// Radio pipe addresses for the 2 nodes to communicate.
const uint64_t pipe = 0xE8E8F0F0E1LL;
// Buffer for received data
int data[9];
// Button past states
int L3_old;
int SEL_old;
int START_old;
unsigned long to;
There's also a function we call in the setup() block to initialize the radio:
Code: Select all
void configureReceiver() {
radio.begin();
radio.openReadingPipe(1,pipe);
radio.startListening();
}
In RX.ino there's a function called computeRC(). This function is called regularly, so we put our radio code in here to receive data from the controller.
In the code below, we first check if the radio has any data sent from the controller. It then reads the controller into an array we made called data[]. After receiving data, we transfer the controller values into the global rcValue array. Values you put in the rcValue array are between 1000 and 2000, representing the position of the analog stick.
For example, the line " rcValue[ROLLPIN] = data[Lx];" Transfers the horizontal position of the Left analog stick into the rcValue array, to control the roll of the quadcopter.
Code: Select all
if (radio.available()){
bool done = false;
while(!done){
done = radio.read( data, sizeof(data));
}
rcValue[ROLLPIN] = data[Lx];
rcValue[PITCHPIN] = data[Ly];
rcValue[YAW] = data[Rx];
rcValue[THROTTLE] = data[Ry];
// If L3 is pressed, arm motor
if (L3_old && !data[L3])
f.ARMED = 1;
//disarm motor if Select is pressed
if (SEL_old && !data[SEL])
f.ARMED = 0;
//enable stable mode when Start is pressed
if (START_old && !data[SRT])
f.ACC_MODE = 1;
L3_old = data[L3];
START_old = data[SRT];
SEL_old = data[SEL];
//clear timer
to = millis();
}
else {
tn = millis() - to;
//disarm motor if timer > 20sec
if(tn >= 20000){
f.ARMED = 0;
}
//fixed speed if timer > 3sec
else if(tn >= 3000){
rcValue[ROLLPIN] = 1500;
rcValue[PITCHPIN] = 1500;
rcValue[YAW] = 1500;
rcValue[THROTTLE] = 1350;
}
}
We included other code in there to handle button presses and control various functions of multiwii such as the arming. We also added failsafes like a timer that checks how long it's been since we last received data from the controller. This will set the quadcopter controls to a safer default value if we lose connection with the transmitter for too long.
That should be enough information for you to get started with the NRF24 modules. I will post a download for my modified multiwii source including the radio code, but be warned that you will probably not be able to run it. It should be used as a reference so you can set up the code for your own aircraft.
Re: Controlling Multiwii with nrf24l01+
so , any news ? how did you handle the channel sync ? what about the replay and the implied delay when you switch from rx to tx ( is it full duplex ) ?
Re: Controlling Multiwii with nrf24l01+
What do you mean by channel sync? replay?
As for switching delay, there is none. The NRF24 can communicate bidirectionally but not in full duplex. What happens is when you transmit a packet, the receiver will transmit you a reply to acknowledge that it received something. In this acknowledge packet you can include your own data to send back. I never used this to send data, but my controller side verifies that the packet has been successfully received and uses some LEDs to indicate when there are communication errors.
As for switching delay, there is none. The NRF24 can communicate bidirectionally but not in full duplex. What happens is when you transmit a packet, the receiver will transmit you a reply to acknowledge that it received something. In this acknowledge packet you can include your own data to send back. I never used this to send data, but my controller side verifies that the packet has been successfully received and uses some LEDs to indicate when there are communication errors.
Re: Controlling Multiwii with nrf24l01+
Hello,
It's a very interesting project, I would like to do the same thing to. Could you please share me code?
It's a very interesting project, I would like to do the same thing to. Could you please share me code?
Re: Controlling Multiwii with nrf24l01+
I'd be very interested in the modified code as well, I've just started a similar project where Arduinos are used as both flight controller and transmitter using the nrf24l01+.
Re: Controlling Multiwii with nrf24l01+
Hey 600baud, that's exactly what I want to do, but when I look at the code of multiwii, i got demotivated, and I came here ask for help... I'm new to multiwii though.
Any help would be appreciated.
Thanks
Any help would be appreciated.
Thanks
Re: Controlling Multiwii with nrf24l01+
Hey guys, sorry I haven't been on here in a while. You can download my full code here: https://pegasusprototyping.ca/assets/do ... e_code.zip
I can't guarantee that the code is correct or will work for you, but you may be able to learn from it. If you have questions about the code it would be better to email me, because I check my email all the time. You can reach me at addy771 AT gmail DOT com
I can't guarantee that the code is correct or will work for you, but you may be able to learn from it. If you have questions about the code it would be better to email me, because I check my email all the time. You can reach me at addy771 AT gmail DOT com