本文整理汇总了Python中cfclient.utils.input.JoystickReader.set_thrust_slew_limiting方法的典型用法代码示例。如果您正苦于以下问题:Python JoystickReader.set_thrust_slew_limiting方法的具体用法?Python JoystickReader.set_thrust_slew_limiting怎么用?Python JoystickReader.set_thrust_slew_limiting使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cfclient.utils.input.JoystickReader
的用法示例。
在下文中一共展示了JoystickReader.set_thrust_slew_limiting方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: HeadlessClient
# 需要导入模块: from cfclient.utils.input import JoystickReader [as 别名]
# 或者: from cfclient.utils.input.JoystickReader import set_thrust_slew_limiting [as 别名]
class HeadlessClient():
"""Crazyflie headless client"""
def __init__(self):
"""Initialize the headless client and libraries"""
cflib.crtp.init_drivers()
self._jr = JoystickReader(do_device_discovery=False)
self._cf = Crazyflie(ro_cache=sys.path[0]+"/cflib/cache",
rw_cache=sys.path[1]+"/cache")
signal.signal(signal.SIGINT, signal.SIG_DFL)
def setup_controller(self, input_config, input_device=0):
"""Set up the device reader"""
# Set values for input from config (advanced)
self._jr.set_thrust_limits(
self._p2t(Config().get("min_thrust")),
self._p2t(Config().get("max_thrust")))
self._jr.set_rp_limit(Config().get("max_rp"))
self._jr.set_yaw_limit(Config().get("max_yaw"))
self._jr.set_thrust_slew_limiting(
self._p2t(Config().get("slew_rate")),
self._p2t(Config().get("slew_limit")))
# Set up the joystick reader
self._jr.device_error.add_callback(self._input_dev_error)
devs = self._jr.getAvailableDevices()
print "Will use [%s] for input" % devs[input_device]["name"]
self._jr.start_input(devs[input_device]["name"],
input_config)
def list_controllers(self):
"""List the available controllers"""
for dev in self._jr.getAvailableDevices():
print "Controller #{}: {}".format(dev["id"], dev["name"])
def connect_crazyflie(self, link_uri):
"""Connect to a Crazyflie on the given link uri"""
self._cf.connectionFailed.add_callback(self._connection_failed)
self._cf.open_link(link_uri)
self._jr.input_updated.add_callback(self._cf.commander.send_setpoint)
def _connection_failed(self, link, message):
"""Callback for a failed Crazyflie connection"""
print "Connection failed on {}: {}".format(link, message)
self._jr.stop_input()
sys.exit(-1)
def _input_dev_error(self, message):
"""Callback for an input device error"""
print "Error when reading device: {}".format(message)
sys.exit(-1)
def _p2t(self, percentage):
"""Convert a percentage to raw thrust"""
return int(65000 * (percentage / 100.0))