qhdwight / frc-go

Go for FRC
MIT License
7 stars 0 forks source link

(Suggestion) Add documentation #7

Closed big-harry closed 2 years ago

big-harry commented 2 years ago

It'd be helpful if there were some documentation to help us make the most out of this library

qhdwight commented 2 years ago

Hi, I'm no longer in high school so I haven't been actively maintaining this project. But I'm happy to try and help out, what part is confusing? It will help me be able to refine the documentation.

big-harry commented 2 years ago

I think it'd be a good start to explain how to even to make a basic robot controller. So far you have an example for initialising the robot and your robot code which has minimal comments. I appreciate you still taking the time to look after this repository.

qhdwight commented 2 years ago

Just some preface: I'm a little hesitant to start changing around code since I no longer have access to a robot and don't want to push code that doesn't work. This repository in general is more of a playground rather than a legitimate infrastructure - although it has all the information required to get going it may require a bit of additional elbow grease.

That being said, you are welcome to make pull requests as you see fit.

For a basic robot controller, see robot.go and scroll down to the bottom. The init and periodic functions are there for you. I would probably separate out this from all of the HAL code above (this is actually what happens in the base class of Java TimedRobot but it's hidden!). Anyways we can see the talons can be initialized with NewTalon and joystick information via getJoystickAxis. Those functions are simply just wrappers for calling C functions in Go. Note that I had to make an addition layer between Go and the C++ phoenix library, that was done via an extern C block.

The cgo CFLAGS and LDFLAGS are very important! They tell Go where to find all these C symbols. If you're wondering where I got the library files, I stole them from the official wpilib repo on GitHub after building it locally on my computer. I can provide more information about that later if interested. You will have to update these if you chose to use the 2022 year. This is probably something that I am able to do.

big-harry commented 2 years ago

Well in robot.go it'd help if some of the functions/variables had like an explanation for what they are used for

big-harry commented 2 years ago

For example, C.HAL_Initialize(500, 0) could have a comment telling what 500 means in the context of this command

qhdwight commented 2 years ago

Yeah so all the HAL stuff is something you don't really need to worry about since it's standard across ALL programming languages and robot implementations. If you're really curious, check out https://github.com/wpilibsuite/allwpilib/blob/main/hal/src/main/native/include/hal/HALBase.h and https://github.com/wpilibsuite/allwpilib/blob/9fde0110b68828274a337f877eda307a413e4cba/wpilibj/src/main/java/edu/wpi/first/wpilibj/RobotBase.java#L424 to see how Java does it. It really should be hidden away from the user and in a different file.

qhdwight commented 2 years ago

See #9

big-harry commented 2 years ago

Sorry for leaving this issue open, I understood when I started actually using it