Help with making a multi copter avoid objects

Post Reply
WolfWing01
Posts: 7
Joined: Mon Jul 13, 2015 11:34 pm

Help with making a multi copter avoid objects

Post by WolfWing01 »

I'm trying to get my multi copter move away from objects when it is in flight. On my copter I have 4 sonic senors, one pointing down ( for alt hold), one facing forward, left and right. All are ranging and showing values correctly.
I having trouble finding a way for the MultiWii to react to values from the senors facing out. I have been looking into PID setting and controls but I don't want to start messing with things I don't understand.

Any suggestions will be appreciated.

FightingFlight
Posts: 16
Joined: Sun Jun 07, 2015 9:04 am

Re: Help with making a multi copter avoid objects

Post by FightingFlight »

There are probably lots of ways to do this, I haven't really looked into added those sorts of sensors myself but I have controlled Multiwii by directly manipulating the rcValue[x] in RX.cpp -
#define PITCH 0
#define ROLL 1
#define YAW 2
#define THROTTLE 3

So you could have your own algorithm running to calculate when it needs to step in and how long for, then directly change the Pitch/Roll/Yaw/Throttle to suit and then hand control back to the user.

WolfWing01
Posts: 7
Joined: Mon Jul 13, 2015 11:34 pm

Re: Help with making a multi copter avoid objects

Post by WolfWing01 »

Thank you for the suggestion.

The rcValue[X] is the array used to store the values that are coming from the RC receiver correct? How would I take and give back control to the user?

FightingFlight
Posts: 16
Joined: Sun Jun 07, 2015 9:04 am

Re: Help with making a multi copter avoid objects

Post by FightingFlight »

The rcValue[X] is the array used to store the values that are coming from the RC receiver correct?

Yes that's correct

How would I take and give back control to the user?

I think the best place to change the rcValue would be in the readRawRC function in RX.cpp. Say if you got to close to the ground, it would branch out of the usual code and set rcValue[THROTTLE] = 1400 (or possibly very high throttle and then every 200ms slowly decreasing) until the sensor detected it was x metres from the ground.

You should also think about setting a switch on your TX to turn your code on and off easily and/or a failsafe, otherwise if there were any bugs there may not be a way to switch it off.

WolfWing01
Posts: 7
Joined: Mon Jul 13, 2015 11:34 pm

Re: Help with making a multi copter avoid objects

Post by WolfWing01 »

Is it that simple? The readRawRC function seems to be where the rcvalue gets updated. So if I implement a few lines like the code below in side the readRawRC function, It should work, or am I missing somthing? I will be messing idea with this for the next few days.

#if SONAR // set to activate when sonar mode is on
if (Sonar_Distance_front <= 50){ // Distance of 50cm
if (Sonar_Distance_front <= 20 && Sonar_Distance_front >= 1){
rcValue[PITCH] == 1150; // Move the quad backwards quickly
}
else if (Sonar_Distance_front <= 40 && Sonar_Distance_front >= 21){
rcValue[PITCH] == 1350; // Move the quad backwards
}
else if (Sonar_Distance_front <= 50 && Sonar_Distance_front >= 41){
rcValue[PITCH] == 1450; // Move the quad backwards slowly
}
}
#endif

FengShuiDrone
Posts: 234
Joined: Wed Dec 24, 2014 1:20 am
Location: ......

Re: Help with making a multi copter avoid objects

Post by FengShuiDrone »

.
Last edited by FengShuiDrone on Fri Aug 07, 2015 1:20 am, edited 1 time in total.

WolfWing01
Posts: 7
Joined: Mon Jul 13, 2015 11:34 pm

Re: Help with making a multi copter avoid objects

Post by WolfWing01 »

I just tested a simple test code, and it works like a charm. Thank you for help FightingFlight!

As soon as I perfect my algorithm and testing, I will post a video and describe how I did it.

WolfWing01
Posts: 7
Joined: Mon Jul 13, 2015 11:34 pm

Re: Help with making a multi copter avoid objects

Post by WolfWing01 »

I have been working with the rcValue[X] array. I can't find how to change the ROLL value.

rcValue[0] = THROTTLE
rcValue[1] = N/A ---------- This should be where I can get and change ROLL but nothing seems to happen
rcValue[2] = PITCH
rcValue[3] = YAW

FightingFlight
Posts: 16
Joined: Sun Jun 07, 2015 9:04 am

Re: Help with making a multi copter avoid objects

Post by FightingFlight »

The 0,1,2,3 elements (can go up to 8 elements) in the array also depends on your radio system, so I would take the props off, turn the TX off and try setting the other elements in the array and use the Multiwii GUI to see which element changes which channel.

WolfWing01
Posts: 7
Joined: Mon Jul 13, 2015 11:34 pm

Re: Help with making a multi copter avoid objects

Post by WolfWing01 »

Yes I have been testing the multiwii that way. I can change all elements from the Throttle to the Aux4, but I can not change the Roll value in any way. I have been reading other posts about there being a problem with the array mapping for rcValue and rcChannel, but I don't think that problem is affecting this. It just seem odd that I can change all but one value on the rcValue array.

FightingFlight
Posts: 16
Joined: Sun Jun 07, 2015 9:04 am

Re: Help with making a multi copter avoid objects

Post by FightingFlight »

That's weird, I can change it without issues - for me in this case it's rcValue[4].
Which board are you using? Any special changes to config.h? I'm testing this using an Arduino Pro MIni.

Image

WolfWing01
Posts: 7
Joined: Mon Jul 13, 2015 11:34 pm

Re: Help with making a multi copter avoid objects

Post by WolfWing01 »

I'm using the Multiwii Pro 2.0 for my flight controller. No I do not have any special changes to this config.h file. I tested it just as your pic and all values change but the Roll value.

I have found a different way to change the element values, by manipulating the data value with in the readRawRC function, as such.

Multiwii test pic
Multiwii test pic

Post Reply