Skip to content

Commit

Permalink
servo files updated
Browse files Browse the repository at this point in the history
  • Loading branch information
thisguyistotallyben committed Mar 7, 2018
1 parent 1f0419f commit a709499
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 2 deletions.
3 changes: 3 additions & 0 deletions appendages/json/servo.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"pin": "int"
}
8 changes: 6 additions & 2 deletions appendages/src/servo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,16 @@

#include <cmd_messenger/cmd_messenger.hpp>

using namespace rip::utilities;

namespace rip
{
namespace appendages
{
Servo::Servo(const nlohmann::json& config, const std::map<std::string, int>& command_map, std::shared_ptr<cmdmessenger::Device> device)
: Appendage(config, device)
, m_write(createCommand("kServoWrite", command_map, cmdmessenger::ArduinoCmdMessenger::makeArgumentString<typename cmdmessenger::ArduinoCmdMessenger::IntegerType, typename cmdmessenger::ArduinoCmdMessenger::IntegerType>()))
, m_write(createCommand("kServoWrite", command_map, cmdmessenger::ArduinoCmdMessenger::makeArgumentString<typename utilities::cmdmessenger::ArduinoCmdMessenger::IntegerType, typename utilities::cmdmessenger::ArduinoCmdMessenger::IntegerType>()))
, m_id(device) // MAYBE?

This comment has been minimized.

Copy link
@xxAtrain223

xxAtrain223 Mar 7, 2018

Contributor

m_id, will be set by the Appendage constructor here:

m_id = config["id"];

{
}

Expand All @@ -24,11 +27,12 @@ namespace rip

void Servo::stop()
{

// no stop command?

This comment has been minimized.

Copy link
@xxAtrain223

xxAtrain223 Mar 7, 2018

Contributor

I'm not sure what this was supposed to do, maybe servos[indexNum].detach();

}

bool Servo::diagnostic()
{
// TODO figure out what this is
return true;
}

Expand Down
33 changes: 33 additions & 0 deletions appendages/xml/servo.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<appendage-template>
<include>
<include standard="false">Servo.h</include>
</include>

<constructors>
<constructor type="Servo" variable="servos">
</constructor>
<constructor type="unsigned char" variable="servo_pin" type-is-class="false">
<argument name="pin" type="int" />
</constructor>
</constructors>

<setup>
servos[$i$].attach($pin$)
</setup>

<loop>
// Servo pin: $pin$
</loop>

<commands>
<command id="kServoWrite" name="ServoWrite" index-num="true">
<parameter type="int" name="value" />
<code>
if (!servos[indexNum].attached()) {
servos[indexNum].write(value)
}
servos[indexNum].write(value)
</code>
</command>
</commands>
</appendage-template>

0 comments on commit a709499

Please sign in to comment.