def set_color(self, red, green, blue, default=False, response=False): """ Sets the color of the sphero given rgb components between 0 and 255, if `default` is true, sphero will default to that color when first connected The returned Response object's data field will be empty, but if `response` is set to `True`, it's success field will indicate if the command was successful. ### Usage: #!python from time import sleep from spheropy.Sphero import Sphero with Sphero("Sphero-YWY", "68:86:E7:07:59:71") as s: s.set_color(255, 0, 0) sleep(1) s.set_color(0, 255, 0) sleep(1) s.set_color(0, 0, 255) """ red = int_to_bytes(red, 1) blue = int_to_bytes(blue, 1) green = int_to_bytes(green, 1) flag = [0x01] if default else [0x00] return self._stable_send(_SPHERO, _SPHERO_COMMANDS['SET COLOR'], red + green + blue + flag, response)
def set_data_stream(self, stream_settings, frequency, packet_count=0, response=False): """ Sets data stream options, where `stream_settings` is a DataStreamManager object, and `frequency` how often you want to recieve data and `packet_count` indicates the number of packets you want to recieve, set to zero for unlimited streaming. The returned Response object's data field will be empty, but if `response` is set to `True`, it's success field will indicate if the command was successful. ### Usage: #!python from spheropy.Sphero import Sphero from spheropy.DataStream import DataStreamManager dsm = DataStreamManager() dsm.acc = True with Sphero("Sphero-YWY", "68:86:E7:07:59:71") as s: s.set_data_stream(dsm, 10 packet_count=2) """ self._data_stream = stream_settings.copy() divisor = int_to_bytes(int(400.0 / frequency), 2) samples = int_to_bytes(self._data_stream.number_frames, 2) mask1 = int_to_bytes(self._data_stream._mask1, 4) mask2 = int_to_bytes(self._data_stream._mask2, 4) data = divisor + samples + mask1 + [packet_count] + mask2 return self._stable_send(_SPHERO, _SPHERO_COMMANDS['SET DATA STRM'], data, response)
def roll(self, speed, heading, fast_rotate=False, response=False): """ Commands the sphero to move. `speed` ranges from 0..255, while `heading` is in degrees from 0..359, 0 is strait, 90 is to the right, 180 is back and 270 is to the left. When `fast_rotate` is set to True sphero will rotate as quickly as possible to given heading regardless of speed. The returned Response object's data field will be empty, but if `response` is set to `True`, it's success field will indicate if the command was successful. """ gobit = [0x02] if fast_rotate else [0x01] speed = int_to_bytes(speed, 1) heading = int_to_bytes(heading, 2) return self._stable_send(_SPHERO, _SPHERO_COMMANDS['ROLL'], speed + heading + gobit, response)
def set_voltage_trip_points(self, low, critical, response=False): """ DOES NOT WORK not implemented This assigns the voltage trip points for Low and Critical battery voltages. The values are specified in 100ths of a volt and the limitations on adjusting these away from their defaults are: Vlow must be in the range 675 to 725 ( += 25) Vcrit must be in the range 625 to 675 ( += 25) There must be 0.25V of separation between the two values """ assert False low = int_to_bytes(low, 2) crit = int_to_bytes(critical, 2) return self._stable_send(_CORE, _CORE_COMMANDS['SET VOLTAGE TRIP'], low + crit, response)
def set_back_light(self, brightness, response=False): """ Controls the brightness of the back LED, non persistent The returned Response object's data field will be empty, but if `response` is set to `True`, it's success field will indicate if the command was successful. """ brightness = int_to_bytes(brightness, 1) return self._stable_send(_SPHERO, _SPHERO_COMMANDS['SET BACKLIGHT'], brightness, response)
def assign_time(self, time_value, response=False): """ Sets the internal timer to `time_value`. This is the time that shows up in a collision message. The returned Response object's data field will be empty, but if `response` is set to `True`, it's success field will indicate if the command was successful. """ return self._stable_send(_CORE, _CORE_COMMANDS['ASSIGN TIME'], int_to_bytes(time_value, 4), response)
def set_motion_timeout(self, timeout, response=False): """ This sets the ultimate timeout for the last motion command to keep Sphero from rolling away timeout is in miliseconds and defaults to 2000 for this to be in effect motion timeout must be in must be set in permanent options The returned Response object's data field will be empty, but if `response` is set to `True`, it's success field will indicate if the command was successful. """ if self._outside_range(timeout, 0, 0xFFFF): raise SpheroException("Timeout outside of valid range") timeout = int_to_bytes(timeout, 2) return self._stable_send(_SPHERO, _SPHERO_COMMANDS['MOTION TIMEOUT'], timeout, response)
def set_heading(self, heading, response=False): """ Sets the spheros heading in degrees, heading must range between 0 to 359. This should move the back tail light. The returned Response object's data field will be empty, but if `response` is set to `True`, it's success field will indicate if the command was successful. """ if heading < 0 or heading > 359: return Response(False, "heading must be between 0 and 359") heading_bytes = int_to_bytes(heading, 2) reply = self._stable_send(_SPHERO, _SPHERO_COMMANDS['SET HEADING'], heading_bytes, response) return reply
def set_rotation_rate(self, rate, response=False): """ DOESN't WORK This sets the roation rate sphero will use to meet new heading commands Lower value offers better control, with a larger turning radius. The rate should be in degrees / sec, anythin above 199 the maxium value is used(400 degrees / sec) """ # TODO returns unknown command if rate < 0: return Response(False, "USE POSITIVE RATE ONLY") if rate > 199: rate = 200 else: rate = int(rate / 0.784) to_bytes = int_to_bytes(rate, 1) return self._send(_SPHERO, _SPHERO_COMMANDS['SET ROTATION RATE'], to_bytes, response)
def set_permanent_options(self, options, response=False): """ Set Options, for option information see PermanentOptionFlag docs. Options persist across power cycles. `options` is a Permanent Option Object The returned Response object's data field will be empty, but if `response` is set to `True`, it's success field will indicate if the command was successful. ### Usage: #!python from spheropy.Sphero import Sphero from spheropy.Options import PermanentOptions po = PermanentOptions() po.set_light_wakeup_sensitivity= True with Sphero("Sphero-YWY", "68:86:E7:07:59:71") as s: s.set_permanent_options(po) """ options = int_to_bytes(options.bitflags, 8) return self._stable_send(_SPHERO, _SPHERO_COMMANDS['SET PERM OPTIONS'], options, response)