wilvn10 / Linorobot-Melodic

Linorobot for Melodic with implementation of LiDAR, XBOX Kinect V1 and ultrasonic sensors.
2 stars 1 forks source link

Battery Status #2

Closed Symeth closed 3 years ago

Symeth commented 3 years ago

hallo

is there a method to get battery status ? so when the battery is low then go to docking station to do charging

thanks you

wilvn10 commented 3 years ago

Hi,

Teensy 4.0 has a maximum input voltage of 3.3 V, while the battery that is being used is 12 V. My solution is to put 2 resistors in series so that the voltage drop of one of the resistors is less than 3.3 V (Using voltage divider method).

The following resistor will be connected to the Analog pin and ground of the Teensy 4.0 (the microcontroller act as the 'multimeter'). In the void loop, do an analogread of the corresponding pin. It will return the number of bytes representing the volt received by the pin. Since Teensy 4.0 ADC has 1023 bits, it represents 3.3 V (1023 bits = 3.3 V) leading us to:

1023 bits= 3.3V 1 bit = 0.003225 V = 3.225 mV

To read the voltage received by the Teensy 4.0, make a variable of the bytes received as a float. This variable will be multiplied by 3.225. The result is the voltage received by the Teensy in milli Volt.

So you can read the battery status continuously in the void loop. When it reaches a certain amount of threshold, do a 'self-charging' function.

Hope this helps.

Symeth commented 3 years ago

hi

thank for ur prompt reply, i will try as per your described

i found interesting product for battery level check

https://wiki.dfrobot.com/Battery_Capacity_Indicator_SKU__FIT0466

level of battery can get using this module but.... how to publish data from robot computer to development computer ?

thanks you

wilvn10 commented 3 years ago

Hi,

frankly, I have not used that module. But to answer your question generally, you should make publisher (say its called a /battery_status) containing a sensor_msgs object. You can store the value of the battery voltage into this message. You can declare this publisher in the firmware.ino

You can check this documentation for the sensor_msgs for battery: http://docs.ros.org/melodic/api/sensor_msgs/html/msg/BatteryState.html

In the development computer, you can subscribe to the topic of /battery_status to retrieve the battery current voltage.

Hope this helps.

Symeth commented 3 years ago

hi

thanks for your guidance, oke i will try to make publisher /battery_status if it need the library i just need to put the library file inside "linorobot/teensy/firmware/lib/" right ?

it very help thank you very much