def _status_to_battery_(status): """ Converts a ds4_driver/Status to sensor_msgs/BatteryState Reference: https://www.psdevwiki.com/ps4/DualShock_4#Specifications :param status: :type status: Status :return: """ msg = BatteryState() msg.header = status.header msg.percentage = status.battery_percentage msg.voltage = Controller.MAX_VOLTAGE * msg.percentage msg.current = float('NaN') msg.charge = float('NaN') msg.capacity = float('NaN') msg.design_capacity = 1.0 if not status.plug_usb: msg.power_supply_status = BatteryState.POWER_SUPPLY_STATUS_NOT_CHARGING elif not status.battery_full_charging: msg.power_supply_status = BatteryState.POWER_SUPPLY_STATUS_CHARGING elif status.battery_full_charging: msg.power_supply_status = BatteryState.POWER_SUPPLY_STATUS_FULL msg.power_supply_technology = BatteryState.POWER_SUPPLY_TECHNOLOGY_LION return msg
GAIN = 1 voltage = 0.0 while not rospy.is_shutdown(): """ message header """ # for header time stamps current_time = rospy.Time.now() h = rospy.Header() h.stamp = current_time h.frame_id = frame_id # "battery" h.seq = seq # increase sequence seq = seq + 1 # add header to IMU message battery_msg.header = h # run some parts only on the real robot if hostname == 'minibot': # read AD converter (battery voltage) # use channel 0 on IC value = adc.read_adc(0, gain=GAIN) # 13.44 Volt battery voltage resulted in 2,94 Volt on the ADC channel with my circuit (voltage divider w/ two resistors (39k + 11k)). # This resulted in a ADC 'value' of 1465. # The conversion factor for the battery voltage is then: 1465 / 13.44 = 109.00297619047619 # voltage = (value / 109.00297619047619) else: # simulated value! voltage = demoVoltage