Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Battery: Add Tattu CAN driver #20824

Closed
wants to merge 3 commits into from
Closed

Conversation

magicrub
Copy link
Contributor

This adds the proprietary CAN driver for TATTU batteries. Tested by @CraigElder and @alexscheck and @jmachuca77.

@rmackay9
Copy link
Contributor

rmackay9 commented May 23, 2022

I guess this will work with any of the "Smart" Tattu batteries with an AS150U plug including this one.

@jmachuca77
Copy link
Contributor

That’s what I tested with

@muramura
Copy link
Contributor

Why don't you do CRC checks on incoming messages?

@hendjoshsr71
Copy link
Member

hendjoshsr71 commented May 23, 2022

Which model #s of batteries does this work on? Need that for documentation so users don't select the wrong driver.
I assume it is a few from this page, https://www.grepow.com/page/uav-battery.html

@magicrub
Copy link
Contributor Author

This driver is hard-coded for the 12S flavor via TATTUCAN_CELL_COUNT_12S but with minor work from @jmachuca77 it could be more flexible to handle and auto-detect 6S and 14S without needing params.

@magicrub
Copy link
Contributor Author

Why don't you do CRC checks on incoming messages?

yup, good point. It's being ignored for now, like all the other non-DroneCAN drivers. It should be easy to add, just need to call crc_xmodem() . @jmachuca77 I didn't have a battery to test against which is why I ignored it, can you add that in?

}

// message complete!
memcpy((uint8_t*)&_message, data, _message_offset);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need this memcpy? Why not just have _message and data be a union, and then the only other things you need to store are just the cycle/remaining percentages, which are both currently being read without a semaphore anyway, and could be corrupt readings.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reworked to use a union, good idea! I was keeping them separate because I was hoping to make a larger buffer to handle 12S and 14S but lets get this 12S one in and then add more features later.

return false;
}

cycles = _message.cycle_life;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be protected by a semaphore if reading the backing array, or better still be reading from a copy aside that gets updated as part of read()

return false;
}

percentage = _message.remaining_percent;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as below, use a copy aside during read rather then directly accessing the _message struct which is a memcpy target.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This really just needs to be added to AP_BattMonitor::BattMonitor_State since UAVCAN also suffers from this. I can't do a semephore lock here because the backend is declares this function as const so even if it's added to the status (and therefore interim_state) we'll still need to change the backend

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you have to deconst the function that's still better then the random interrupt. But on first glance I'm not opposed to moving it into the state either, as it does seem odd to split it.

@magicrub
Copy link
Contributor Author

@jmachuca77 can you take a look at the comments from @WickedShell

@magicrub magicrub added the WIP label May 31, 2022
@Rataillon
Copy link

Hello, I tried your CAN Drivers with a Smart Tattu 12S battery on a CubePilot Orange but without success. It seems to me that I did not receive any data. Which board did you use for testing it and/or did I miss anything for using it?

@magicrub
Copy link
Contributor Author

magicrub commented Jul 1, 2022

@Rataillon sorry about that, I should close this. This branch is actually an older version of the driver. Try this newer version on my branch magicrub/pr/tattu_can3. I think there's still some testing that is pending on it before I make a new PR for it. Please test!

@CraigElder
Copy link
Contributor

CraigElder commented Jul 3, 2022

@Rataillon After working with GREPOW directly to support this TattuCAN protocol, we are now helping them implement DroneCAN in their batteries. It is quite close to working. Soon they will only sell DroneCAN batteries and the TattuCAN protocol will be deprecated by GREPOW

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

9 participants