Hello,
I am trying to adjust the swarmsequence code according to what I want to happen. What I need to happen is the two drones doing more than just 3 sequences. Besides the sequences and the "run_sequence" values, what else should I change to, for example, be able to run 8 sequences? I keep getting a "tuple out of range" error and the drones going crazy! Please guide me if possible into what variables I would have to change for that example of 8 movements? [am using lighthouse decks for both]
Sincerely,
Leopardopt
swarmSequence Detail Question
Re: swarmSequence Detail Question
Hi!
Are you still having issues with this? If so what script did you start from and can you copy/paste some code to show your modifications?
Are you still having issues with this? If so what script did you start from and can you copy/paste some code to show your modifications?
-
- Beginner
- Posts: 25
- Joined: Wed Mar 31, 2021 2:40 am
Re: swarmSequence Detail Question
Hello!
Thank you for getting back to me. Here is what I have modified in the swarmsequence which has not helped with the error of "tuple out of range":
z0 = 0.5
z = 1.0
x0 = 0.5
x1 = 0.0
x2 = -0.7
y0 = 0.0
y1 = -0.5
y2 = 0.4
y3 = 1.0
# x y z time
sequence1 = [
(x0, y0, z0, 5.0),
(x0, y1, z0, 5.0),
(x1, y1, z0, 5.0),
(x1, y0, z0, 5.0),
]
sequence2 = [
(x0, y0, z0, 5.0),
(x0, y1, z0, 5.0),
(x1, y1, z0, 5.0),
(x1, y0, z0, 5.0),
]
.....
def take_off(cf, position):
take_off_time = 1.0
sleep_time = 0.1
steps = int(take_off_time / sleep_time)
vz = position[3] / take_off_time
....
def land(cf, position):
landing_time = 1.0
sleep_time = 0.1
steps = int(landing_time / sleep_time)
vz = -position[3] / landing_time
....
def run_sequence(scf, sequence):
try:
cf = scf.cf
take_off(cf, sequence[0])
for position in sequence:
print('Setting position {}'.format(position))
end_time = time.time() + position[4]
while time.time() < end_time:
cf.commander.send_position_setpoint(position[0],
position[1],
position[2],
position[3], 0)
....
This has not fixed the issue. I would ask if there is something else I am missing which does not allow me to go beyond 3 seqeuences. There are 2 drones and I made sure that URIs are uncommented for needed sequences and everything is in order.
Sincerely,
Leopardopt
Thank you for getting back to me. Here is what I have modified in the swarmsequence which has not helped with the error of "tuple out of range":
z0 = 0.5
z = 1.0
x0 = 0.5
x1 = 0.0
x2 = -0.7
y0 = 0.0
y1 = -0.5
y2 = 0.4
y3 = 1.0
# x y z time
sequence1 = [
(x0, y0, z0, 5.0),
(x0, y1, z0, 5.0),
(x1, y1, z0, 5.0),
(x1, y0, z0, 5.0),
]
sequence2 = [
(x0, y0, z0, 5.0),
(x0, y1, z0, 5.0),
(x1, y1, z0, 5.0),
(x1, y0, z0, 5.0),
]
.....
def take_off(cf, position):
take_off_time = 1.0
sleep_time = 0.1
steps = int(take_off_time / sleep_time)
vz = position[3] / take_off_time
....
def land(cf, position):
landing_time = 1.0
sleep_time = 0.1
steps = int(landing_time / sleep_time)
vz = -position[3] / landing_time
....
def run_sequence(scf, sequence):
try:
cf = scf.cf
take_off(cf, sequence[0])
for position in sequence:
print('Setting position {}'.format(position))
end_time = time.time() + position[4]
while time.time() < end_time:
cf.commander.send_position_setpoint(position[0],
position[1],
position[2],
position[3], 0)
....
This has not fixed the issue. I would ask if there is something else I am missing which does not allow me to go beyond 3 seqeuences. There are 2 drones and I made sure that URIs are uncommented for needed sequences and everything is in order.
Sincerely,
Leopardopt
Re: swarmSequence Detail Question
Hi Leopardopt!
So, a sequence is a list of tuples, like your new sequence1:
The tuple in a sequence has 4 elements, they are numbered: 0, 1, 2, 3.
So in the code you have added:
You try to reference "position[4]" which will give you tuple out of range! The last element in the sequence tuple is "position[3]".
Jonas
So, a sequence is a list of tuples, like your new sequence1:
Code: Select all
sequence1 = [
(x0, y0, z0, 5.0),
(x0, y1, z0, 5.0),
(x1, y1, z0, 5.0),
(x1, y0, z0, 5.0),
]
So in the code you have added:
Code: Select all
def run_sequence(scf, sequence):
try:
cf = scf.cf
take_off(cf, sequence[0])
for position in sequence:
print('Setting position {}'.format(position))
end_time = time.time() + position[4]
while time.time() < end_time:
cf.commander.send_position_setpoint(position[0],
position[1],
position[2],
position[3], 0)
Jonas
-
- Beginner
- Posts: 25
- Joined: Wed Mar 31, 2021 2:40 am
Re: swarmSequence Detail Question
Hi!
Thank you for getting back to me. Sorry, this might have been a bad question. I was not thinking about that when working on it. Would you please explain why the default code has 0-2 but references pos[3]?
Sincerely,
Leopardopt
Thank you for getting back to me. Sorry, this might have been a bad question. I was not thinking about that when working on it. Would you please explain why the default code has 0-2 but references pos[3]?
Sincerely,
Leopardopt
Re: swarmSequence Detail Question
Hi Leopardopt!
I am not sure I understand exactly what you are asking, so I am sorry if I answer the wrong thing!
There is an reference to position[3] in the original code, run_sequence:
Here the code is iterating through a sequence, a sequence is one of:
So each position in this iteration is a tuple in a sequence. That tuple has 4 members, which can be accessed by: position[0], position[1], position[2] or position[3] which correspond to x, y, z and time.
Does this answer your question?
I am not sure I understand exactly what you are asking, so I am sorry if I answer the wrong thing!
There is an reference to position[3] in the original code, run_sequence:
Code: Select all
def run_sequence(scf, sequence):
try:
cf = scf.cf
take_off(cf, sequence[0])
for position in sequence:
print('Setting position {}'.format(position))
end_time = time.time() + position[3]
while time.time() < end_time:
cf.commander.send_position_setpoint(position[0],
position[1],
position[2], 0)
time.sleep(0.1)
land(cf, sequence[-1])
except Exception as e:
print(e)
Code: Select all
# x y z time
sequence1 = [
(x0, y0, z0, 3.0),
(x0, y0, z, 30.0),
(x0, y0, z0, 3.0),
]
sequence2 = [
(x0, y1, z0, 3.0),
(x0, y1, z, 30.0),
(x0, y1, z0, 3.0),
]
[...]
Does this answer your question?
-
- Beginner
- Posts: 25
- Joined: Wed Mar 31, 2021 2:40 am
Re: swarmSequence Detail Question [SOLVED]
Got it thank you!