# Looping velocity logic

**URL:** <https://scilab.discourse.group/t/looping-velocity-logic/987>\
**Category:** Xcos\
**Created:** [June 25, 2025, 9:46am UTC](https://scilab.discourse.group/t/looping-velocity-logic/987 "2025-06-25T09:46:44Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![mikeyxd](https://avatars.discourse-cdn.com/v4/letter/m/aeb1de/32.png) [@mikeyxd](https://scilab.discourse.group/u/mikeyxd)\
**Post date:** [June 25, 2025, 9:46am UTC](https://scilab.discourse.group/t/looping-velocity-logic/987/1 "2025-06-25T09:46:44Z")

</div>

Hello, I have been trying to loop a velocity logic that I made recently but I cant seem to make it work. The velocity starts at 5/s and then after 25m, the velocity changes to 0, then when it becomes 0, it stays there for 3 sec, after the 3 sec delay it moves back with a speed of-5m/s until it goes back to the original position then once it reaches the original position, the velocity becomes 0 then i want it to loop. The attached below is the screenshot as well as the file for the velocity logic. It would help me greatly if someone could give me an insight on how to fix it. I am still new to xcos so I still have dificulties operating.

[velocity logic .zcos](https://scilab.discourse.group/uploads/short-url/gKwoTzHuNCsmby91x2YOw3o6b1C.zcos) (5.6 KB)

 ![Screenshot 2025-06-25 114536](https://global.discourse-cdn.com/free1/uploads/utc/original/1X/e42975c72fbadd82e4e60dbac7016d9616c20b45.png)

---

<div class="post-metadata">

**Author:** ![mottelet](https://yyz2.discourse-cdn.com/free1/user_avatar/scilab.discourse.group/mottelet/32/13_2.png) [@mottelet](https://scilab.discourse.group/u/mottelet)\
**Post date:** [June 25, 2025, 2:57pm UTC](https://scilab.discourse.group/t/looping-velocity-logic/987/2 "2025-06-25T14:57:38Z")

</div>

Hello,

Seeing your diagram (why make it so complicated when a simple solution exists), you are still using unappropriate methods (I gave you some advice some time ago, see [https://scilab.discourse.group/t/piecewise-velocity-over-time-scilab-xcos](https://scilab.discourse.group/t/piecewise-velocity-over-time-scilab-xcos)). If you want some help, you should first describe things precisely (you have some typos, e.g. does “5/s” mean “5m/s” ?).

_The velocity starts at 5/s and then after 25m, the velocity changes to 0, then when it becomes 0, it stays there for 3 sec, after the 3 sec delay it moves back with a speed of-5m/s until it goes back to the original position then once it reaches the original position, the velocity becomes 0 then i want it to loop_

Are you considering a point which is moving along a linear axis, initially at x=0, whose speed profile is defined on [0,t\_3] by

x'(t)=\left\{ \begin{array}{rr} 5 & \mbox{ for } t\leq t\_1,\\ 0 & \mbox{ for } t \in ]t\_1,t\_2],\\ -5 & \mbox{ for } t \in ]t\_2,t\_3] \end{array} \right.

with t\_2=t\_1+3 and such that x'(t) is periodic and has period t\_3 ? if the answer is yes, you have t\_1=5s, t\_2=8s and t\_3=13s and it is easy to generate x(t) in Xcos (and even make it periodic) by using the signal builder block:

[speedprofile.zcos](https://scilab.discourse.group/uploads/short-url/AqlIEXyOGPtNFHfDKVVmZfg4Hqp.zcos) (3.6 KB)

 ![Screenshot 2025-06-25 at 16.55.22](https://global.discourse-cdn.com/free1/uploads/utc/original/1X/9dcf98b5927f35d8afb287643ae5fc546baa9659.jpeg)  
 ![Screenshot 2025-06-25 at 16.55.18](https://global.discourse-cdn.com/free1/uploads/utc/original/1X/e4b77377e499d5c05b82c550c2173ddc9ace0bd9.jpeg)  
 ![Screenshot 2025-06-25 at 16.55.11](https://global.discourse-cdn.com/free1/uploads/utc/original/1X/0cb1bbb7c67eff0f0e132dcbbbf1b634462495ae.jpeg)

---

<div class="post-metadata">

**Author:** ![mikeyxd](https://avatars.discourse-cdn.com/v4/letter/m/aeb1de/32.png) [@mikeyxd](https://scilab.discourse.group/u/mikeyxd)\
**Post date:** [July 2, 2025, 9:38am UTC](https://scilab.discourse.group/t/looping-velocity-logic/987/3 "2025-07-02T09:38:28Z")

</div>

Hello,

Thank you for your reply and for pointing out the previous advice and corrections.

Yes, your interpretation is correct. I am considering a point moving along a linear axis,

Thank you for the recommendation to use the Signal Builder block in Xcos. I will try implementing it that way to keep the model cleaner and simpler. I wil make sure to also check what I post when asking for help

Thank you again for your help

---

<div class="post-metadata">

**Author:** ![mottelet](https://yyz2.discourse-cdn.com/free1/user_avatar/scilab.discourse.group/mottelet/32/13_2.png) [@mottelet](https://scilab.discourse.group/u/mottelet)\
**Post date:** [July 2, 2025, 11:54am UTC](https://scilab.discourse.group/t/looping-velocity-logic/987/4 "2025-07-02T11:54:45Z")

</div>

Hello,

I don’t claim that a method is systematically better than another. Sometimes using the block diagram logic operators may look simpler, but for a function using piecewise cases like yours, and when the switching times are well defined, the signal builder is the way to go.  
However, if the switching times were not defined in advance, the signal builder could not have been used.

S.
