Page 2 of 2
Re: Control A Servo through Arduino by controling a joint in Coppelia Sim
Posted: 11 May 2022, 11:43
by coppelia
if your client is expecting a number in text format, then simply send, e.g. "45.0\n"
Unfortunately we do not have the corresponding Arduino code...
Cheers
Re: Control A Servo through Arduino by controling a joint in Coppelia Sim
Posted: 11 May 2022, 15:25
by bsakal
Eureka! That works, thanks a lot.
But now I want to send the joint position, p1=sim.getJointPosition(joint), and how can I add this '/n' message with this variable?
Also for this code
Code: Select all
sim.serialSend(serialPortHandle,sim.packInt32Table({number})) -- send as coded int32
is there tutorial or example that I can follow to understand how it works?
Thank you very much for your time.
Sincerely,
Re: Control A Servo through Arduino by controling a joint in Coppelia Sim
Posted: 12 May 2022, 07:06
by coppelia
Then your client must be accepting angles in degrees, as strings.
So you can do, e.g.:
Code: Select all
local stringToSend=tostring(sim.getJointPosition(joint))..'\n'
Cheers
Re: Control A Servo through Arduino by controling a joint in Coppelia Sim
Posted: 13 May 2022, 10:26
by bsakal
Thanks a lot, once again everything works now. However, simulation send data so fast that the Arduino bottlenecks and gets unstable also the servo cannot reach that fast.
Is there a way to slow down the data send speed or maybe something like delay(500) to delay data send after each one.
Such as
Send Data
wait 0,5 secs
Send Data
wait 0,5 secs
Also, for this kind of codes should use a threaded script instead of the non-threaded?
Sincerely,
BS
Re: Control A Servo through Arduino by controling a joint in Coppelia Sim
Posted: 16 May 2022, 15:59
by coppelia
With a threaded script, you can use sim.wait.
With a non-threaded script, simply count how often you've sent data, and skip sensing if too frequent, e.g.:
Code: Select all
function sysCall_init()
lastTime=sim.getSystemTimeInMs(-1)
end
function sysCall_actuation()
currentTime=sim.getSystemTimeInMs(-1)
if currentTime-lastTime>500 then
...send data here...
lastTime=currentTime
end
end
Cheers
Re: Control A Servo through Arduino by controling a joint in Coppelia Sim
Posted: 17 May 2022, 17:13
by bsakal
Hello Mr. Admin,
Thank you very much for your contribution, your suggestions work like magic.
If a student would have a similar situation like mine - I want to write some hints.
AS I understood Coppelia Sim with basic serialsend code send to Arduino as chars and here this example 4 code works great with the task. It takes it and converts into integer.
I was not able to work with
Code: Select all
sim.serialSend(serialPortHandle,sim.packInt32Table({number})) -- send as coded int32
code, I will try to do it later on.
Re: Control A Servo through Arduino by controling a joint in Coppelia Sim
Posted: 17 May 2022, 17:15
by bsakal
Another question from me is:
I need to control several actuators from Simulation and I wonder
-How can I send several serial messages with maybe different headings so that Arduino can understand which code is which code? How can I achieve this, could you please guide me?