Recently I was able to import a CSV file which contains a linear velocity and angular velocity. ( [Linear Velocity, Angular Velocity] ) (from a value of -1 to 1)
The CSV file supposedly moves the crazyflie in a circle. While I do get a circular motion, it's not a smooth movement but rather stops after each line being read. I suspect it has something to do how I am certain commands. I've attached the code I've used for this in this thread.
Code: Select all
# -*- coding: utf-8 -*- # # || ____ _ __ # +------+ / __ )(_) /_______________ _____ ___ # | 0xBC | / __ / / __/ ___/ ___/ __ `/_ / / _ \ # +------+ / /_/ / / /_/ /__/ / / /_/ / / /_/ __/ # || || /_____/_/\__/\___/_/ \__,_/ /___/\___/ # # Copyright (C) 2017 Bitcraze AB # # Crazyflie Nano Quadcopter Client # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License # as published by the Free Software Foundation; either version 2 # of the License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, # MA 02110-1301, USA. """ This script shows the basic use of the MotionCommander class. Simple example that connects to the crazyflie at `URI` and runs a sequence. This script requires some kind of location system, it has been tested with (and designed for) the flow deck. The MotionCommander uses velocity setpoints. Change the URI variable to your Crazyflie configuration. """ import logging import time import cflib.crtp from cflib.crazyflie import Crazyflie from cflib.crazyflie.syncCrazyflie import SyncCrazyflie from cflib.positioning.motion_commander import MotionCommander from cflib.crazyflie.log import LogConfig from cflib.crazyflie.syncLogger import SyncLogger import csv URI = 'radio://0/33/1M' # Only output errors from the logging framework logging.basicConfig(level=logging.ERROR) log_config = LogConfig(name='test log', period_in_ms=100) log_config.add_variable('stateEstimate.x', 'float') log_config.add_variable('stateEstimate.y', 'float') log_config.add_variable('stateEstimate.z', 'float') if __name__ == '__main__': # Initialize the low-level drivers (don't list the debug drivers) cflib.crtp.init_drivers(enable_debug_driver=True) with SyncCrazyflie(URI, cf=Crazyflie(rw_cache='./cache')) as scf: # We take off when the commander is created with MotionCommander(scf, default_height=0.5) as mc: time.sleep(3) """ # Forward and Backward Test with open('D:\DSO-AISwarm\InitialSampleData\ActionTest(1AgtforSUTD_test)(MovForward) - Copy.txt') as csv_file: csv_reader = csv.reader(csv_file, delimiter=' ') line_count = 0 for row in csv_reader: velocity = float(row) * 0.1 if velocity > 0: mc.forward(0.2, velocity=velocity) print('forward') if velocity < 0: velocity = -1.0 * velocity mc.back(0.2, velocity=velocity) print('backward') line_count += 1 print(row+' ' + row) mc.stop # Rotate Test with open('D:\DSO-AISwarm\InitialSampleData\ActionTest(1AgtforSUTD_test)(RotatClockw) - Copy.txt') as csv_file: print('brought in rotate') csv_reader = csv.reader(csv_file, delimiter=' ') line_count = 0 for row in csv_reader: angle = float(row) * 45 if angle > 0: mc.turn_right(angle) if angle < 0: angle = -1.0 * angle mc.turn_left(angle) print(row+' ' + row) #mc.turn_right(angle,angle) line_count += 1 mc.stop() """ with open('D:\DSO-AISwarm\InitialSampleData\Record(1AgtforSUTD_test)_2ndHalf.txt') as csv_file: # print('brought in data') csv_reader = csv.reader(csv_file, delimiter=' ') line_count = 0 for row in csv_reader: velocity_v = float(row) * 0.05 rotation = float(row)*5 if velocity_v > 0: mc.forward(distance_m= velocity_v,velocity= velocity_v) if rotation > 0: mc.turn_right(rotation) line_count += 1 elif rotation < 0: rotation = -1.0 * rotation mc.turn_left(5,rotation) line_count += 1 elif velocity_v < 0: velocity_v = -1.0 * velocity_v mc.back(distance_m= velocity_v,velocity= velocity_v) if rotation > 0: mc.turn_right(rotation) line_count += 1 elif rotation < 0: rotation = -1.0 * rotation mc.turn_left(5,rotation) line_count += 1 print(line_count) mc.stop() """ # There is a set of functions that move a specific distance # We can move in all directions mc.forward(0.3) mc.back(0.3) time.sleep(1) mc.up(0.3) mc.down(0.3) time.sleep(1) # We can also set the velocity mc.right(0.3, velocity=0.5) time.sleep(1) mc.left(0.3, velocity=0.4) time.sleep(1) # We can do circles or parts of circles mc.circle_right(0.5, velocity=0.5, angle_degrees=180) # Or turn mc.turn_left(90) time.sleep(1) # We can move along a line in 3D space mc.move_distance(-1, 0.0, 0.5, velocity=0.6) time.sleep(1) # There is also a set of functions that start a motion. The # Crazyflie will keep on going until it gets a new command. mc.start_left(velocity=0.5) # The motion is started and we can do other stuff, printing for # instance for _ in range(5): print('Doing other work') time.sleep(0.2) print('Connected') """ # And we can stop #mc.stop() # We land when the MotionCommander goes out of scope