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

Libhal 2.0 port science #114

Merged
merged 135 commits into from
Jan 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
135 commits
Select commit Hold shift + click to select a range
b3cf470
:construction: working on porting to 2.0, started base file structure
Coreyboy1820 Jul 4, 2023
c491d15
started porting to libhal prebuilts
Coreyboy1820 Jul 9, 2023
de04b29
working on port
Coreyboy1820 Jul 21, 2023
4c3b370
Nearly finished up the init platform. Will work on mc next
Coreyboy1820 Jul 23, 2023
6336afe
:sparkles: finished the initalizing platform
Coreyboy1820 Jul 23, 2023
b06e2b2
:sparkles: :construction: finished converting all the basic logic to …
Coreyboy1820 Jul 29, 2023
24f6c90
:constructions: nealy finished mission control implementation
Coreyboy1820 Jul 29, 2023
c6f2dbf
:construction: finished adding mission control just need to fix errors
Coreyboy1820 Jul 30, 2023
68d8825
This is before I switch all of the pairs to using pointers
Coreyboy1820 Jul 30, 2023
ee8c8be
:sparkles: finished switching the servos over to offset homing
Coreyboy1820 Jul 30, 2023
9e25e2f
:sparkles: finished changing from shared pointers to regular pointers…
Coreyboy1820 Jul 30, 2023
90cfa27
updated the mission control
Coreyboy1820 Jul 30, 2023
0b156d9
:sparkles: changed homing function to be a template function so it no…
Coreyboy1820 Jul 30, 2023
f805225
:sparkles: switched away from int to size_t
Coreyboy1820 Jul 30, 2023
fd323b2
:sparkles: finished switching from templates
Coreyboy1820 Jul 30, 2023
686776e
:sparkles:updated code to use homing structs instead of passing in se…
Coreyboy1820 Jul 31, 2023
b5bf910
:bug:finished testing and slight bug fixing
Coreyboy1820 Jul 31, 2023
5307bd8
fixed arm to build succesfully
Coreyboy1820 Aug 5, 2023
5f7de42
untested stuff to get commands
Viha123 Aug 5, 2023
050fbda
fixing bugs drive esp
Viha123 Aug 5, 2023
c42cdb5
:bandaid: fixed project name in cmake
Coreyboy1820 Aug 18, 2023
9230c83
:construction: finished testing for the day
Coreyboy1820 Aug 19, 2023
49b5fbe
Fixed main part of code
Coreyboy1820 Aug 26, 2023
b5a0ca1
found issue with version numbers
Coreyboy1820 Aug 31, 2023
f2f7691
:construction: :sparkles: got code to cycle through but the floats ar…
Coreyboy1820 Sep 1, 2023
28852a0
:sparkles: reverted back to using hardware and not print implementations
Coreyboy1820 Sep 1, 2023
ad92cc7
:sparkles: added floating point support in cmake
Coreyboy1820 Sep 1, 2023
ef9a7bd
Merge branch 'libhal2.0-port-reverting-to-hardware' into libhal2.0-port
Coreyboy1820 Sep 1, 2023
f0d9dfe
builds lmao
FluffyFTW Sep 2, 2023
ada2831
Parsing commands currently works, just need to work out a bug which c…
Coreyboy1820 Sep 8, 2023
72510e4
buildable
FluffyFTW Sep 11, 2023
f72ed67
.
Coreyboy1820 Sep 11, 2023
be0eaf4
angles change
FluffyFTW Sep 16, 2023
7a6832f
bug found where subtracting in offset servo instead of adding
Coreyboy1820 Sep 23, 2023
cdecc45
debugging offsets with servos
Coreyboy1820 Sep 23, 2023
cb15537
changed order of legs in drive
Coreyboy1820 Sep 29, 2023
2dd45bf
:construction: finished testing for the day
Coreyboy1820 Aug 19, 2023
1593e58
Fixed main part of code
Coreyboy1820 Aug 26, 2023
875cb7a
.
Coreyboy1820 Sep 11, 2023
c5b54d9
found issue with version numbers
Coreyboy1820 Aug 31, 2023
556f0c2
bug found where subtracting in offset servo instead of adding
Coreyboy1820 Sep 23, 2023
740db42
:construction: :sparkles: got code to cycle through but the floats ar…
Coreyboy1820 Sep 1, 2023
ee4c648
tmp
FluffyFTW Sep 26, 2023
2fe6e82
:sparkles: added floating point support in cmake
Coreyboy1820 Sep 1, 2023
a818ab0
building debug on ubuntu22.04
FluffyFTW Sep 26, 2023
c06bdd6
:sparkles: reverted back to using hardware and not print implementations
Coreyboy1820 Sep 1, 2023
e34e1eb
changed max rmp to 2
FluffyFTW Sep 29, 2023
c01794d
Parsing commands currently works, just need to work out a bug which c…
Coreyboy1820 Sep 8, 2023
f633662
esp not updating
FluffyFTW Oct 7, 2023
851f956
10/16
FluffyFTW Oct 17, 2023
e6b4277
added static to socket config in lpc
Coreyboy1820 Oct 18, 2023
7e635e9
10/17
FluffyFTW Oct 18, 2023
249862d
10/17
FluffyFTW Oct 18, 2023
6ab1e8f
esp works now
FluffyFTW Oct 19, 2023
a8e9ecc
fuck lerp
FluffyFTW Oct 19, 2023
311b171
:alien: Libhal 2.0 update for arm
Coreyboy1820 Sep 11, 2023
29df351
Merge branch 'libhal2.0-arm' of https://github.com/SJSURoboticsTeam/u…
Coreyboy1820 Oct 19, 2023
245aa69
:alien: merged arm libhal2.0 port into main 2.0 port
Coreyboy1820 Oct 19, 2023
43ef590
:alien: ported arms esp over to drives
Coreyboy1820 Oct 19, 2023
a1c9e48
:construction: fixed bugs, now need to revert parse commands
Coreyboy1820 Oct 19, 2023
c362d03
:sparkles: brought in old drive parse commands and fixed it, code now…
Coreyboy1820 Oct 19, 2023
6c51ed2
:ambulance: Fixed homing
FluffyFTW Oct 20, 2023
5a804c5
:sparkles: fully finished converting arm and drive to libhal 2.0, arm…
Coreyboy1820 Oct 21, 2023
809bf7e
:fire: removed all of the old code
Coreyboy1820 Oct 21, 2023
8cbfcff
beginning lpc4078 port
Viha123 Oct 22, 2023
1b4ebf3
Merge branch 'libhal2.0-port' into libhal-2.0-port-science
Viha123 Oct 23, 2023
933dcef
target platform builds
Viha123 Oct 23, 2023
e66e0ed
added platform-implementation files
Viha123 Nov 4, 2023
350a1e5
demos
Viha123 Nov 4, 2023
ac46788
science on libhal 2.0 has been updated
Viha123 Nov 4, 2023
33ac77a
deleted one of the flatform files cuz not required
Viha123 Nov 6, 2023
9bdda38
scd40.hpp and scd40.cpp transfered
Nov 11, 2023
563d818
transfer scd40.cpp
MichaelYKersey Nov 11, 2023
84381b4
transfer scd40.hpp
MichaelYKersey Nov 11, 2023
3abde90
fix no return for read of scd40
MichaelYKersey Nov 11, 2023
c2a6a07
It works, trust me
andrew-bork Nov 11, 2023
f826011
finished scd40 file transfer
Nov 11, 2023
a54c388
git scd40.cpp indentaiton
MichaelYKersey Nov 11, 2023
7dd31ab
fix scd40 namespace
MichaelYKersey Nov 11, 2023
6b795ce
add member variables for scd40
MichaelYKersey Nov 11, 2023
0506bc2
fix member variable names for scd40
MichaelYKersey Nov 11, 2023
031a924
create starter demo
MichaelYKersey Nov 12, 2023
a2c75f7
scd40 demo
MichaelYKersey Nov 12, 2023
75b7bd0
get_co2 method
MichaelYKersey Nov 12, 2023
3da5489
get_RH method
MichaelYKersey Nov 12, 2023
7f820a7
get_RH and get_temp
Nov 12, 2023
72fe910
Revert "get_co2 method"
MichaelYKersey Nov 12, 2023
fde9a57
get_temp and get_RH
Nov 12, 2023
09f67c9
Merge branch 'scd40-driver-libhal-2.0' of github.com:SJSURoboticsTeam…
MichaelYKersey Nov 12, 2023
d0f9d2e
:sparkles: update cmakelists to add sources
Viha123 Nov 17, 2023
9bc5c49
scd40 demo
Nov 18, 2023
76bfda0
print statments added to scd40_demo.cpp
Nov 18, 2023
260d290
:rotatiing_light: fixed errors and added buffer reading
MichaelYKersey Nov 19, 2023
2f10cd0
:recycle: have get functions call the get buffer functions
MichaelYKersey Nov 19, 2023
5ece00f
start color sensor
Viha123 Nov 28, 2023
0e21011
Created sht21 driver skeleton
andrew-bork Dec 4, 2023
8a31117
Implemented sht21 driver
andrew-bork Dec 4, 2023
102f8d4
correct where get_RH_buffer() reads in the buffer
MichaelYKersey Dec 4, 2023
cc42592
fix demo print and change to table
MichaelYKersey Dec 4, 2023
775a6c2
fix conan libhal version
MichaelYKersey Dec 4, 2023
4107ad0
remove call to removed method
MichaelYKersey Dec 9, 2023
b7bf426
read returns a struct for data
MichaelYKersey Dec 17, 2023
7d32f70
remove individual data read methods in scd40.hpp
MichaelYKersey Dec 17, 2023
2e4ff7f
implementation of color sensor done, demo and testing requried
Viha123 Dec 22, 2023
4ade829
values change but they don't seem accurate, validity of sensor needs …
Viha123 Dec 24, 2023
7e9e21b
:twisted_rightwards_arrows: update branch with master
Viha123 Dec 26, 2023
3c06eea
Rename scd40 Adresses
MichaelYKersey Dec 30, 2023
9dba9f6
Reimplement scd40 stop
MichaelYKersey Dec 30, 2023
737eef4
Add scd40 Settting Addresses
MichaelYKersey Dec 30, 2023
ffa698e
Fixed scd40_demo to use struct
Dec 30, 2023
68e8bbb
Add crc fuction in scd40.hpp
MichaelYKersey Dec 30, 2023
32ef530
Fixed scd40_demo to use struct
Dec 30, 2023
312d262
Adapt CRC code from data sheet
MichaelYKersey Jan 6, 2024
ff6590d
Finished basic setting functions have not tested set_settings
Jan 7, 2024
55c6a95
added soil_sensor_demo to science demos cmake
andrew-bork Jan 7, 2024
ece3aa5
Created soil sensor demo
andrew-bork Jan 7, 2024
b5c4a48
Added untested warnings
andrew-bork Jan 7, 2024
f7a0cc3
Fixed default parameters and scaling factors for sensor functions
andrew-bork Jan 7, 2024
a997978
deleeted extra files and color sensor works kind of, will need to buy…
Viha123 Jan 9, 2024
8f55fe7
Seprate scd40 crc method into generate and validate
MichaelYKersey Jan 13, 2024
f36f904
Chages finally committed
Jan 13, 2024
30eddd2
merge conflict somewhat resolved
Jan 13, 2024
7494a44
Merge branch 'libhal-2.0-port-science' into scd40-driver-libhal-2.0
MichaelYKersey Jan 13, 2024
846f0e7
Gave option to set some of the settings
Jan 13, 2024
cdd5259
Create blank perstaltic-pump.cpp & .hpp
MichaelYKersey Jan 13, 2024
d9f7fa4
data type of settings and read_data channged from double to float
Jan 20, 2024
2e69bda
Created Light Strip Driver
andrew-bork Jan 21, 2024
ec48887
Create led strip driver
andrew-bork Jan 21, 2024
3ea6fbe
Updated driver with lights array seperated
andrew-bork Jan 21, 2024
a47c064
Merge pull request #108 from SJSURoboticsTeam/scd40-driver-libhal-2.0
Viha123 Jan 23, 2024
f228532
Merge branch 'libhal-2.0-port-science' into sk922-led-strip-driver
Viha123 Jan 23, 2024
5d3fd83
Merge pull request #112 from SJSURoboticsTeam/sk922-led-strip-driver
Viha123 Jan 23, 2024
faa8a63
Merge branch 'libhal-2.0-port-science' into soil-sensor-driver
Viha123 Jan 23, 2024
75a1a0d
Merge pull request #113 from SJSURoboticsTeam/soil-sensor-driver
Viha123 Jan 23, 2024
ee08e0e
Merge branch 'main' into libhal-2.0-port-science
Viha123 Jan 23, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions code/science/implementations/scd40.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#pragma once

#include <libhal-util/i2c.hpp>
#include <libhal-util/serial.hpp>
#include "scd40.hpp"

scd40::create(hal::i2c& p_i2c, hal::steady_clock& clock){
scd40 scd40 = scd40(p_i2c, clock);
HAL_CHECK(scd40.start())

}

scd40::start(){}

scd40::get_CO2{}

scd40::get_RH(){}

scd40::get_temp(){}
22 changes: 22 additions & 0 deletions drive/implementations/command_lerper.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#pragma once

#include "../dto/drive.hpp"

namespace sjsu::drive {
class command_lerper
{
public:
int lerp(int speed)
{
previous_speed =
static_cast<int>(std::lerp(static_cast<float>(previous_speed),
static_cast<float>(speed),
speed_lerp));
return previous_speed;
}

private:
static constexpr float speed_lerp = 0.1f;
float previous_speed = 0; // don't touch mode or wheel orientation logic
};
} // namespace Drive
66 changes: 66 additions & 0 deletions drive/implementations/mode_switcher.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
#pragma once

#include "../dto/drive.hpp"
#include "../dto/motor_feedback.hpp"
#include "../platform-implementations/mission_control.hpp"

namespace sjsu::drive {
class mode_switch
{
public:
// Should handle all the logic for switching to new steer mode
mission_control::mc_commands switch_steer_mode(
mission_control::mc_commands commands,
tri_wheel_router_arguments previous_arguments,
motor_feedback current_motor_feedback,
hal::serial& terminal)
{
bool hubs_stopped((previous_arguments.left.speed >= -0.01f &&
previous_arguments.left.speed <= 0.01f) &&
(previous_arguments.right.speed >= -0.01f &&
previous_arguments.right.speed <= 0.01f) &&
(previous_arguments.back.speed >= -0.01f &&
previous_arguments.back.speed <= 0.01f));

bool steers_stopped((current_motor_feedback.left_steer_speed >= -0.01f &&
current_motor_feedback.left_steer_speed <= 0.01f) &&
(current_motor_feedback.right_steer_speed >= -0.01f &&
current_motor_feedback.right_steer_speed <= 0.01f) &&
(current_motor_feedback.back_steer_speed >= -0.01f &&
current_motor_feedback.back_steer_speed <= 0.01f));

if (previous_mode_ != commands.mode) {
in_the_middle_of_switching_modes_ = true;
skip_once_ = true;
}

if (in_the_middle_of_switching_modes_) {
commands.speed = 0;
if (!hubs_stopped) {
commands.mode = previous_mode_;
return commands;
} // hubs must be stopped to pass here

else if (!skip_once_ && steers_stopped) {
in_the_middle_of_switching_modes_ = false;
skip_once_ = true;
} // only once steer motors have stopped moving after hubs stopped will
// we exit switching modes
previous_mode_ = commands.mode;
skip_once_ = false;
}

return commands;
}

private:

char previous_mode_ =
'H'; // This is H for homing when the rover turns on, it makes sure that we
// don't switch to drive mode and allow commands to be parsed through
bool in_the_middle_of_switching_modes_ = true;
bool skip_once_ = true;

};

} // namespace Drive
22 changes: 22 additions & 0 deletions drive/implementations/serial.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#pragma once

#include <libhal/serial.hpp>

#include <string_view>

namespace Drive {
inline hal::result<std::string_view> get_commands(hal::serial& terminal)
{
std::array<hal::byte, 8192> buffer{};
auto received = HAL_CHECK(terminal.read(buffer)).data;
if (received.size() != 0) {
auto response = std::string_view(
reinterpret_cast<const char*>(received.data()), received.size());
hal::print<200>(
terminal, "%.*s", static_cast<int>(response.size()), response.data());
return response;
} else {
return std::string_view("");
}
}
} // namespace Drive
25 changes: 9 additions & 16 deletions science/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,20 +1,7 @@
# Copyright 2023 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

cmake_minimum_required(VERSION 3.20)

project(starter_project.elf VERSION 0.0.1 LANGUAGES CXX)
project(science VERSION 0.0.1 LANGUAGES CXX)

set(platform_library $ENV{LIBHAL_PLATFORM_LIBRARY})
set(platform $ENV{LIBHAL_PLATFORM})
Expand All @@ -26,15 +13,21 @@ endif()

find_package(libhal-${platform_library} REQUIRED CONFIG)
find_package(libhal-util REQUIRED CONFIG)
find_package(libhal-esp8266 REQUIRED CONFIG)

add_executable(${PROJECT_NAME}
main.cpp
application.cpp
applications/application.cpp
platforms/${platform}.cpp)
target_include_directories(${PROJECT_NAME} PUBLIC .)
target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_20)
target_link_options(${PROJECT_NAME} PRIVATE
--oslib=semihost --crt0=minimal)
target_link_libraries(${PROJECT_NAME} PRIVATE
libhal::${platform_library}
libhal::util)
libhal::util
libhal::esp8266)

# target_link_options(${PROJECT_NAME} INTERFACE "LINKER:--no-warn-rwx-segments")
libhal_post_build(${PROJECT_NAME})

26 changes: 0 additions & 26 deletions science/application.cpp

This file was deleted.

34 changes: 0 additions & 34 deletions science/application.hpp

This file was deleted.

6 changes: 4 additions & 2 deletions science/conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,13 @@ def build_requirements(self):

def requirements(self):
# Application requirements
self.requires("libhal-util/[^3.0.0]")
self.requires("libhal/[^2.0.3]")
self.requires("libhal-util/[^3.0.1]")
self.requires("libhal-esp8266/[^2.0.1]")

# List of supported platforms
if str(self.options.platform).startswith("lpc40"):
self.requires("libhal-lpc40/[^2.0.0]")
self.requires("libhal-lpc40/[^2.1.2]")
else:
raise ConanInvalidConfiguration(
f"The platform '{str(self.options.platform)}' is not"
Expand Down
9 changes: 8 additions & 1 deletion science/demos/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,16 @@ libhal_build_demos(
DEMOS
co2_demo
pressure_sensor_demo

soil_sensor_demo
scd40_demo
color_sensor_demo
led_strip_demo

SOURCES
../platform-implementations/scd40.cpp
../platform-implementations/pressure_sensor_bme680.cpp
../platform-implementations/soil_sensor_sht21.cpp
../platform-implementations/color_sensor_opt4048.cpp

PACKAGES
libhal-lpc40
Expand Down
33 changes: 33 additions & 0 deletions science/demos/applications/co2_demo.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#include <libhal-armcortex/dwt_counter.hpp>
#include <libhal-armcortex/startup.hpp>
#include <libhal-armcortex/system_control.hpp>
#include <libhal-util/serial.hpp>
#include <libhal-util/steady_clock.hpp>
#include <libhal/units.hpp>

#include "../../platform-implementations/co2_sensor_sc40.cpp"
#include "../hardware_map.hpp"

using namespace hal::literals;
using namespace std::chrono_literals;
namespace sjsu::science {

hal::status application(application_framework& p_framework)
{
// configure drivers
auto& i2c2 = *p_framework.i2c;
auto& clock = *p_framework.steady_clock;
auto& terminal = *p_framework.terminal;

auto co2_sensor = HAL_CHECK(science::co2_sensor::create(i2c2, clock));

while (true) {
hal::delay(clock, 500ms);
auto co2_level = HAL_CHECK(co2_sensor.read_co2());
hal::print<64>(terminal, "C02: %d\n", co2_level);
hal::delay(clock, 1ms);
}

return hal::success();
}
} // namespace sjsu::science
54 changes: 54 additions & 0 deletions science/demos/applications/color_sensor_demo.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#include <libhal-armcortex/dwt_counter.hpp>
#include <libhal-armcortex/startup.hpp>
#include <libhal-armcortex/system_control.hpp>
#include <libhal-util/serial.hpp>
#include <libhal-util/steady_clock.hpp>
#include <libhal/units.hpp>

#include "../../platform-implementations/color_sensor_opt4048.hpp"
#include "../hardware_map.hpp"

using namespace hal::literals;
using namespace std::chrono_literals;

hal::status probe_bus(hal::i2c& i2c, hal::serial& console) {
hal::print(console, "\n\nProbing i2c2\n");
for(hal::byte addr = 0x08; addr < 0x78; addr++) {
if (hal::probe(i2c, addr)) {
hal::print<8>(console, "0x%02X ", addr);
}else{
hal::print(console, " -- ");
}
if(addr % 8 == 7) {
hal::print(console, "\n");
}
}
hal::print(console, "\n");

return hal::success();
}

namespace sjsu::science {

hal::status application(application_framework& p_framework)
{
// configure drivers
auto& i2c2 = *p_framework.i2c;
auto& clock = *p_framework.steady_clock;
auto& terminal = *p_framework.terminal;

hal::print(terminal, "hi\n");
HAL_CHECK(probe_bus(i2c2, terminal));

//create the stuff here
auto color_sensor = HAL_CHECK(science::opt4048::create(i2c2, clock, terminal));
while(true){
hal::print(terminal, "\nnew measurement\n");
auto readings = HAL_CHECK(color_sensor.get_data());
hal::print<40>(terminal, "R: %f\t G: %f\t B: %f\n", readings.r, readings.g, readings.b);
hal::delay(clock, 50ms);
}

return hal::success();
}
} // namespace sjsu::science
Loading
Loading