FireFly编辑器调用C语言,grasshopper的插件FireFly 萤火虫

本帖最后由 lettle 于 2010-4-8 12:12 编辑

grasshopper的插件FireFly  萤火虫 不知道有人发过没有,如果有 版主删了吧。。。。

来自于http://www.liftarchitects.com/journal/2010/3/11/firefly-beta-release.html#comments

安装到x:\Program Files\Rhinoceros 4.0\Plug-ins\Grasshopper\Components里面

对计算机语言无感   貌似是连接Arduino与grasshopper的  具体翻译如下How to use the Serial Read component:

The Serial Read component allows you to retrieve a value coming over the Serial Port. There are three input nodes for this component.

The P-input (Port Number) has to be the same Serial Port assigned in the Arduino IDE.  The default port is set to 3 (ie. COM 3) although

this port value may vary depending on computer configurations.  The B-input (Baud Rate) value should match the speed set in the Arduino

sketch.  Standard values include: 4800, 9600, 14400, 19200, 28800, 38400, 57600. The N-input requires an integer in order to (0) Open Port,

(1) Get Value, or (2) Close Port.  You can connect a Timer component to the Serial Read component to retreive values at a given interval.

Note: you should only turn the Timer component "On" after you have opened the port(0) and then retrieved the first value (1).  The output

for this component will return a string.  If you have sent a numeric value to the Serial Port, you will need to cast the string output of

the Serial Read component into a numeric value.  To do this, simply feed the output of the Serial Read component into a Number or Integer

parameter (Params/Primitive).

How to use the Serial Write component:

The Serial Write component allows you to write a string value to the Serial Port.  There are four input nodes for this component.  The

N,P, and B inputs are the same as the Serial Read (see above for more information).  The D-input is the data you wish to write to the

Serial Port.  Note: This component does not need to use a Timer component to update at a given interval if you are sending slider information

to the Serial Port.

如何使用串行读组件:

串行读取组件允许您检索一个值通过串口来。这有三个组件的输入节点。

该P -输入(端口号)必须在同一串口IDE中的阿都伊诺分配。默认的端口设置为3(即COM 3个),尽管

此端口值可能取决于计算机的配置。这架B -输入(波特率)值应匹配的Arduino设定速度

素描。标准值包括:4800,9600,14400,19200,28800,38400,57600。的N -输入需要一个整数,以(0)开放港口,

(1)获取的价值,或(2)关闭端口。您可以连接一个Timer组件的串行读组件retreive在给定区间值。

注意:您应该只打开“后,你已经打开的端口(0定时器组成部分”),然后检索到的第一个值(1)。输出

此组件将返回一个字符串。如果你有一个数字值发送到串行端口,你将需要把字符串输出

串行读取内容纳入一个数字值。要做到这一点,只需馈入一个数或整数的分量输出的串行读

参数(Params /原始)。

串行写入组件允许你写一个字符串值到串行端口。这有四个组件的输入节点。该

氮,磷和B输入为串行读相同(见上面获取更多信息)。该D -输入的数据,你想写信给

串行端口。注意:此组件并不需要使用一个Timer组件更新在给定的时间间隔,如果你发送信息滑块

到串行端口。

9883f91cc66f57a601628a31877e41ff.gif

2010-4-8 12:12 上传

点击文件名下载附件

下载积分: 照度 -1 lux

10.22 KB, 下载次数: 260, 下载积分: 照度 -1 lux

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
萤火虫算法是一种基于自然界萤火虫行为的启发式优化算法,用于解决优化问题。它模拟了萤火虫的交互行为,通过光强度和吸引度来调整萤火虫的移动方向,从而找到最优解。 路径规划是指在给定起点和终点的情况下,确定一条最优路径以满足特定的约束条件。萤火虫算法可以应用于路径规划问题,通过优化萤火虫的移动策略来寻找最优路径。 以下是基于萤火虫算法的路径规划的示例代码: ```python # 导入必要的库 import numpy as np # 定义萤火虫类 class Firefly: def __init__(self, position): self.position = position self.intensity = 0 def __str__(self): return f"Position: {self.position}, Intensity: {self.intensity}" # 定义路径规划函数 def path_planning(start, end, num_fireflies, max_iterations): # 初始化萤火虫群体 fireflies = [Firefly(start) for _ in range(num_fireflies)] # 迭代更新萤火虫位置和亮度 for _ in range(max_iterations): for i in range(num_fireflies): for j in range(num_fireflies): if fireflies[j].intensity > fireflies[i].intensity: # 计算吸引度 attractiveness = calculate_attractiveness(fireflies[i], fireflies[j]) # 更新位置 fireflies[i].position += attractiveness * (fireflies[j].position - fireflies[i].position) # 更新亮度 fireflies[i].intensity = calculate_intensity(fireflies[i]) # 选择最优路径 best_firefly = max(fireflies, key=lambda x: x.intensity) best_path = best_firefly.position return best_path # 计算吸引度 def calculate_attractiveness(firefly1, firefly2): distance = np.linalg.norm(firefly1.position - firefly2.position) attractiveness = 1 / (1 + distance) return attractiveness # 计算亮度 def calculate_intensity(firefly): intensity = np.linalg.norm(firefly.position) return intensity # 示例使用 start = np.array([0, 0]) end = np.array([10, 10]) num_fireflies = 10 max_iterations = 100 best_path = path_planning(start, end, num_fireflies, max_iterations) print("Best path:", best_path) ``` 这段代码演示了如何使用萤火虫算法进行路径规划。在示例中,我们定义了一个萤火虫类,包含位置和亮度属性。然后,我们定义了路径规划函数,其中使用萤火虫算法迭代更新萤火虫的位置和亮度。最后,我们选择亮度最高的萤火虫作为最优路径。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值