59浏览
查看: 59|回复: 1

[M10项目] 2025东莞创客嘉年华--主题3 运动健康 (未获奖)作品展示

[复制链接]
运动健康包括了科学健身、疾病防治、青少年成长、传统养生等多个领域,请设计一个与之相关的方案。可参考一下选题:趣味运动:为了提高青少年运动的兴趣,将其运动游戏化和趣味化运动健康管理:构建智能化健康管理方案,实现运动过程中身体的监测,预防运动受伤关注受伤后的恢复以及治疗


  1. import sys
  2. sys.path.append("/root/mindplus/.lib/thirdExtension/nick-pyttsx3-thirdex")
  3. sys.path.append("/root/mindplus/.lib/thirdExtension/nick-unihiker_wifi-thirdex")
  4. sys.path.append("/root/mindplus/.lib/thirdExtension/mengchangfeng-kimi-thirdex")
  5. sys.path.append("/root/mindplus/.lib/thirdExtension/nick-unihiker_sound-thirdex")
  6. import siot
  7. import time
  8. import pyttsx3
  9. from unihiker import GUI
  10. import openai
  11. import json
  12. from unihiker_sound import *
  13. from pinpong.board import Board
  14. from pinpong.board import DHT11
  15. from unihiker_connet_wifi import *
  16. from pinpong.board import Board, Pin
  17. from pinpong.extension.unihiker import *
  18. unihiker_sound = SoundManager()
  19. wifi_manager = WiFiManager()
  20. response_success = wifi_manager.connect_wifi(open("./WIFI").read().split("\n")[0], open("./WIFI").read().split("\n")[1])
  21. def on_message_callback(client, userdata, msg):
  22.     if msg.topic == (str("siot/sports/info")):
  23.         if msg.payload.decode().split("--")[0] == "cgq":
  24.             if msg.payload.decode().split("--")[1] == "voice":
  25.                 if int(msg.payload.decode().split("--")[2]) == 5:
  26.                     sports_mode_window()
  27.                     start_sports()
  28.                 if int(msg.payload.decode().split("--")[2]) == 6:
  29.                     end_sports()
  30.                 if int((msg.payload.decode().split("--")[2])) == 7:
  31.                     pass
  32.         elif msg.payload.decode().split("--")[0] == "time":
  33.             pass
  34.         elif msg.payload.decode().split("--")[0] == "":
  35.             pass
  36. siot.init(client_id="7078199769605087", server="10.1.2.3", port=1883, user="siot", password="dfrobot")
  37. Board().begin()
  38. u_gui = GUI()
  39. siot.connect()
  40. siot.loop()
  41. siot.set_callback(on_message_callback)
  42. siot.getsubscribe(topic="siot/sports/info")
  43. siot.getsubscribe(topic="siot/sports/chart")
  44. siot.getsubscribe(topic="siot/sports/chart_1")
  45. record_strength = 0
  46. single_sports_times_sec = 0
  47. total_sports_times_sec = 0
  48. engine = pyttsx3.init()
  49. unihiker_sound.set_volume(100)
  50. engine.setProperty('volume', 1)
  51. dht1 = DHT11(Pin(Pin.P24))
  52. client = openai.OpenAI(api_key=open("./key").read(),
  53.                        base_url="https://api.moonshot.cn/v1")
  54. kimi_model = "moonshot-v1-8k"
  55. kimi_temperature = 0.3
  56. kimi_history = [
  57.     {"role": "system", "content": """你是智能运动助手,
  58.     你更擅长中文和英文的对话。你会为用户提供安全,有帮助,准确的回答。
  59.     回答问题的时候尽量精简词语,尽量将回答控制在50字以内。
  60.     也不需要在回答中添加关于时效性或者是请注意之类的额外说明"""}
  61. ]
  62. def kimi_chat(query, kimi_history_, kimi_model_, kimi_temperature_):
  63.     kimi_history_.append({
  64.         "role": "user",
  65.         "content": query
  66.     })
  67.     completion = client.chat.completions.create(
  68.         model=kimi_model_,
  69.         messages=kimi_history_,
  70.         temperature=kimi_temperature_,
  71.     )
  72.     result = completion.choices[0].message.content
  73.     kimi_history_.append({
  74.         "role": "assistant",
  75.         "content": result
  76.     })
  77.     return result
  78. def hides(*sth):
  79.     for _ in sth:
  80.         _.config(x=-100, y=-100)
  81. def sports_mode_window():
  82.     print("运动模式")
  83.     hides(btn1, btn2, t1, t2, t3, t4, btn5, btn6, btn7, t5, t6, t7, t8, btn8)
  84.     t4.config(x=5, y=100)
  85.     btn5.config(x=5, y=5)
  86.     btn6.config(x=5, y=40)
  87.     btn7.config(x=135, y=5)
  88.     t5.config(x=5, y=145)
  89.     t6.config(x=5, y=165)
  90.     t7.config(x=5, y=185)
  91. def main_window():
  92.     hides(btn1, btn2, t1, t2, t3, t4, btn5, btn6, btn7, t5, t6, t7, t8, btn8)
  93.     btn1.config(x=5, y=10)
  94.     btn2.config(x=120, y=10)
  95.     t1.config(x=5, y=100)
  96.     t2.config(x=5, y=135)
  97.     t3.config(x=5, y=170)
  98. def report_window():
  99.     hides(btn1, btn2, t1, t2, t3, t4, btn5, btn6, btn7, t5, t6, t7, t8, btn8)
  100.     t8.config(x=5, y=35)
  101.     btn8.config(x=5, y=5)
  102.     btn7.config(x=135, y=5)
  103. def start_sports():
  104.     global record_time, record_strength, main
  105.     t4.config(text="运动状态:已开始")
  106.     record_time = u_gui.start_thread(u_record_time_function)
  107.     record_strength = u_gui.start_thread(u_record_strength_function)
  108.     main = u_gui.start_thread(u_main_function)
  109. def end_sports():
  110.     t4.config(text="运动状态:已结束")
  111.     u_gui.stop_thread(record_time)
  112.     u_gui.stop_thread(record_strength)
  113. def report():
  114.     t8.config(text="正在分析...")
  115.     ttt = kimi_chat(
  116.         f"分析给出数据以返回运动分析报告: 运动时长(s):{single_sports_times_sec} 温度(摄氏度):{dht1.temp_c()} 湿度(%rh):{dht1.humidity()}",
  117.         kimi_history, kimi_model, kimi_temperature)
  118.     t8.config(text=ttt)
  119.     engine.say(ttt)
  120.     engine.runAndWait()
  121. record_time = 0
  122. main = 0
  123. btn1 = u_gui.add_button(text="运动模式", x=5, y=10, w=80, h=30, onclick=sports_mode_window)
  124. btn2 = u_gui.add_button(text="健康报告", x=120, y=10, w=80, h=30, onclick=report_window)
  125. t1 = u_gui.draw_text(text="当前状态:待机中", x=5, y=100, font_size=10, color="#0000FF")
  126. t2 = u_gui.draw_text(text="今日运动: 0分钟 ", x=5, y=135, font_size=10, color="#999900")
  127. t3 = u_gui.draw_text(text="语音提示: 说"开始运动"启动 ", x=5, y=170, font_size=10, color="#00FF00")
  128. t4 = u_gui.draw_text(text="运动状态:未知", x=-100, y=-100, font_size=10, color="#00FF00")
  129. btn5 = u_gui.add_button(text="开始运动", x=-100, y=-100, w=80, h=30, onclick=start_sports)
  130. btn6 = u_gui.add_button(text="结束运动", x=-100, y=-100, w=80, h=30, onclick=end_sports)
  131. btn7 = u_gui.add_button(text="返回主界面", x=-100, y=-100, w=100, h=30, onclick=main_window)
  132. t5 = u_gui.draw_text(text="已运动 NaN 分钟 NaN 秒", x=-100, y=-100, font_size=10, color="#00FF00")
  133. t6 = u_gui.draw_text(text="当前湿度:", x=-100, y=-100, font_size=10, color="#000000")
  134. t7 = u_gui.draw_text(text="当前温度:", x=-100, y=-100, font_size=10, color="#000000")
  135. t8 = u_gui.draw_text(text="", x=-100, y=-100, font_size=10, color="#000000", w=230)
  136. btn8 = u_gui.add_button(text="报告", x=-100, y=-100, w=80, h=30, onclick=report)
  137. def StoSM(s):
  138.     return f"{(s - s % 60) // 60}分{s % 60}秒"
  139. def u_record_time_function():
  140.     global single_sports_times_sec, total_sports_times_sec
  141.     single_sports_times_sec = 0
  142.     while True:
  143.         time.sleep(1)
  144.         single_sports_times_sec += 1
  145.         total_sports_times_sec += 1
  146. def u_record_strength_function():
  147.     while True:
  148.         time.sleep(3)
  149.         siot.publish(topic="siot/sports/info",
  150.                      data=f"info--strength--{(accelerometer.get_strength() + 1) ** 2.5}")
  151.         siot.publish_save(topic="siot/sports/chart", data=(accelerometer.get_strength() + 1) ** 2.5)
  152.         siot.publish_save(topic="siot/sports/chart_1", data=f"{dht1.temp_c()},{dht1.humidity()}")
  153. def u_main_function():
  154.     while True:
  155.         t5.config(text=(str("已运动") + str(StoSM(single_sports_times_sec))))
  156.         t6.config(text=f"当前湿度:{dht1.humidity()}")
  157.         t7.config(text=f"当前温度:{dht1.temp_c()}")
  158.         last_record = accelerometer.get_strength()
  159.         time.sleep(0.001)
  160.         if accelerometer.get_strength() - last_record >= 3:
  161.             engine.say("你还好吗?你摔到了吗?")
  162.             engine.runAndWait()
  163.             for _ in range(5):
  164.                 buzzer.pitch(988, 1)
  165.                 buzzer.pitch(523, 1)
  166.                 buzzer.pitch(698, 1)
  167.                 buzzer.pitch(311, 1)
  168.                 buzzer.pitch(156, 1)
  169. while True:
  170.     t2.config(text=f"今日运动: {StoSM(total_sports_times_sec)}")
复制代码

运动报告(已获取数据)

运动报告(已获取数据)

主界面

主界面

运动报告(未获取数据)

运动报告(未获取数据)

运动报告(已获取数据)

运动报告(已获取数据)

siot

siot

可视化界面

可视化界面

运动模式

运动模式

孙洪尧1985  高级技师

发表于 2025-6-28 21:27:24

虽然未获奖,但是我觉得是很有意义的项目
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

为本项目制作心愿单
购买心愿单
心愿单 编辑
[[wsData.name]]

硬件清单

  • [[d.name]]
btnicon
我也要做!
点击进入购买页面
上海智位机器人股份有限公司 沪ICP备09038501号-4 备案 沪公网安备31011502402448

© 2013-2025 Comsenz Inc. Powered by Discuz! X3.4 Licensed

mail